diff --git a/packages/algoliasearch/src/builds/browser.ts b/packages/algoliasearch/src/builds/browser.ts index 9dcc2d791..ba1113fd7 100644 --- a/packages/algoliasearch/src/builds/browser.ts +++ b/packages/algoliasearch/src/builds/browser.ts @@ -451,7 +451,10 @@ export type SearchIndex = BaseSearchIndex & { readonly replaceAllSynonyms: ( synonyms: readonly Synonym[], requestOptions?: RequestOptions & - Pick> + Pick< + SaveSynonymsOptions, + Exclude + > ) => Readonly>; readonly searchRules: ( query: string, diff --git a/packages/algoliasearch/src/builds/node.ts b/packages/algoliasearch/src/builds/node.ts index 20414795d..74f3916f5 100644 --- a/packages/algoliasearch/src/builds/node.ts +++ b/packages/algoliasearch/src/builds/node.ts @@ -454,7 +454,10 @@ export type SearchIndex = BaseSearchIndex & { readonly replaceAllSynonyms: ( synonyms: readonly Synonym[], requestOptions?: RequestOptions & - Pick> + Pick< + SaveSynonymsOptions, + Exclude + > ) => Readonly>; readonly searchRules: ( query: string, diff --git a/packages/client-search/src/methods/index/replaceAllSynonyms.ts b/packages/client-search/src/methods/index/replaceAllSynonyms.ts index 540f32367..56ffaa48e 100644 --- a/packages/client-search/src/methods/index/replaceAllSynonyms.ts +++ b/packages/client-search/src/methods/index/replaceAllSynonyms.ts @@ -9,11 +9,14 @@ export const replaceAllSynonyms = (base: SearchIndex) => { return ( synonyms: readonly Synonym[], requestOptions?: RequestOptions & - Pick> + Pick< + SaveSynonymsOptions, + Exclude + > ): Readonly> => { return saveSynonyms(base)(synonyms, { ...requestOptions, - replaceExistingSynonyms: true, + clearExistingSynonyms: true, }); }; }; diff --git a/packages/client-search/src/methods/index/saveSynonyms.ts b/packages/client-search/src/methods/index/saveSynonyms.ts index 1bfb40428..a144ddf85 100644 --- a/packages/client-search/src/methods/index/saveSynonyms.ts +++ b/packages/client-search/src/methods/index/saveSynonyms.ts @@ -10,14 +10,15 @@ export const saveSynonyms = (base: SearchIndex) => { synonyms: readonly Synonym[], requestOptions?: SaveSynonymsOptions & RequestOptions ): Readonly> => { - const { forwardToReplicas, replaceExistingSynonyms, ...options } = requestOptions || {}; + const { forwardToReplicas, clearExistingSynonyms, replaceExistingSynonyms, ...options } = + requestOptions || {}; const mappedRequestOptions = createMappedRequestOptions(options); if (forwardToReplicas) { mappedRequestOptions.queryParameters.forwardToReplicas = 1; // eslint-disable-line functional/immutable-data } - if (replaceExistingSynonyms) { + if (replaceExistingSynonyms || clearExistingSynonyms) { mappedRequestOptions.queryParameters.replaceExistingSynonyms = 1; // eslint-disable-line functional/immutable-data } diff --git a/packages/client-search/src/types/SaveSynonymsOptions.ts b/packages/client-search/src/types/SaveSynonymsOptions.ts index ed20a1cac..cc3788964 100644 --- a/packages/client-search/src/types/SaveSynonymsOptions.ts +++ b/packages/client-search/src/types/SaveSynonymsOptions.ts @@ -6,6 +6,12 @@ export type SaveSynonymsOptions = { /** * If the existing synonyms should be removed. + * @deprecated use clearExistingSynonyms */ readonly replaceExistingSynonyms?: boolean; + + /** + * If the existing synonyms should be removed. + */ + readonly clearExistingSynonyms?: boolean; };