From c1fdf310ee47add5fbec51a2be311cb32a58ca8d Mon Sep 17 00:00:00 2001 From: amit-ksh Date: Fri, 19 Apr 2024 14:00:47 +0530 Subject: [PATCH] Update SearchCutoffMs --- README.md | 22 ++++++++++++++++- src/indexes.ts | 10 ++++---- src/types/types.ts | 6 ++--- tests/__snapshots__/settings.test.ts.snap | 18 ++++++++++++++ tests/searchCutoffMs.ts | 30 +++++++++-------------- tests/settings.test.ts | 4 ++- 6 files changed, 60 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index df76a25f7..1bf364810 100644 --- a/README.md +++ b/README.md @@ -983,7 +983,7 @@ client.index('myIndex').resetProximityPrecision(): Promise ### Embedders -⚠️ This feature is experimental. Activate the [`vectorStore` experimental feature to use it](https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features) +⚠️ This feature is experimental. Activate the [`vectorStore` experimental feature to use it](https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features) #### [Get embedders](https://www.meilisearch.com/docs/reference/api/settings#get-embedders) @@ -1003,6 +1003,26 @@ client.index('myIndex').updateEmbedders(embedders: Embedders): Promise ``` +### SearchCutoffMs + +#### [Get SearchCutoffMs](https://www.meilisearch.com/docs/reference/api/settings#get-search-cutoff-ms) + +```ts +client.index('myIndex').getSearchCutoffMs(): Promise +``` + +#### [Update SearchCutoffMs](https://www.meilisearch.com/docs/reference/api/settings#update-search-cutoff-ms) + +```ts +client.index('myIndex').updateSearchCutoffMs(searchCutoffMs: SearchCutoffMs): Promise +``` + +#### [Reset SearchCutoffMs](https://www.meilisearch.com/docs/reference/api/settings#reset-search-cutoff-ms) + +```ts +client.index('myIndex').resetSearchCutoffMs(): Promise +``` + ### Keys #### [Get keys](https://www.meilisearch.com/docs/reference/api/keys#get-all-keys) diff --git a/src/indexes.ts b/src/indexes.ts index f8a84801f..1690402db 100644 --- a/src/indexes.ts +++ b/src/indexes.ts @@ -52,7 +52,7 @@ import { Dictionary, ProximityPrecision, Embedders, - SearchCutoffMsSettings, + SearchCutoffMs, } from './types' import { removeUndefinedFromObject } from './utils' import { HttpRequests } from './http-requests' @@ -1345,9 +1345,9 @@ class Index = Record> { * * @returns Promise containing object of SearchCutoffMs settings */ - async getSearchCutoffMs(): Promise { + async getSearchCutoffMs(): Promise { const url = `indexes/${this.uid}/settings/search-cutoff-ms` - return await this.httpRequest.get(url) + return await this.httpRequest.get(url) } /** @@ -1357,10 +1357,10 @@ class Index = Record> { * @returns Promise containing an EnqueuedTask */ async updateSearchCutoffMs( - searchCutoffMs: SearchCutoffMsSettings + searchCutoffMs: SearchCutoffMs ): Promise { const url = `indexes/${this.uid}/settings/search-cutoff-ms` - const task = await this.httpRequest.patch(url, searchCutoffMs) + const task = await this.httpRequest.put(url, searchCutoffMs) return new EnqueuedTask(task) } diff --git a/src/types/types.ts b/src/types/types.ts index 606d20ccb..8b66e0d73 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -373,9 +373,7 @@ export type PaginationSettings = { maxTotalHits?: number | null } -export type SearchCutoffMsSettings = { - searchCutoffMs?: number | null -} +export type SearchCutoffMs = number | null export type Settings = { filterableAttributes?: FilterableAttributes @@ -394,7 +392,7 @@ export type Settings = { dictionary?: Dictionary proximityPrecision?: ProximityPrecision embedders?: Embedders - searchCutoffMs?: SearchCutoffMsSettings + searchCutoffMs?: SearchCutoffMs } /* diff --git a/tests/__snapshots__/settings.test.ts.snap b/tests/__snapshots__/settings.test.ts.snap index 654f57729..5252c6889 100644 --- a/tests/__snapshots__/settings.test.ts.snap +++ b/tests/__snapshots__/settings.test.ts.snap @@ -27,6 +27,7 @@ exports[`Test on settings Admin key: Get default settings of an index 1`] = ` "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -73,6 +74,7 @@ exports[`Test on settings Admin key: Get default settings of empty index with pr "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -119,6 +121,7 @@ exports[`Test on settings Admin key: Reset settings 1`] = ` "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -165,6 +168,7 @@ exports[`Test on settings Admin key: Reset settings of empty index 1`] = ` "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -211,6 +215,7 @@ exports[`Test on settings Admin key: Update searchableAttributes settings on emp "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "title", ], @@ -257,6 +262,7 @@ exports[`Test on settings Admin key: Update searchableAttributes settings on emp "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "title", ], @@ -308,6 +314,7 @@ exports[`Test on settings Admin key: Update settings 1`] = ` "id:asc", "typo", ], + "searchCutoffMs": 1000, "searchableAttributes": [ "title", ], @@ -366,6 +373,7 @@ exports[`Test on settings Admin key: Update settings on empty index with primary "title:asc", "typo", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -414,6 +422,7 @@ exports[`Test on settings Admin key: Update settings with all null values 1`] = "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -460,6 +469,7 @@ exports[`Test on settings Master key: Get default settings of an index 1`] = ` "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -506,6 +516,7 @@ exports[`Test on settings Master key: Get default settings of empty index with p "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -552,6 +563,7 @@ exports[`Test on settings Master key: Reset settings 1`] = ` "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -598,6 +610,7 @@ exports[`Test on settings Master key: Reset settings of empty index 1`] = ` "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -644,6 +657,7 @@ exports[`Test on settings Master key: Update searchableAttributes settings on em "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "title", ], @@ -690,6 +704,7 @@ exports[`Test on settings Master key: Update searchableAttributes settings on em "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "title", ], @@ -741,6 +756,7 @@ exports[`Test on settings Master key: Update settings 1`] = ` "id:asc", "typo", ], + "searchCutoffMs": 1000, "searchableAttributes": [ "title", ], @@ -799,6 +815,7 @@ exports[`Test on settings Master key: Update settings on empty index with primar "title:asc", "typo", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], @@ -847,6 +864,7 @@ exports[`Test on settings Master key: Update settings with all null values 1`] = "sort", "exactness", ], + "searchCutoffMs": null, "searchableAttributes": [ "*", ], diff --git a/tests/searchCutoffMs.ts b/tests/searchCutoffMs.ts index 3b5c853d6..b0cb391aa 100644 --- a/tests/searchCutoffMs.ts +++ b/tests/searchCutoffMs.ts @@ -12,7 +12,7 @@ const index = { uid: 'movies_test', } -const DEFAULT_SEARCHCUTOFFMS = 1500 +const DEFAULT_SEARCHCUTOFFMS = null jest.setTimeout(100 * 1000) @@ -34,14 +34,12 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( const client = await getClient(permission) const response = await client.index(index.uid).getSearchCutoffMs() - expect(response).toEqual({ searchCutoffMs: DEFAULT_SEARCHCUTOFFMS }) + expect(response).toEqual(DEFAULT_SEARCHCUTOFFMS) }) test(`${permission} key: Update searchCutoffMs to valid value`, async () => { const client = await getClient(permission) - const newSearchCutoffMs = { - searchCutoffMs: 100, - } + const newSearchCutoffMs = 100 const task = await client .index(index.uid) .updateSearchCutoffMs(newSearchCutoffMs) @@ -54,9 +52,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( test(`${permission} key: Update searchCutoffMs to null`, async () => { const client = await getClient(permission) - const newSearchCutoffMs = { - searchCutoffMs: null, - } + const newSearchCutoffMs = null const task = await client .index(index.uid) .updateSearchCutoffMs(newSearchCutoffMs) @@ -64,14 +60,12 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( const response = await client.index(index.uid).getSearchCutoffMs() - expect(response).toEqual({ searchCutoffMs: DEFAULT_SEARCHCUTOFFMS }) + expect(response).toEqual(DEFAULT_SEARCHCUTOFFMS) }) test(`${permission} key: Update searchCutoffMs with invalid value`, async () => { const client = await getClient(permission) - const newSearchCutoffMs = { - searchCutoffMs: 'hello', // bad searchCutoffMs value - } as any + const newSearchCutoffMs = 'hello' as any // bad searchCutoffMs value await expect( client.index(index.uid).updateSearchCutoffMs(newSearchCutoffMs) @@ -83,9 +77,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( test(`${permission} key: Reset searchCutoffMs`, async () => { const client = await getClient(permission) - const newSearchCutoffMs = { - searchCutoffMs: 100, - } + const newSearchCutoffMs = 100 const updateTask = await client .index(index.uid) .updateSearchCutoffMs(newSearchCutoffMs) @@ -95,7 +87,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( const response = await client.index(index.uid).getSearchCutoffMs() - expect(response).toEqual({ searchCutoffMs: DEFAULT_SEARCHCUTOFFMS }) + expect(response).toEqual(DEFAULT_SEARCHCUTOFFMS) }) } ) @@ -119,7 +111,7 @@ describe.each([{ permission: 'Search' }])( test(`${permission} key: try to update searchCutoffMs and be denied`, async () => { const client = await getClient(permission) await expect( - client.index(index.uid).updateSearchCutoffMs({ searchCutoffMs: 100 }) + client.index(index.uid).updateSearchCutoffMs(100) ).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY) }) @@ -154,7 +146,7 @@ describe.each([{ permission: 'No' }])( test(`${permission} key: try to update searchCutoffMs and be denied`, async () => { const client = await getClient(permission) await expect( - client.index(index.uid).updateSearchCutoffMs({ searchCutoffMs: 100 }) + client.index(index.uid).updateSearchCutoffMs(100) ).rejects.toHaveProperty( 'code', ErrorStatusCode.MISSING_AUTHORIZATION_HEADER @@ -198,7 +190,7 @@ describe.each([ const client = new MeiliSearch({ host }) const strippedHost = trailing ? host.slice(0, -1) : host await expect( - client.index(index.uid).updateSearchCutoffMs({ searchCutoffMs: null }) + client.index(index.uid).updateSearchCutoffMs(null) ).rejects.toHaveProperty( 'message', `request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( diff --git a/tests/settings.test.ts b/tests/settings.test.ts index 4316c84ae..2f3c73631 100644 --- a/tests/settings.test.ts +++ b/tests/settings.test.ts @@ -90,6 +90,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( separatorTokens: ['&sep', '/', '|'], nonSeparatorTokens: ['&sep', '/', '|'], dictionary: ['J. K.', 'J. R. R.'], + searchCutoffMs: 1000, } // Add the settings const task = await client.index(index.uid).updateSettings(newSettings) @@ -104,7 +105,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( test(`${permission} key: Update settings with all null values`, async () => { const client = await getClient(permission) - const newSettings = { + const newSettings: Settings = { filterableAttributes: null, sortableAttributes: null, distinctAttribute: null, @@ -132,6 +133,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( separatorTokens: null, nonSeparatorTokens: null, dictionary: null, + searchCutoffMs: null, } // Add the settings const task = await client.index(index.uid).updateSettings(newSettings)