Skip to content

Commit 2f87b7b

Browse files
authored
Merge pull request #1790 from meilisearch/feat/add-1.12-new-settings
Add new `prefixSearch` and `facetSearch` index settings
2 parents 3994181 + 8ef18d0 commit 2f87b7b

File tree

9 files changed

+724
-0
lines changed

9 files changed

+724
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,46 @@ client.index('myIndex').updateProximityPrecision(proximityPrecision: ProximityPr
995995
client.index('myIndex').resetProximityPrecision(): Promise<EnqueuedTask>
996996
```
997997

998+
### Facet search settings <!-- omit in toc -->
999+
1000+
#### [Get facet search settings](https://www.meilisearch.com/docs/reference/api/settings#get-facet-search-settings)
1001+
1002+
```ts
1003+
client.index('myIndex').getFacetSearch(): Promise<boolean>
1004+
```
1005+
1006+
#### [Update facet search settings](https://www.meilisearch.com/docs/reference/api/settings#update-facet-search-settings)
1007+
1008+
```ts
1009+
client.index('myIndex').updateFacetSearch(enabled: boolean): Promise<EnqueuedTask>
1010+
```
1011+
1012+
#### [Reset facet search settings](https://www.meilisearch.com/docs/reference/api/settings#reset-facet-search-settings)
1013+
1014+
```ts
1015+
client.index('myIndex').resetFacetSearch(): Promise<EnqueuedTask>
1016+
```
1017+
1018+
### Prefix search settings <!-- omit in toc -->
1019+
1020+
#### [Get prefix search settings](https://www.meilisearch.com/docs/reference/api/settings#get-prefix-search-settings)
1021+
1022+
```ts
1023+
client.index('myIndex').getPrefixSearch(): Promise<PrefixSearch>
1024+
```
1025+
1026+
#### [Update prefix search settings](https://www.meilisearch.com/docs/reference/api/settings#update-prefix-search-settings)
1027+
1028+
```ts
1029+
client.index('myIndex').updatePrefixSearch(prefixSearch: PrefixSearch): Promise<EnqueuedTask>
1030+
```
1031+
1032+
#### [Reset prefix search settings](https://www.meilisearch.com/docs/reference/api/settings#reset-prefix-search-settings)
1033+
1034+
```ts
1035+
client.index('myIndex').resetPrefixSearch(): Promise<EnqueuedTask>
1036+
```
1037+
9981038
### Embedders <!-- omit in toc -->
9991039

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

src/indexes.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
SearchSimilarDocumentsParams,
5757
LocalizedAttributes,
5858
UpdateDocumentsByFunctionOptions,
59+
PrefixSearch,
5960
} from "./types";
6061
import { removeUndefinedFromObject } from "./utils";
6162
import { HttpRequests } from "./http-requests";
@@ -1457,6 +1458,80 @@ class Index<T extends Record<string, any> = Record<string, any>> {
14571458

14581459
return new EnqueuedTask(task);
14591460
}
1461+
1462+
///
1463+
/// FACET SEARCH SETTINGS
1464+
///
1465+
1466+
/**
1467+
* Get the facet search settings.
1468+
*
1469+
* @returns Promise containing object of facet search settings
1470+
*/
1471+
async getFacetSearch(): Promise<boolean> {
1472+
const url = `indexes/${this.uid}/settings/facet-search`;
1473+
return await this.httpRequest.get<boolean>(url);
1474+
}
1475+
1476+
/**
1477+
* Update the facet search settings.
1478+
*
1479+
* @param facetSearch - Boolean value
1480+
* @returns Promise containing an EnqueuedTask
1481+
*/
1482+
async updateFacetSearch(facetSearch: boolean): Promise<EnqueuedTask> {
1483+
const url = `indexes/${this.uid}/settings/facet-search`;
1484+
const task = await this.httpRequest.put(url, facetSearch);
1485+
return new EnqueuedTask(task);
1486+
}
1487+
1488+
/**
1489+
* Reset the facet search settings.
1490+
*
1491+
* @returns Promise containing an EnqueuedTask
1492+
*/
1493+
async resetFacetSearch(): Promise<EnqueuedTask> {
1494+
const url = `indexes/${this.uid}/settings/facet-search`;
1495+
const task = await this.httpRequest.delete(url);
1496+
return new EnqueuedTask(task);
1497+
}
1498+
1499+
///
1500+
/// PREFIX SEARCH SETTINGS
1501+
///
1502+
1503+
/**
1504+
* Get the prefix search settings.
1505+
*
1506+
* @returns Promise containing object of prefix search settings
1507+
*/
1508+
async getPrefixSearch(): Promise<PrefixSearch> {
1509+
const url = `indexes/${this.uid}/settings/prefix-search`;
1510+
return await this.httpRequest.get<PrefixSearch>(url);
1511+
}
1512+
1513+
/**
1514+
* Update the prefix search settings.
1515+
*
1516+
* @param prefixSearch - PrefixSearch value
1517+
* @returns Promise containing an EnqueuedTask
1518+
*/
1519+
async updatePrefixSearch(prefixSearch: PrefixSearch): Promise<EnqueuedTask> {
1520+
const url = `indexes/${this.uid}/settings/prefix-search`;
1521+
const task = await this.httpRequest.put(url, prefixSearch);
1522+
return new EnqueuedTask(task);
1523+
}
1524+
1525+
/**
1526+
* Reset the prefix search settings.
1527+
*
1528+
* @returns Promise containing an EnqueuedTask
1529+
*/
1530+
async resetPrefixSearch(): Promise<EnqueuedTask> {
1531+
const url = `indexes/${this.uid}/settings/prefix-search`;
1532+
const task = await this.httpRequest.delete(url);
1533+
return new EnqueuedTask(task);
1534+
}
14601535
}
14611536

14621537
export { Index };

src/types/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ export type LocalizedAttribute = {
492492

493493
export type LocalizedAttributes = LocalizedAttribute[] | null;
494494

495+
export type PrefixSearch = "indexingTime" | "disabled";
496+
495497
export type Settings = {
496498
filterableAttributes?: FilterableAttributes;
497499
distinctAttribute?: DistinctAttribute;
@@ -511,6 +513,17 @@ export type Settings = {
511513
embedders?: Embedders;
512514
searchCutoffMs?: SearchCutoffMs;
513515
localizedAttributes?: LocalizedAttributes;
516+
517+
/**
518+
* Enable facet searching on all the filters of an index (requires Meilisearch
519+
* 1.12.0 or later)
520+
*/
521+
facetSearch?: boolean;
522+
/**
523+
* Enable the ability to search a word by prefix on an index (requires
524+
* Meilisearch 1.12.0 or later)
525+
*/
526+
prefixSearch?: "indexingTime" | "disabled";
514527
};
515528

516529
/*
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Test on facet search settings > Admin key: Get facetSearch settings on empty index 1`] = `true`;
4+
5+
exports[`Test on facet search settings > Admin key: Reset facetSearch settings on an empty index 1`] = `true`;
6+
7+
exports[`Test on facet search settings > Master key: Get facetSearch settings on empty index 1`] = `true`;
8+
9+
exports[`Test on facet search settings > Master key: Reset facetSearch settings on an empty index 1`] = `true`;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Test on prefix search settings > Admin key: Get prefixSearch settings on empty index 1`] = `"indexingTime"`;
4+
5+
exports[`Test on prefix search settings > Admin key: Reset prefixSearch settings on an empty index 1`] = `"indexingTime"`;
6+
7+
exports[`Test on prefix search settings > Master key: Get prefixSearch settings on empty index 1`] = `"indexingTime"`;
8+
9+
exports[`Test on prefix search settings > Master key: Reset prefixSearch settings on an empty index 1`] = `"indexingTime"`;

tests/__snapshots__/settings.test.ts.snap

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,106 @@ exports[`Test on settings > Admin key: Update embedders settings 1`] = `
309309
}
310310
`;
311311

312+
exports[`Test on settings > Admin key: Update facetSearch settings on empty index 1`] = `
313+
{
314+
"dictionary": [],
315+
"displayedAttributes": [
316+
"*",
317+
],
318+
"distinctAttribute": null,
319+
"facetSearch": false,
320+
"faceting": {
321+
"maxValuesPerFacet": 100,
322+
"sortFacetValuesBy": {
323+
"*": "alpha",
324+
},
325+
},
326+
"filterableAttributes": [],
327+
"localizedAttributes": null,
328+
"nonSeparatorTokens": [],
329+
"pagination": {
330+
"maxTotalHits": 1000,
331+
},
332+
"prefixSearch": "indexingTime",
333+
"proximityPrecision": "byWord",
334+
"rankingRules": [
335+
"words",
336+
"typo",
337+
"proximity",
338+
"attribute",
339+
"sort",
340+
"exactness",
341+
],
342+
"searchCutoffMs": null,
343+
"searchableAttributes": [
344+
"*",
345+
],
346+
"separatorTokens": [],
347+
"sortableAttributes": [],
348+
"stopWords": [],
349+
"synonyms": {},
350+
"typoTolerance": {
351+
"disableOnAttributes": [],
352+
"disableOnWords": [],
353+
"enabled": true,
354+
"minWordSizeForTypos": {
355+
"oneTypo": 5,
356+
"twoTypos": 9,
357+
},
358+
},
359+
}
360+
`;
361+
362+
exports[`Test on settings > Admin key: Update prefixSearch settings on an empty index 1`] = `
363+
{
364+
"dictionary": [],
365+
"displayedAttributes": [
366+
"*",
367+
],
368+
"distinctAttribute": null,
369+
"facetSearch": true,
370+
"faceting": {
371+
"maxValuesPerFacet": 100,
372+
"sortFacetValuesBy": {
373+
"*": "alpha",
374+
},
375+
},
376+
"filterableAttributes": [],
377+
"localizedAttributes": null,
378+
"nonSeparatorTokens": [],
379+
"pagination": {
380+
"maxTotalHits": 1000,
381+
},
382+
"prefixSearch": "disabled",
383+
"proximityPrecision": "byWord",
384+
"rankingRules": [
385+
"words",
386+
"typo",
387+
"proximity",
388+
"attribute",
389+
"sort",
390+
"exactness",
391+
],
392+
"searchCutoffMs": null,
393+
"searchableAttributes": [
394+
"*",
395+
],
396+
"separatorTokens": [],
397+
"sortableAttributes": [],
398+
"stopWords": [],
399+
"synonyms": {},
400+
"typoTolerance": {
401+
"disableOnAttributes": [],
402+
"disableOnWords": [],
403+
"enabled": true,
404+
"minWordSizeForTypos": {
405+
"oneTypo": 5,
406+
"twoTypos": 9,
407+
},
408+
},
409+
}
410+
`;
411+
312412
exports[`Test on settings > Admin key: Update searchableAttributes settings on empty index 1`] = `
313413
{
314414
"dictionary": [],
@@ -887,6 +987,106 @@ exports[`Test on settings > Master key: Update embedders settings 1`] = `
887987
}
888988
`;
889989

990+
exports[`Test on settings > Master key: Update facetSearch settings on empty index 1`] = `
991+
{
992+
"dictionary": [],
993+
"displayedAttributes": [
994+
"*",
995+
],
996+
"distinctAttribute": null,
997+
"facetSearch": false,
998+
"faceting": {
999+
"maxValuesPerFacet": 100,
1000+
"sortFacetValuesBy": {
1001+
"*": "alpha",
1002+
},
1003+
},
1004+
"filterableAttributes": [],
1005+
"localizedAttributes": null,
1006+
"nonSeparatorTokens": [],
1007+
"pagination": {
1008+
"maxTotalHits": 1000,
1009+
},
1010+
"prefixSearch": "indexingTime",
1011+
"proximityPrecision": "byWord",
1012+
"rankingRules": [
1013+
"words",
1014+
"typo",
1015+
"proximity",
1016+
"attribute",
1017+
"sort",
1018+
"exactness",
1019+
],
1020+
"searchCutoffMs": null,
1021+
"searchableAttributes": [
1022+
"*",
1023+
],
1024+
"separatorTokens": [],
1025+
"sortableAttributes": [],
1026+
"stopWords": [],
1027+
"synonyms": {},
1028+
"typoTolerance": {
1029+
"disableOnAttributes": [],
1030+
"disableOnWords": [],
1031+
"enabled": true,
1032+
"minWordSizeForTypos": {
1033+
"oneTypo": 5,
1034+
"twoTypos": 9,
1035+
},
1036+
},
1037+
}
1038+
`;
1039+
1040+
exports[`Test on settings > Master key: Update prefixSearch settings on an empty index 1`] = `
1041+
{
1042+
"dictionary": [],
1043+
"displayedAttributes": [
1044+
"*",
1045+
],
1046+
"distinctAttribute": null,
1047+
"facetSearch": true,
1048+
"faceting": {
1049+
"maxValuesPerFacet": 100,
1050+
"sortFacetValuesBy": {
1051+
"*": "alpha",
1052+
},
1053+
},
1054+
"filterableAttributes": [],
1055+
"localizedAttributes": null,
1056+
"nonSeparatorTokens": [],
1057+
"pagination": {
1058+
"maxTotalHits": 1000,
1059+
},
1060+
"prefixSearch": "disabled",
1061+
"proximityPrecision": "byWord",
1062+
"rankingRules": [
1063+
"words",
1064+
"typo",
1065+
"proximity",
1066+
"attribute",
1067+
"sort",
1068+
"exactness",
1069+
],
1070+
"searchCutoffMs": null,
1071+
"searchableAttributes": [
1072+
"*",
1073+
],
1074+
"separatorTokens": [],
1075+
"sortableAttributes": [],
1076+
"stopWords": [],
1077+
"synonyms": {},
1078+
"typoTolerance": {
1079+
"disableOnAttributes": [],
1080+
"disableOnWords": [],
1081+
"enabled": true,
1082+
"minWordSizeForTypos": {
1083+
"oneTypo": 5,
1084+
"twoTypos": 9,
1085+
},
1086+
},
1087+
}
1088+
`;
1089+
8901090
exports[`Test on settings > Master key: Update searchableAttributes settings on empty index 1`] = `
8911091
{
8921092
"dictionary": [],

0 commit comments

Comments
 (0)