Skip to content

feat(environment): Added functionality to perist entries from different instance.#116

Open
kulak-at wants to merge 2 commits intoalgolia:masterfrom
kulak-at:master
Open

feat(environment): Added functionality to perist entries from different instance.#116
kulak-at wants to merge 2 commits intoalgolia:masterfrom
kulak-at:master

Conversation

@kulak-at
Copy link

Context
I am currently working on a project with federated search combining results from multiple gatsby instances. I've wanted to use this plugin but realized it is clearing all the results that did not appear in the new run. I've added an option to skip the results added from the different environment (i.e. different gatsby instance).

@Haroenv
Copy link
Contributor

Haroenv commented Feb 18, 2021

Thanks for your PR! Could having a specific matchField for each one of the environments work?

@kulak-at
Copy link
Author

Unfortunately, the matchField itself doesn't cover this use-case. The items I want to preserve in my case are the entries that are generated from different gatsby instance so there's nothing I can match the entries against and they will always be removed. Maybe there's another way to use matchField to cover that you have in mind but I don't see a straightforward solution.

@Serjlee
Copy link

Serjlee commented Apr 21, 2021

I think this would be a useful addition, as I just found myself in a similar case: we got multiple "documentation" websites using different technologies, and it makes sense for us to use a single index because of the search app UX, and because of the content itself

We already got a couple (non-Gatsby) applications sharing a single index, and the ability to also share it with a Gatsby site would be extremely handy

Comment on lines +86 to +87
useEnvironment: 'blog', // default: false, used in conjunction with enablePartialUpdates let you persist entries from different environment
environmentKey: 'product', // default: 'environment', key used when useEnvironment is set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems confusing, what if we have only the option environmentKey, and use it whenever it's set. I think also the option on line 86 possibly has the wrong example value? (is it a boolean or a string?)

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the idea, although I think it overlaps with match fields

Comment on lines +118 to +119
useEnvironment = false,
environmentKey = 'environment'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
useEnvironment = false,
environmentKey = 'environment'
environmentKey


// iterate over existing objects and compare to fresh data
for (const [id, existingObj] of Object.entries(indexedObjects)) {
if (useEnvironment && existingObj[environmentKey] !== useEnvironment) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (useEnvironment && existingObj[environmentKey] !== useEnvironment) {
if (environmentKey && existingObj[environmentKey] !== environmentKey) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need to check that similar to matchFields, it's present on all new objects

If you pass `replicaUpdateMode: 'merge'` in the index settings, the replica settings will combine the replicas set on your dashboard with the additional ones you set via index settings here.

### Persisting entries
If you want to persist entries that are added to the index (for example added by the different gatsby instance if your index is combining several websites) you can set `useEnvironment` to unique string that represents given instance. All entries with different `environment` value will be ignored. You can change the key accordingly using `environmentKey`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also needs updating based on that

Comment on lines +86 to +87
useEnvironment: 'blog', // default: false, used in conjunction with enablePartialUpdates let you persist entries from different environment
environmentKey: 'product', // default: 'environment', key used when useEnvironment is set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
useEnvironment: 'blog', // default: false, used in conjunction with enablePartialUpdates let you persist entries from different environment
environmentKey: 'product', // default: 'environment', key used when useEnvironment is set.
environmentKey: 'blog', // a key that is unique to the Gatsby records. Records without this key are left in place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants