Skip to content

Commit 0dc6d90

Browse files
authored
Merge pull request #1645 from amit-ksh/feat/update-searchCutoffMs
Update SearchCutoffMs
2 parents f2f9b18 + c1fdf31 commit 0dc6d90

File tree

6 files changed

+60
-30
lines changed

6 files changed

+60
-30
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ client.index('myIndex').resetProximityPrecision(): Promise<EnqueuedTask>
983983

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

986-
⚠️ This feature is experimental. Activate the [`vectorStore` experimental feature to use it](https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features)
986+
⚠️ This feature is experimental. Activate the [`vectorStore` experimental feature to use it](https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features)
987987

988988
#### [Get embedders](https://www.meilisearch.com/docs/reference/api/settings#get-embedders)
989989

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

1006+
### SearchCutoffMs <!-- omit in toc -->
1007+
1008+
#### [Get SearchCutoffMs](https://www.meilisearch.com/docs/reference/api/settings#get-search-cutoff-ms)
1009+
1010+
```ts
1011+
client.index('myIndex').getSearchCutoffMs(): Promise<SearchCutoffMs>
1012+
```
1013+
1014+
#### [Update SearchCutoffMs](https://www.meilisearch.com/docs/reference/api/settings#update-search-cutoff-ms)
1015+
1016+
```ts
1017+
client.index('myIndex').updateSearchCutoffMs(searchCutoffMs: SearchCutoffMs): Promise<EnqueuedTask>
1018+
```
1019+
1020+
#### [Reset SearchCutoffMs](https://www.meilisearch.com/docs/reference/api/settings#reset-search-cutoff-ms)
1021+
1022+
```ts
1023+
client.index('myIndex').resetSearchCutoffMs(): Promise<EnqueuedTask>
1024+
```
1025+
10061026
### Keys <!-- omit in toc -->
10071027

10081028
#### [Get keys](https://www.meilisearch.com/docs/reference/api/keys#get-all-keys)

