Skip to content

Commit

Permalink
Update SearchCutoffMs
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-ksh committed Apr 19, 2024
1 parent b017fca commit c1fdf31
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 30 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ client.index('myIndex').resetProximityPrecision(): Promise<EnqueuedTask>

### Embedders <!-- omit in toc -->

⚠️ 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)

Expand All @@ -1003,6 +1003,26 @@ client.index('myIndex').updateEmbedders(embedders: Embedders): Promise<EnqueuedT
client.index('myIndex').resetEmbedders(): Promise<EnqueuedTask>
```

### SearchCutoffMs <!-- omit in toc -->

#### [Get SearchCutoffMs](https://www.meilisearch.com/docs/reference/api/settings#get-search-cutoff-ms)

```ts
client.index('myIndex').getSearchCutoffMs(): Promise<SearchCutoffMs>
```

#### [Update SearchCutoffMs](https://www.meilisearch.com/docs/reference/api/settings#update-search-cutoff-ms)

```ts
client.index('myIndex').updateSearchCutoffMs(searchCutoffMs: SearchCutoffMs): Promise<EnqueuedTask>
```

#### [Reset SearchCutoffMs](https://www.meilisearch.com/docs/reference/api/settings#reset-search-cutoff-ms)

```ts
client.index('myIndex').resetSearchCutoffMs(): Promise<EnqueuedTask>
```

### Keys <!-- omit in toc -->

#### [Get keys](https://www.meilisearch.com/docs/reference/api/keys#get-all-keys)
Expand Down
10 changes: 5 additions & 5 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
Dictionary,
ProximityPrecision,
Embedders,
SearchCutoffMsSettings,
SearchCutoffMs,
} from './types'
import { removeUndefinedFromObject } from './utils'
import { HttpRequests } from './http-requests'
Expand Down Expand Up @@ -1345,9 +1345,9 @@ class Index<T extends Record<string, any> = Record<string, any>> {
*
* @returns Promise containing object of SearchCutoffMs settings
*/
async getSearchCutoffMs(): Promise<SearchCutoffMsSettings> {
async getSearchCutoffMs(): Promise<SearchCutoffMs> {
const url = `indexes/${this.uid}/settings/search-cutoff-ms`
return await this.httpRequest.get<SearchCutoffMsSettings>(url)
return await this.httpRequest.get<SearchCutoffMs>(url)
}

/**
Expand All @@ -1357,10 +1357,10 @@ class Index<T extends Record<string, any> = Record<string, any>> {
* @returns Promise containing an EnqueuedTask
*/
async updateSearchCutoffMs(
searchCutoffMs: SearchCutoffMsSettings
searchCutoffMs: SearchCutoffMs
): Promise<EnqueuedTask> {
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)
}
Expand Down
6 changes: 2 additions & 4 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -394,7 +392,7 @@ export type Settings = {
dictionary?: Dictionary
proximityPrecision?: ProximityPrecision
embedders?: Embedders
searchCutoffMs?: SearchCutoffMsSettings
searchCutoffMs?: SearchCutoffMs
}

/*
Expand Down
18 changes: 18 additions & 0 deletions tests/__snapshots__/settings.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports[`Test on settings Admin key: Get default settings of an index 1`] = `
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -73,6 +74,7 @@ exports[`Test on settings Admin key: Get default settings of empty index with pr
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -119,6 +121,7 @@ exports[`Test on settings Admin key: Reset settings 1`] = `
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -165,6 +168,7 @@ exports[`Test on settings Admin key: Reset settings of empty index 1`] = `
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -211,6 +215,7 @@ exports[`Test on settings Admin key: Update searchableAttributes settings on emp
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"title",
],
Expand Down Expand Up @@ -257,6 +262,7 @@ exports[`Test on settings Admin key: Update searchableAttributes settings on emp
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"title",
],
Expand Down Expand Up @@ -308,6 +314,7 @@ exports[`Test on settings Admin key: Update settings 1`] = `
"id:asc",
"typo",
],
"searchCutoffMs": 1000,
"searchableAttributes": [
"title",
],
Expand Down Expand Up @@ -366,6 +373,7 @@ exports[`Test on settings Admin key: Update settings on empty index with primary
"title:asc",
"typo",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -414,6 +422,7 @@ exports[`Test on settings Admin key: Update settings with all null values 1`] =
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -460,6 +469,7 @@ exports[`Test on settings Master key: Get default settings of an index 1`] = `
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -506,6 +516,7 @@ exports[`Test on settings Master key: Get default settings of empty index with p
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -552,6 +563,7 @@ exports[`Test on settings Master key: Reset settings 1`] = `
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -598,6 +610,7 @@ exports[`Test on settings Master key: Reset settings of empty index 1`] = `
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -644,6 +657,7 @@ exports[`Test on settings Master key: Update searchableAttributes settings on em
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"title",
],
Expand Down Expand Up @@ -690,6 +704,7 @@ exports[`Test on settings Master key: Update searchableAttributes settings on em
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"title",
],
Expand Down Expand Up @@ -741,6 +756,7 @@ exports[`Test on settings Master key: Update settings 1`] = `
"id:asc",
"typo",
],
"searchCutoffMs": 1000,
"searchableAttributes": [
"title",
],
Expand Down Expand Up @@ -799,6 +815,7 @@ exports[`Test on settings Master key: Update settings on empty index with primar
"title:asc",
"typo",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down Expand Up @@ -847,6 +864,7 @@ exports[`Test on settings Master key: Update settings with all null values 1`] =
"sort",
"exactness",
],
"searchCutoffMs": null,
"searchableAttributes": [
"*",
],
Expand Down
30 changes: 11 additions & 19 deletions tests/searchCutoffMs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const index = {
uid: 'movies_test',
}

const DEFAULT_SEARCHCUTOFFMS = 1500
const DEFAULT_SEARCHCUTOFFMS = null

jest.setTimeout(100 * 1000)

Expand All @@ -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)
Expand All @@ -54,24 +52,20 @@ 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)
await client.index(index.uid).waitForTask(task.taskUid)

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)
Expand All @@ -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)
Expand All @@ -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)
})
}
)
Expand All @@ -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)
})

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion tests/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c1fdf31

Please sign in to comment.