Skip to content

Commit

Permalink
feat(saveSynonyms): replaceExistingSynonyms -> clearExistingSynonyms (#…
Browse files Browse the repository at this point in the history
…1226)

fixes #1224
  • Loading branch information
Haroenv authored Nov 18, 2020
1 parent 6cb1d0a commit 2fcf485
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion packages/algoliasearch/src/builds/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,10 @@ export type SearchIndex = BaseSearchIndex & {
readonly replaceAllSynonyms: (
synonyms: readonly Synonym[],
requestOptions?: RequestOptions &
Pick<SaveSynonymsOptions, Exclude<keyof SaveSynonymsOptions, 'replaceExistingSynonyms'>>
Pick<
SaveSynonymsOptions,
Exclude<keyof SaveSynonymsOptions, 'clearExistingSynonyms' | 'replaceExistingSynonyms'>
>
) => Readonly<WaitablePromise<SaveSynonymsResponse>>;
readonly searchRules: (
query: string,
Expand Down
5 changes: 4 additions & 1 deletion packages/algoliasearch/src/builds/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ export type SearchIndex = BaseSearchIndex & {
readonly replaceAllSynonyms: (
synonyms: readonly Synonym[],
requestOptions?: RequestOptions &
Pick<SaveSynonymsOptions, Exclude<keyof SaveSynonymsOptions, 'replaceExistingSynonyms'>>
Pick<
SaveSynonymsOptions,
Exclude<keyof SaveSynonymsOptions, 'clearExistingSynonyms' | 'replaceExistingSynonyms'>
>
) => Readonly<WaitablePromise<SaveSynonymsResponse>>;
readonly searchRules: (
query: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ export const replaceAllSynonyms = (base: SearchIndex) => {
return (
synonyms: readonly Synonym[],
requestOptions?: RequestOptions &
Pick<SaveSynonymsOptions, Exclude<keyof SaveSynonymsOptions, 'replaceExistingSynonyms'>>
Pick<
SaveSynonymsOptions,
Exclude<keyof SaveSynonymsOptions, 'clearExistingSynonyms' | 'replaceExistingSynonyms'>
>
): Readonly<WaitablePromise<SaveSynonymsResponse>> => {
return saveSynonyms(base)(synonyms, {
...requestOptions,
replaceExistingSynonyms: true,
clearExistingSynonyms: true,
});
};
};
5 changes: 3 additions & 2 deletions packages/client-search/src/methods/index/saveSynonyms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export const saveSynonyms = (base: SearchIndex) => {
synonyms: readonly Synonym[],
requestOptions?: SaveSynonymsOptions & RequestOptions
): Readonly<WaitablePromise<SaveSynonymsResponse>> => {
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
}

Expand Down
6 changes: 6 additions & 0 deletions packages/client-search/src/types/SaveSynonymsOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 2fcf485

Please sign in to comment.