diff --git a/packages/algoliasearch/src/builds/browser.ts b/packages/algoliasearch/src/builds/browser.ts index f8976e59d..0dab73b08 100644 --- a/packages/algoliasearch/src/builds/browser.ts +++ b/packages/algoliasearch/src/builds/browser.ts @@ -45,6 +45,7 @@ import { browseSynonyms, ChunkedBatchResponse, ChunkOptions, + clearDictionaryEntries, clearObjects, clearRules, ClearRulesOptions, @@ -60,6 +61,7 @@ import { DeleteApiKeyResponse, deleteBy, DeleteByFiltersOptions, + deleteDictionaryEntries, deleteIndex, deleteObject, deleteObjects, @@ -67,6 +69,8 @@ import { deleteRule, deleteSynonym, DeleteSynonymOptions, + DictionaryEntry, + DictionarySettings, exists, findAnswers, FindAnswersOptions, @@ -76,6 +80,9 @@ import { FindObjectResponse, getApiKey, GetApiKeyResponse, + getDictionarySettings, + GetDictionarySettingsResponse, + getDictionaryTask, getLogs, GetLogsResponse, getObject, @@ -127,9 +134,13 @@ import { ReplaceAllObjectsOptions, replaceAllRules, replaceAllSynonyms, + replaceDictionaryEntries, restoreApiKey, RestoreApiKeyResponse, Rule, + saveDictionaryEntries, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, saveObject, SaveObjectResponse, saveObjects, @@ -146,6 +157,8 @@ import { SaveSynonymsResponse, search, SearchClient as BaseSearchClient, + searchDictionaryEntries, + SearchDictionaryEntriesResponse, searchForFacetValues, SearchForFacetValuesQueryParams, SearchForFacetValuesResponse, @@ -160,14 +173,18 @@ import { searchUserIDs, SearchUserIDsOptions, SearchUserIDsResponse, + setDictionarySettings, + SetDictionarySettingsResponse, setSettings, SetSettingsResponse, Settings, Synonym, + TaskStatusResponse, updateApiKey, UpdateApiKeyOptions, UpdateApiKeyResponse, UserIDResponse, + waitDictionaryTask, waitTask, } from '@algolia/client-search'; import { LogLevelEnum } from '@algolia/logger-common'; @@ -235,6 +252,15 @@ export default function algoliasearch( getTopUserIDs, removeUserID, hasPendingMappings, + clearDictionaryEntries, + deleteDictionaryEntries, + getDictionarySettings, + getDictionaryTask, + replaceDictionaryEntries, + saveDictionaryEntries, + searchDictionaryEntries, + setDictionarySettings, + waitDictionaryTask, initIndex: base => (indexName: string): SearchIndex => { return initIndex(base)(indexName, { methods: { @@ -601,6 +627,41 @@ export type SearchClient = BaseSearchClient & { readonly hasPendingMappings: ( requestOptions?: HasPendingMappingsOptions & RequestOptions ) => Readonly>; + readonly clearDictionaryEntries: ( + dictionary: string, + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly deleteDictionaryEntries: ( + dictionary: string, + objectIDs: readonly string[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly replaceDictionaryEntries: ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly saveDictionaryEntries: ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly searchDictionaryEntries: ( + dictionary: string, + query: string, + requestOptions?: RequestOptions + ) => Readonly>; + readonly getDictionarySettings: ( + requestOptions?: RequestOptions + ) => Readonly>; + readonly setDictionarySettings: ( + settings: readonly DictionarySettings[], + requestOptions?: RequestOptions + ) => Readonly>; + readonly getDictionaryTask: ( + taskID: number, + requestOptions?: RequestOptions + ) => Readonly>; readonly initAnalytics: (options?: InitAnalyticsOptions) => AnalyticsClient; readonly initRecommendation: (options?: InitRecommendationOptions) => RecommendationClient; }; diff --git a/packages/algoliasearch/src/builds/node.ts b/packages/algoliasearch/src/builds/node.ts index b1030fd6d..711b82000 100644 --- a/packages/algoliasearch/src/builds/node.ts +++ b/packages/algoliasearch/src/builds/node.ts @@ -44,6 +44,7 @@ import { browseSynonyms, ChunkedBatchResponse, ChunkOptions, + clearDictionaryEntries, clearObjects, clearRules, ClearRulesOptions, @@ -59,6 +60,7 @@ import { DeleteApiKeyResponse, deleteBy, DeleteByFiltersOptions, + deleteDictionaryEntries, deleteIndex, deleteObject, deleteObjects, @@ -66,6 +68,8 @@ import { deleteRule, deleteSynonym, DeleteSynonymOptions, + DictionaryEntry, + DictionarySettings, exists, findAnswers, FindAnswersOptions, @@ -76,6 +80,9 @@ import { generateSecuredApiKey, getApiKey, GetApiKeyResponse, + getDictionarySettings, + GetDictionarySettingsResponse, + getDictionaryTask, getLogs, GetLogsResponse, getObject, @@ -128,9 +135,13 @@ import { ReplaceAllObjectsOptions, replaceAllRules, replaceAllSynonyms, + replaceDictionaryEntries, restoreApiKey, RestoreApiKeyResponse, Rule, + saveDictionaryEntries, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, saveObject, SaveObjectResponse, saveObjects, @@ -147,6 +158,8 @@ import { SaveSynonymsResponse, search, SearchClient as BaseSearchClient, + searchDictionaryEntries, + SearchDictionaryEntriesResponse, searchForFacetValues, SearchForFacetValuesQueryParams, SearchForFacetValuesResponse, @@ -162,14 +175,18 @@ import { SearchUserIDsOptions, SearchUserIDsResponse, SecuredApiKeyRestrictions, + setDictionarySettings, + SetDictionarySettingsResponse, setSettings, SetSettingsResponse, Settings, Synonym, + TaskStatusResponse, updateApiKey, UpdateApiKeyOptions, UpdateApiKeyResponse, UserIDResponse, + waitDictionaryTask, waitTask, } from '@algolia/client-search'; import { createNullLogger } from '@algolia/logger-common'; @@ -238,6 +255,15 @@ export default function algoliasearch( generateSecuredApiKey, getSecuredApiKeyRemainingValidity, destroy, + clearDictionaryEntries, + deleteDictionaryEntries, + getDictionarySettings, + getDictionaryTask, + replaceDictionaryEntries, + saveDictionaryEntries, + searchDictionaryEntries, + setDictionarySettings, + waitDictionaryTask, initIndex: base => (indexName: string): SearchIndex => { return initIndex(base)(indexName, { methods: { @@ -609,6 +635,41 @@ export type SearchClient = BaseSearchClient & { restrictions: SecuredApiKeyRestrictions ) => string; readonly getSecuredApiKeyRemainingValidity: (securedApiKey: string) => number; + readonly clearDictionaryEntries: ( + dictionary: string, + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly deleteDictionaryEntries: ( + dictionary: string, + objectIDs: readonly string[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly replaceDictionaryEntries: ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly saveDictionaryEntries: ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly searchDictionaryEntries: ( + dictionary: string, + query: string, + requestOptions?: RequestOptions + ) => Readonly>; + readonly getDictionarySettings: ( + requestOptions?: RequestOptions + ) => Readonly>; + readonly setDictionarySettings: ( + settings: readonly DictionarySettings[], + requestOptions?: RequestOptions + ) => Readonly>; + readonly getDictionaryTask: ( + taskID: number, + requestOptions?: RequestOptions + ) => Readonly>; readonly initAnalytics: (options?: InitAnalyticsOptions) => AnalyticsClient; readonly initRecommendation: (options?: InitRecommendationOptions) => RecommendationClient; } & Destroyable; diff --git a/packages/client-search/src/__tests__/integration/dictionary.test.ts b/packages/client-search/src/__tests__/integration/dictionary.test.ts new file mode 100644 index 000000000..b28eefa9c --- /dev/null +++ b/packages/client-search/src/__tests__/integration/dictionary.test.ts @@ -0,0 +1,93 @@ +import { TestSuite } from '../../../../client-common/src/__tests__/TestSuite'; + +const testSuite = new TestSuite('dictionary'); + +test(testSuite.testName, async () => { + const client = testSuite.makeSearchClient('ALGOLIA_APPLICATION_ID_2', 'ALGOLIA_ADMIN_KEY_2') + + // Stopwords + const stopwordEntryId = Math.floor(Math.random() * 10000).toString(); + expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(0); + + const stopwordEntry = { + objectID: stopwordEntryId, + language: 'en', + word: 'down', + }; + + await client.saveDictionaryEntries('stopwords', [stopwordEntry]); + + const stopwords = await client.searchDictionaryEntries('stopwords', stopwordEntryId); + expect(stopwords.nbHits).toEqual(1); + expect(stopwords.hits[0].objectID).toEqual(stopwordEntry.objectID); + expect(stopwords.hits[0].word).toEqual(stopwordEntry.word); + + await client.deleteDictionaryEntries('stopwords', [stopwordEntryId]); + expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(0); + + const oldDictionaryState = await client.searchDictionaryEntries('stopwords', ''); + const oldDictionaryEntries = oldDictionaryState.hits.map(hit => { + delete hit.type; + + return hit; + }); + + await client.saveDictionaryEntries('stopwords', [stopwordEntry]); + expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(1); + + await client.replaceDictionaryEntries('stopwords', oldDictionaryEntries); + expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(0); + + const stopwordsSettings = { + disableStandardEntries: { + stopwords: { + en: true, + }, + }, + }; + + await client.setDictionarySettings(stopwordsSettings); + expect(await client.getDictionarySettings()).toEqual(stopwordsSettings); + + // Plurals + const pluralEntryId = Math.floor(Math.random() * 10000).toString(); + expect(await client.searchDictionaryEntries('plurals', pluralEntryId).nbHits).toEqual(0); + + const pluralEntry = { + objectID: pluralEntryId, + language: 'fr', + words: ['cheval', 'chevaux'], + }; + + await client.saveDictionaryEntries('plurals', [pluralEntry]); + + const plurals = await client.searchDictionaryEntries('plurals', pluralEntryId); + expect(plurals.nbHits).toEqual(1); + expect(plurals.hits[0].objectID).toEqual(pluralEntry.objectID); + expect(plurals.hits[0].words).toEqual(pluralEntry.words); + + await client.deleteDictionaryEntries('plurals', [pluralEntryId]); + expect(await client.searchDictionaryEntries('plurals', pluralEntryId).nbHits).toEqual(0); + + // Compounds + const compoundEntryId = Math.floor(Math.random() * 10000).toString(); + expect(await client.searchDictionaryEntries('plurals', compoundEntryId).nbHits).toEqual(0); + + const compoundEntry = { + objectID: compoundEntryId, + language: 'fr', + word: 'kopfschmerztablette', + decomposition: ['kopf', 'schmerz', 'tablette'], + }; + + await client.saveDictionaryEntries('plurals', [compoundEntry]); + + const compounds = await client.searchDictionaryEntries('plurals', compoundEntryId); + expect(compounds.nbHits).toEqual(1); + expect(compounds.hits[0].objectID).toEqual(compoundEntry.objectID); + expect(compounds.hits[0].word).toEqual(compoundEntry.word); + expect(compounds.hits[0].decomposition).toEqual(compoundEntry.decomposition); + + await client.deleteDictionaryEntries('plurals', [compoundEntryId]); + expect(await client.searchDictionaryEntries('plurals', compoundEntryId).nbHits).toEqual(0); +}); diff --git a/packages/client-search/src/methods/client/clearDictionaryEntries.ts b/packages/client-search/src/methods/client/clearDictionaryEntries.ts new file mode 100644 index 000000000..999c71d6c --- /dev/null +++ b/packages/client-search/src/methods/client/clearDictionaryEntries.ts @@ -0,0 +1,30 @@ +import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient } from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in SaveDictionaryEntriesOptions type +export const clearDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Post, + path: encode('/1/dictionaries/%s/batch', dictionary), + data: { + clearExistingDictionaryEntries: true, + requests: { action: 'addEntry', body: [] }, + }, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts new file mode 100644 index 000000000..3684625bf --- /dev/null +++ b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts @@ -0,0 +1,29 @@ +import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient } from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in SaveDictionaryEntriesOptions type +// TODO objectIDs have to be a composite objects with actionType=deleteEntry and body=objectID like MultipleBatch +export const deleteDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + objectIDs: readonly string[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Post, + path: encode('/1/dictionaries/%s/batch', dictionary), + data: { clearExistingDictionaryEntries: false, requests: objectIDs }, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/getDictionarySettings.ts b/packages/client-search/src/methods/client/getDictionarySettings.ts new file mode 100644 index 000000000..11ea0c970 --- /dev/null +++ b/packages/client-search/src/methods/client/getDictionarySettings.ts @@ -0,0 +1,17 @@ +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { GetDictionarySettingsResponse, SearchClient } from '../..'; + +// TODO: fill in GetDictionarySettingsResponse type +export const getDictionarySettings = (base: SearchClient) => { + return (requestOptions?: RequestOptions): Readonly> => { + return base.transporter.read( + { + method: MethodEnum.Get, + path: '/1/dictionaries/*/settings', + }, + requestOptions + ); + }; +}; diff --git a/packages/client-search/src/methods/client/getDictionaryTask.ts b/packages/client-search/src/methods/client/getDictionaryTask.ts new file mode 100644 index 000000000..18ba6d081 --- /dev/null +++ b/packages/client-search/src/methods/client/getDictionaryTask.ts @@ -0,0 +1,20 @@ +import { encode } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SearchClient, TaskStatusResponse } from '../..'; + +export const getDictionaryTask = (base: SearchClient) => { + return ( + taskID: number, + requestOptions?: RequestOptions + ): Readonly> => { + return base.transporter.read( + { + method: MethodEnum.Get, + path: encode('1/task/%s', taskID.toString()), + }, + requestOptions + ); + }; +}; diff --git a/packages/client-search/src/methods/client/index.ts b/packages/client-search/src/methods/client/index.ts index c0ed301c0..787a568c6 100644 --- a/packages/client-search/src/methods/client/index.ts +++ b/packages/client-search/src/methods/client/index.ts @@ -5,16 +5,20 @@ export * from './addApiKey'; export * from './assignUserID'; export * from './assignUserIDs'; +export * from './clearDictionaryEntries'; export * from './copyIndex'; export * from './copyRules'; export * from './copySettings'; export * from './copySynonyms'; export * from './deleteApiKey'; +export * from './deleteDictionaryEntries'; export * from './generateSecuredApiKey'; export * from './getApiKey'; +export * from './getDictionarySettings'; export * from './getLogs'; export * from './getSecuredApiKeyRemainingValidity'; export * from './getTopUserIDs'; +export * from './getDictionaryTask'; export * from './getUserID'; export * from './hasPendingMappings'; export * from './initIndex'; @@ -28,6 +32,11 @@ export * from './multipleGetObjects'; export * from './multipleQueries'; export * from './multipleSearchForFacetValues'; export * from './removeUserID'; +export * from './replaceDictionaryEntries'; export * from './restoreApiKey'; +export * from './saveDictionaryEntries'; +export * from './searchDictionaryEntries'; export * from './searchUserIDs'; +export * from './setDictionarySettings'; export * from './updateApiKey'; +export * from './waitDictionaryTask'; diff --git a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts new file mode 100644 index 000000000..39df752ca --- /dev/null +++ b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts @@ -0,0 +1,34 @@ +import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { + DictionaryEntry, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, + SearchClient, +} from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in DictionaryEntry & SaveDictionaryEntriesOptions types +// TODO entries have to be a composite objects with actionType=addEntry and body=DictEntry like MultipleBatch +export const replaceDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Post, + path: encode('/1/dictionaries/%s/batch', dictionary), + data: { clearExistingDictionaryEntries: true, requests: entries }, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/saveDictionaryEntries.ts b/packages/client-search/src/methods/client/saveDictionaryEntries.ts new file mode 100644 index 000000000..94dd4d151 --- /dev/null +++ b/packages/client-search/src/methods/client/saveDictionaryEntries.ts @@ -0,0 +1,34 @@ +import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { + DictionaryEntry, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, + SearchClient, +} from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in DictionaryEntry & SaveDictionaryEntriesOptions types +// TODO entries have to be a composite objects with actionType=addEntry and body=DictEntry like MultipleBatch +export const saveDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Post, + path: encode('/1/dictionaries/%s/batch', dictionary), + data: { clearExistingDictionaryEntries: false, requests: entries }, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/searchDictionaryEntries.ts b/packages/client-search/src/methods/client/searchDictionaryEntries.ts new file mode 100644 index 000000000..e91dd04b4 --- /dev/null +++ b/packages/client-search/src/methods/client/searchDictionaryEntries.ts @@ -0,0 +1,26 @@ +import { encode } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SearchClient, SearchDictionaryEntriesResponse } from '../..'; + +// TODO: fill in SearchDictionaryEntriesResponse type +export const searchDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + query: string, + requestOptions?: RequestOptions + ): Readonly>> => { + return base.transporter.read( + { + method: MethodEnum.Post, + path: encode('1/indexes/%s/query', dictionary), + data: { + query, + }, + cacheable: true, + }, + requestOptions + ); + }; +}; diff --git a/packages/client-search/src/methods/client/setDictionarySettings.ts b/packages/client-search/src/methods/client/setDictionarySettings.ts new file mode 100644 index 000000000..023294320 --- /dev/null +++ b/packages/client-search/src/methods/client/setDictionarySettings.ts @@ -0,0 +1,27 @@ +import { createWaitablePromise, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { DictionarySettings, SearchClient, SetDictionarySettingsResponse } from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in DictionarySettings & SetDictionarySettingsResponse types +export const setDictionarySettings = (base: SearchClient) => { + return ( + settings: readonly DictionarySettings[], + requestOptions?: RequestOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Put, + path: '/1/dictionaries/*/settings', + data: settings, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/waitDictionaryTask.ts b/packages/client-search/src/methods/client/waitDictionaryTask.ts new file mode 100644 index 000000000..0e1c38b1a --- /dev/null +++ b/packages/client-search/src/methods/client/waitDictionaryTask.ts @@ -0,0 +1,15 @@ +import { createRetryablePromise } from '@algolia/client-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SearchClient } from '../..'; +import { getDictionaryTask } from '.'; + +export const waitDictionaryTask = (base: SearchClient) => { + return (taskID: number, requestOptions?: RequestOptions): Readonly> => { + return createRetryablePromise(retry => { + return getDictionaryTask(base)(taskID, requestOptions).then(response => { + return response.status !== 'published' ? retry() : undefined; + }); + }); + }; +}; diff --git a/packages/client-search/src/types/DictionaryEntry.ts b/packages/client-search/src/types/DictionaryEntry.ts new file mode 100644 index 000000000..c0c6e6d81 --- /dev/null +++ b/packages/client-search/src/types/DictionaryEntry.ts @@ -0,0 +1,10 @@ +export type DictionaryEntry = { + /** + * Unique identifier for the rule (format: [A-Za-z0-9_-]+). + */ + readonly objectID: string; + + /** + * TODO + */ +}; diff --git a/packages/client-search/src/types/DictionarySettings.ts b/packages/client-search/src/types/DictionarySettings.ts new file mode 100644 index 000000000..a6cb0090f --- /dev/null +++ b/packages/client-search/src/types/DictionarySettings.ts @@ -0,0 +1,10 @@ +export type DictionarySettings = { + /** + * Unique identifier for the rule (format: [A-Za-z0-9_-]+). + */ + readonly objectID: string; + + /** + * TODO + */ +}; diff --git a/packages/client-search/src/types/GetDictionarySettingsResponse.ts b/packages/client-search/src/types/GetDictionarySettingsResponse.ts new file mode 100644 index 000000000..4a82816ea --- /dev/null +++ b/packages/client-search/src/types/GetDictionarySettingsResponse.ts @@ -0,0 +1,5 @@ +export type GetDictionarySettingsResponse = { + /** + * TODO + */ +}; diff --git a/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts b/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts new file mode 100644 index 000000000..4b13c6de1 --- /dev/null +++ b/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts @@ -0,0 +1,5 @@ +export type SaveDictionaryEntriesOptions = { + /** + * TODO + */ +}; diff --git a/packages/client-search/src/types/SaveDictionaryEntriesResponse.ts b/packages/client-search/src/types/SaveDictionaryEntriesResponse.ts new file mode 100644 index 000000000..e7ffba065 --- /dev/null +++ b/packages/client-search/src/types/SaveDictionaryEntriesResponse.ts @@ -0,0 +1,11 @@ +export type SaveDictionaryEntriesResponse = { + /** + * When the given rules got saved. + */ + updatedAt: number; + + /** + * The operation task id. May be used to perform a wait task. + */ + taskID: number; +}; diff --git a/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts b/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts new file mode 100644 index 000000000..fe67e73e5 --- /dev/null +++ b/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts @@ -0,0 +1,70 @@ +import { Hit } from '.'; + +export type SearchDictionaryEntriesResponse = { + /** + * TODO + */ + + /** + * The hits returned by the search. + * + * Hits are ordered according to the ranking or sorting of the index being queried. + */ + hits: Array>; + + /** + * Index of the current page (zero-based). + */ + page: number; + + /** + * Number of hits returned (used only with offset) + */ + length?: number; + + /** + * The offset of the first hit to returned. + */ + offset?: number; + + /** + * Number of hits matched by the query. + */ + nbHits: number; + + /** + * Subset of hits selected when relevancyStrictness is applied. + */ + nbSortedHits?: number; + + /** + * Number of pages returned. + * + * Calculation is based on the total number of hits (nbHits) divided by the + * number of hits per page (hitsPerPage), rounded up to the nearest integer. + */ + nbPages: number; + + /** + * Maximum number of hits returned per page. + */ + hitsPerPage: number; + + /** + * Time the server took to process the request, in milliseconds. This does not include network time. + */ + processingTimeMS: number; + + /** + * Whether the nbHits is exhaustive (true) or approximate (false). + * + * An approximation is done when the query takes more than 50ms to be + * processed (this can happen when using complex filters on millions on records). + */ + exhaustiveNbHits: boolean; + + /** + * Whether the facet count is exhaustive (true) or approximate (false). + */ + exhaustiveFacetsCount?: boolean; +}; diff --git a/packages/client-search/src/types/SetDictionarySettingsResponse.ts b/packages/client-search/src/types/SetDictionarySettingsResponse.ts new file mode 100644 index 000000000..eb8bb843b --- /dev/null +++ b/packages/client-search/src/types/SetDictionarySettingsResponse.ts @@ -0,0 +1,11 @@ +export type SetDictionarySettingsResponse = { + /** + * When the given rules got saved. + */ + updatedAt: number; + + /** + * The operation task id. May be used to perform a wait task. + */ + taskID: number; +}; diff --git a/packages/client-search/src/types/index.ts b/packages/client-search/src/types/index.ts index 523dfd08e..44d2eb8d2 100644 --- a/packages/client-search/src/types/index.ts +++ b/packages/client-search/src/types/index.ts @@ -24,6 +24,8 @@ export * from './DeleteApiKeyResponse'; export * from './DeleteByFiltersOptions'; export * from './DeleteResponse'; export * from './DeleteSynonymOptions'; +export * from './DictionaryEntry'; +export * from './DictionarySettings'; export * from './FacetHit'; export * from './FindAnswersOptions'; export * from './FindAnswersResponse'; @@ -35,6 +37,7 @@ export * from './GetLogsResponse'; export * from './GetObjectOptions'; export * from './GetObjectsOptions'; export * from './GetObjectsResponse'; +export * from './GetDictionarySettingsResponse'; export * from './GetTopUserIDsResponse'; export * from './HasPendingMappingsOptions'; export * from './HasPendingMappingsResponse'; @@ -61,6 +64,8 @@ export * from './RemoveUserIDResponse'; export * from './ReplaceAllObjectsOptions'; export * from './RestoreApiKeyResponse'; export * from './Rule'; +export * from './SaveDictionaryEntriesOptions'; +export * from './SaveDictionaryEntriesResponse'; export * from './SaveObjectResponse'; export * from './SaveObjectsOptions'; export * from './SaveRuleResponse'; @@ -71,6 +76,7 @@ export * from './SaveSynonymsOptions'; export * from './SaveSynonymsResponse'; export * from './SearchClient'; export * from './SearchClientOptions'; +export * from './SearchDictionaryEntriesResponse'; export * from './SearchForFacetValuesQueryParams'; export * from './SearchForFacetValuesResponse'; export * from './SearchIndex'; @@ -82,6 +88,7 @@ export * from './SearchSynonymsResponse'; export * from './SearchUserIDsOptions'; export * from './SearchUserIDsResponse'; export * from './SecuredApiKeyRestrictions'; +export * from './SetDictionarySettingsResponse'; export * from './SetSettingsOptions'; export * from './SetSettingsResponse'; export * from './Settings';