feat(environment): Added functionality to perist entries from different instance.#116
feat(environment): Added functionality to perist entries from different instance.#116kulak-at wants to merge 2 commits intoalgolia:masterfrom
Conversation
|
Thanks for your PR! Could having a specific matchField for each one of the environments work? |
|
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. |
|
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 |
| 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. |
There was a problem hiding this comment.
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?)
Haroenv
left a comment
There was a problem hiding this comment.
I'm ok with the idea, although I think it overlaps with match fields
| useEnvironment = false, | ||
| environmentKey = 'environment' |
There was a problem hiding this comment.
| 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) { |
There was a problem hiding this comment.
| if (useEnvironment && existingObj[environmentKey] !== useEnvironment) { | |
| if (environmentKey && existingObj[environmentKey] !== environmentKey) { |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
also needs updating based on that
| 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. |
There was a problem hiding this comment.
| 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 |
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).