-
Notifications
You must be signed in to change notification settings - Fork 222
/
browseSynonyms.ts
42 lines (38 loc) · 1.09 KB
/
browseSynonyms.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { RequestOptions } from '@algolia/transporter';
import {
BrowseOptions,
BrowseResponse,
createBrowsablePromise,
SearchIndex,
searchSynonyms,
SearchSynonymsOptions,
Synonym,
} from '../..';
export const browseSynonyms = (base: SearchIndex) => {
return (
requestOptions?: SearchSynonymsOptions & BrowseOptions<Synonym> & RequestOptions
): Readonly<Promise<void>> => {
const options = {
hitsPerPage: 1000,
...requestOptions,
};
return createBrowsablePromise<Synonym>({
shouldStop: response => response.hits.length < options.hitsPerPage,
...options,
request(data) {
return searchSynonyms(base)('', { ...options, ...data }).then(
(response): BrowseResponse<Synonym> => {
return {
...response,
hits: response.hits.map(synonym => {
// eslint-disable-next-line functional/immutable-data,no-param-reassign
delete (synonym as any)._highlightResult;
return synonym;
}),
};
}
);
},
});
};
};