src/indexes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import {
5252
Dictionary,
5353
ProximityPrecision,
5454
Embedders,
55-
SearchCutoffMsSettings,
55+
SearchCutoffMs,
5656
} from './types'
5757
import { removeUndefinedFromObject } from './utils'
5858
import { HttpRequests } from './http-requests'
@@ -1345,9 +1345,9 @@ class Index<T extends Record<string, any> = Record<string, any>> {
13451345
*
13461346
* @returns Promise containing object of SearchCutoffMs settings
13471347
*/
1348-
async getSearchCutoffMs(): Promise<SearchCutoffMsSettings> {
1348+
async getSearchCutoffMs(): Promise<SearchCutoffMs> {
13491349
const url = `indexes/${this.uid}/settings/search-cutoff-ms`
1350-
return await this.httpRequest.get<SearchCutoffMsSettings>(url)
1350+
return await this.httpRequest.get<SearchCutoffMs>(url)
13511351
}
13521352

13531353
/**
@@ -1357,10 +1357,10 @@ class Index<T extends Record<string, any> = Record<string, any>> {
13571357
* @returns Promise containing an EnqueuedTask
13581358
*/
13591359
async updateSearchCutoffMs(
1360-
searchCutoffMs: SearchCutoffMsSettings
1360+
searchCutoffMs: SearchCutoffMs
13611361
): Promise<EnqueuedTask> {
13621362
const url = `indexes/${this.uid}/settings/search-cutoff-ms`
1363-
const task = await this.httpRequest.patch(url, searchCutoffMs)
1363+
const task = await this.httpRequest.put(url, searchCutoffMs)
13641364

13651365
return new EnqueuedTask(task)
13661366
}

src/types/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,7 @@ export type PaginationSettings = {
374374
maxTotalHits?: number | null
375375
}
376376

377-
export type SearchCutoffMsSettings = {
378-
searchCutoffMs?: number | null
379-
}
377+
export type SearchCutoffMs = number | null
380378

381379
export type Settings = {
382380
filterableAttributes?: FilterableAttributes
@@ -395,7 +393,7 @@ export type Settings = {
395393
dictionary?: Dictionary
396394
proximityPrecision?: ProximityPrecision
397395
embedders?: Embedders
398-
searchCutoffMs?: SearchCutoffMsSettings
396+
searchCutoffMs?: SearchCutoffMs
399397
}
400398

401399
/*

tests/__snapshots__/settings.test.ts.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ exports[`Test on settings Admin key: Get default settings of an index 1`] = `
2727
"sort",
2828
"exactness",
2929
],
30+
"searchCutoffMs": null,
3031
"searchableAttributes": [
3132
"*",
3233
],
@@ -73,6 +74,7 @@ exports[`Test on settings Admin key: Get default settings of empty index with pr
7374
"sort",
7475
"exactness",
7576
],
77+
"searchCutoffMs": null,
7678
"searchableAttributes": [
7779
"*",
7880
],
@@ -119,6 +121,7 @@ exports[`Test on settings Admin key: Reset settings 1`] = `
119121
"sort",
120122
"exactness",
121123
],
124+
"searchCutoffMs": null,
122125
"searchableAttributes": [
123126
"*",
124127
],
@@ -165,6 +168,7 @@ exports[`Test on settings Admin key: Reset settings of empty index 1`] = `
165168
"sort",
166169
"exactness",
167170
],
171+
"searchCutoffMs": null,
168172
"searchableAttributes": [
169173
"*",
170174
],
@@ -211,6 +215,7 @@ exports[`Test on settings Admin key: Update searchableAttributes settings on emp
211215
"sort",
212216
"exactness",
213217
],
218+
"searchCutoffMs": null,
214219
"searchableAttributes": [
215220
"title",
216221
],
@@ -257,6 +262,7 @@ exports[`Test on settings Admin key: Update searchableAttributes settings on emp
257262
"sort",
258263
"exactness",
259264
],
265+
"searchCutoffMs": null,
260266
"searchableAttributes": [
261267
"title",
262268
],
@@ -308,6 +314,7 @@ exports[`Test on settings Admin key: Update settings 1`] = `
308314
"id:asc",
309315
"typo",
310316
],
317+
"searchCutoffMs": 1000,
311318
"searchableAttributes": [
312319
"title",
313320
],
@@ -366,6 +373,7 @@ exports[`Test on settings Admin key: Update settings on empty index with primary
366373
"title:asc",
367374
"typo",
368375
],
376+
"searchCutoffMs": null,
369377
"searchableAttributes": [
370378
"*",
371379
],
@@ -414,6 +422,7 @@ exports[`Test on settings Admin key: Update settings with all null values 1`] =
414422
"sort",
415423
"exactness",
416424
],
425+
"searchCutoffMs": null,
417426
"searchableAttributes": [
418427
"*",
419428
],
@@ -460,6 +469,7 @@ exports[`Test on settings Master key: Get default settings of an index 1`] = `
460469
"sort",
461470
"exactness",
462471
],
472+
"searchCutoffMs": null,
463473
"searchableAttributes": [
464474
"*",
465475
],
@@ -506,6 +516,7 @@ exports[`Test on settings Master key: Get default settings of empty index with p
506516
"sort",
507517
"exactness",
508518
],
519+
"searchCutoffMs": null,
509520
"searchableAttributes": [
510521
"*",
511522
],
@@ -552,6 +563,7 @@ exports[`Test on settings Master key: Reset settings 1`] = `
552563
"sort",
553564
"exactness",
554565
],
566+
"searchCutoffMs": null,
555567
"searchableAttributes": [
556568
"*",
557569
],
@@ -598,6 +610,7 @@ exports[`Test on settings Master key: Reset settings of empty index 1`] = `
598610
"sort",
599611
"exactness",
600612
],
613+
"searchCutoffMs": null,
601614
"searchableAttributes": [
602615
"*",
603616
],
@@ -644,6 +657,7 @@ exports[`Test on settings Master key: Update searchableAttributes settings on em
644657
"sort",
645658
"exactness",
646659
],
660+
"searchCutoffMs": null,
647661
"searchableAttributes": [
648662
"title",
649663
],
@@ -690,6 +704,7 @@ exports[`Test on settings Master key: Update searchableAttributes settings on em
690704
"sort",
691705
"exactness",
692706
],
707+
"searchCutoffMs": null,
693708
"searchableAttributes": [
694709
"title",
695710
],
@@ -741,6 +756,7 @@ exports[`Test on settings Master key: Update settings 1`] = `
741756
"id:asc",
742757
"typo",
743758
],
759+
"searchCutoffMs": 1000,
744760
"searchableAttributes": [
745761
"title",
746762
],
@@ -799,6 +815,7 @@ exports[`Test on settings Master key: Update settings on empty index with primar
799815
"title:asc",
800816
"typo",
801817
],
818+
"searchCutoffMs": null,
802819
"searchableAttributes": [
803820
"*",
804821
],
@@ -847,6 +864,7 @@ exports[`Test on settings Master key: Update settings with all null values 1`] =
847864
"sort",
848865
"exactness",
849866
],
867+
"searchCutoffMs": null,
850868
"searchableAttributes": [
851869
"*",
852870
],

tests/searchCutoffMs.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const index = {
1212
uid: 'movies_test',
1313
}
1414

15-
const DEFAULT_SEARCHCUTOFFMS = 1500
15+
const DEFAULT_SEARCHCUTOFFMS = null
1616

1717
jest.setTimeout(100 * 1000)
1818

@@ -34,14 +34,12 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
3434
const client = await getClient(permission)
3535
const response = await client.index(index.uid).getSearchCutoffMs()
3636

37-
expect(response).toEqual({ searchCutoffMs: DEFAULT_SEARCHCUTOFFMS })
37+
expect(response).toEqual(DEFAULT_SEARCHCUTOFFMS)
3838
})
3939

4040
test(`${permission} key: Update searchCutoffMs to valid value`, async () => {
4141
const client = await getClient(permission)
42-
const newSearchCutoffMs = {
43-
searchCutoffMs: 100,
44-
}
42+
const newSearchCutoffMs = 100
4543
const task = await client
4644
.index(index.uid)
4745
.updateSearchCutoffMs(newSearchCutoffMs)
@@ -54,24 +52,20 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
5452

5553
test(`${permission} key: Update searchCutoffMs to null`, async () => {
5654
const client = await getClient(permission)
57-
const newSearchCutoffMs = {
58-
searchCutoffMs: null,
59-
}
55+
const newSearchCutoffMs = null
6056
const task = await client
6157
.index(index.uid)
6258
.updateSearchCutoffMs(newSearchCutoffMs)
6359
await client.index(index.uid).waitForTask(task.taskUid)
6460

6561
const response = await client.index(index.uid).getSearchCutoffMs()
6662

67-
expect(response).toEqual({ searchCutoffMs: DEFAULT_SEARCHCUTOFFMS })
63+
expect(response).toEqual(DEFAULT_SEARCHCUTOFFMS)
6864
})
6965

7066
test(`${permission} key: Update searchCutoffMs with invalid value`, async () => {
7167
const client = await getClient(permission)
72-
const newSearchCutoffMs = {
73-
searchCutoffMs: 'hello', // bad searchCutoffMs value
74-
} as any
68+
const newSearchCutoffMs = 'hello' as any // bad searchCutoffMs value
7569

7670
await expect(
7771
client.index(index.uid).updateSearchCutoffMs(newSearchCutoffMs)
@@ -83,9 +77,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
8377

8478
test(`${permission} key: Reset searchCutoffMs`, async () => {
8579
const client = await getClient(permission)
86-
const newSearchCutoffMs = {
87-
searchCutoffMs: 100,
88-
}
80+
const newSearchCutoffMs = 100
8981
const updateTask = await client
9082
.index(index.uid)
9183
.updateSearchCutoffMs(newSearchCutoffMs)
@@ -95,7 +87,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
9587

9688
const response = await client.index(index.uid).getSearchCutoffMs()
9789

98-
expect(response).toEqual({ searchCutoffMs: DEFAULT_SEARCHCUTOFFMS })
90+
expect(response).toEqual(DEFAULT_SEARCHCUTOFFMS)
9991
})
10092
}
10193
)
@@ -119,7 +111,7 @@ describe.each([{ permission: 'Search' }])(
119111
test(`${permission} key: try to update searchCutoffMs and be denied`, async () => {
120112
const client = await getClient(permission)
121113
await expect(
122-
client.index(index.uid).updateSearchCutoffMs({ searchCutoffMs: 100 })
114+
client.index(index.uid).updateSearchCutoffMs(100)
123115
).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY)
124116
})
125117

@@ -154,7 +146,7 @@ describe.each([{ permission: 'No' }])(
154146
test(`${permission} key: try to update searchCutoffMs and be denied`, async () => {
155147
const client = await getClient(permission)
156148
await expect(
157-
client.index(index.uid).updateSearchCutoffMs({ searchCutoffMs: 100 })
149+
client.index(index.uid).updateSearchCutoffMs(100)
158150
).rejects.toHaveProperty(
159151
'code',
160152
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
@@ -198,7 +190,7 @@ describe.each([
198190
const client = new MeiliSearch({ host })
199191
const strippedHost = trailing ? host.slice(0, -1) : host
200192
await expect(
201-
client.index(index.uid).updateSearchCutoffMs({ searchCutoffMs: null })
193+
client.index(index.uid).updateSearchCutoffMs(null)
202194
).rejects.toHaveProperty(
203195
'message',
204196
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(

tests/settings.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
9090
separatorTokens: ['&sep', '/', '|'],
9191
nonSeparatorTokens: ['&sep', '/', '|'],
9292
dictionary: ['J. K.', 'J. R. R.'],
93+
searchCutoffMs: 1000,
9394
}
9495
// Add the settings
9596
const task = await client.index(index.uid).updateSettings(newSettings)
@@ -104,7 +105,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
104105

105106
test(`${permission} key: Update settings with all null values`, async () => {
106107
const client = await getClient(permission)
107-
const newSettings = {
108+
const newSettings: Settings = {
108109
filterableAttributes: null,
109110
sortableAttributes: null,
110111
distinctAttribute: null,
@@ -132,6 +133,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
132133
separatorTokens: null,
133134
nonSeparatorTokens: null,
134135
dictionary: null,
136+
searchCutoffMs: null,
135137
}
136138
// Add the settings
137139
const task = await client.index(index.uid).updateSettings(newSettings)

0 commit comments

Comments
 (0)