Skip to content

Commit 7b52526

Browse files
authored
feat: add proximity precision settings (#1619)
* feat: add proximity precision settings * Update proximity precision default value byWord
1 parent 7916ad9 commit 7b52526

File tree

6 files changed

+230
-10
lines changed

6 files changed

+230
-10
lines changed

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -903,64 +903,84 @@ client.index('myIndex').resetTypoTolerance(): Promise<EnqueuedTask>
903903

904904
### Separator tokens <!-- omit in toc -->
905905

906-
#### Get separator tokens
906+
#### [Get separator tokens](https://www.meilisearch.com/docs/reference/api/settings#get-separator-tokens)
907907

908908
```ts
909909
client.index('myIndex').getSeparatorTokens(): Promise<SeparatorTokens>
910910
```
911911

912-
#### Update separator tokens
912+
#### [Update separator tokens](https://www.meilisearch.com/docs/reference/api/settings#update-separator-tokens)
913913

914914
```ts
915915
client.index('myIndex').updateSeparatorTokens(separatorTokens: SeparatorTokens | null): Promise<EnqueuedTask>
916916
```
917917

918-
#### Reset separator tokens
918+
#### [Reset separator tokens](https://www.meilisearch.com/docs/reference/api/settings#reset-separator-tokens)
919919

920920
```ts
921921
client.index('myIndex').resetSeparatorTokens(): Promise<EnqueuedTask>
922922
```
923923

924924
### Non Separator tokens <!-- omit in toc -->
925925

926-
#### Get non separator tokens
926+
#### [Get non separator tokens](https://www.meilisearch.com/docs/reference/api/settings#get-non-separator-tokens)
927927

928928
```ts
929929
client.index('myIndex').getNonSeparatorTokens(): Promise<NonSeparatorTokens>
930930
```
931931

932-
#### Update non separator tokens
932+
#### [Update non separator tokens](https://www.meilisearch.com/docs/reference/api/settings#update-non-separator-tokens)
933933

934934
```ts
935935
client.index('myIndex').updateNonSeparatorTokens(nonSeparatorTokens: NonSeparatorTokens | null): Promise<EnqueuedTask>
936936
```
937937

938-
#### Reset non separator tokens
938+
#### [Reset non separator tokens](https://www.meilisearch.com/docs/reference/api/settings#reset-non-separator-tokens)
939939

940940
```ts
941941
client.index('myIndex').resetNonSeparatorTokens(): Promise<EnqueuedTask>
942942
```
943943

944944
### Dictionary <!-- omit in toc -->
945945

946-
#### Get dictionary
946+
#### [Get dictionary](https://www.meilisearch.com/docs/reference/api/settings#get-dictionary)
947947

948948
```ts
949949
client.index('myIndex').getDictionary(): Promise<Dictionary>
950950
```
951951

952-
#### Update dictionary
952+
#### [Update dictionary](https://www.meilisearch.com/docs/reference/api/settings#update-dictionary)
953953

954954
```ts
955955
client.index('myIndex').updateDictionary(dictionary: Dictionary | null): Promise<EnqueuedTask>
956956
```
957957

958-
#### Reset dictionary
958+
#### [Reset dictionary](https://www.meilisearch.com/docs/reference/api/settings#reset-dictionary)
959959

960960
```ts
961961
client.index('myIndex').resetDictionary(): Promise<EnqueuedTask>
962962
```
963963

964+
### Proximity Precision <!-- omit in toc -->
965+
966+
#### [Get proximity precision](https://www.meilisearch.com/docs/reference/api/settings#get-prximity-precision)
967+
968+
```ts
969+
client.index('myIndex').getProximityPrecision(): Promise<ProximityPrecision>
970+
```
971+
972+
#### [Update proximity precision](https://www.meilisearch.com/docs/reference/api/settings#update-proximity-precision)
973+
974+
```ts
975+
client.index('myIndex').updateProximityPrecision(proximityPrecision: ProximityPrecision): Promise<EnqueuedTask>
976+
```
977+
978+
#### [Reset proximity precision](https://www.meilisearch.com/docs/reference/api/settings#reset-proximity-precision)
979+
980+
```ts
981+
client.index('myIndex').resetProximityPrecision(): Promise<EnqueuedTask>
982+
```
983+
964984
### Keys <!-- omit in toc -->
965985

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

src/indexes.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
SeparatorTokens,
5151
NonSeparatorTokens,
5252
Dictionary,
53+
ProximityPrecision,
5354
} from './types'
5455
import { removeUndefinedFromObject } from './utils'
5556
import { HttpRequests } from './http-requests'
@@ -1222,7 +1223,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
12221223
}
12231224

12241225
/**
1225-
* Update the the dictionary settings. Overwrite the old settings.
1226+
* Update the dictionary settings. Overwrite the old settings.
12261227
*
12271228
* @param dictionary - Array that contains the new dictionary settings.
12281229
* @returns Promise containing an EnqueuedTask or null
@@ -1247,6 +1248,50 @@ class Index<T extends Record<string, any> = Record<string, any>> {
12471248

12481249
return task
12491250
}
1251+
1252+
///
1253+
/// PROXIMITY PRECISION
1254+
///
1255+
1256+
/**
1257+
* Get the proximity precision settings of a Meilisearch index.
1258+
*
1259+
* @returns Promise containing the proximity precision settings
1260+
*/
1261+
async getProximityPrecision(): Promise<ProximityPrecision> {
1262+
const url = `indexes/${this.uid}/settings/proximity-precision`
1263+
return await this.httpRequest.get<ProximityPrecision>(url)
1264+
}
1265+
1266+
/**
1267+
* Update the proximity precision settings. Overwrite the old settings.
1268+
*
1269+
* @param proximityPrecision - String that contains the new proximity
1270+
* precision settings.
1271+
* @returns Promise containing an EnqueuedTask or null
1272+
*/
1273+
async updateProximityPrecision(
1274+
proximityPrecision: ProximityPrecision
1275+
): Promise<EnqueuedTask> {
1276+
const url = `indexes/${this.uid}/settings/proximity-precision`
1277+
const task = await this.httpRequest.put(url, proximityPrecision)
1278+
1279+
return new EnqueuedTask(task)
1280+
}
1281+
1282+
/**
1283+
* Reset the proximity precision settings to its default value
1284+
*
1285+
* @returns Promise containing an EnqueuedTask
1286+
*/
1287+
async resetProximityPrecision(): Promise<EnqueuedTask> {
1288+
const url = `indexes/${this.uid}/settings/proximity-precision`
1289+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
1290+
1291+
task.enqueuedAt = new Date(task.enqueuedAt)
1292+
1293+
return task
1294+
}
12501295
}
12511296

12521297
export { Index }

src/types/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ export type TypoTolerance = {
316316
export type SeparatorTokens = string[] | null
317317
export type NonSeparatorTokens = string[] | null
318318
export type Dictionary = string[] | null
319+
export type ProximityPrecision = 'byWord' | 'byAttribute'
319320

320321
export type FacetOrder = 'alpha' | 'count'
321322

@@ -343,6 +344,7 @@ export type Settings = {
343344
separatorTokens?: SeparatorTokens
344345
nonSeparatorTokens?: NonSeparatorTokens
345346
dictionary?: Dictionary
347+
proximityPrecision?: ProximityPrecision
346348
}
347349

348350
/*

tests/__snapshots__/settings.test.ts.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Object {
1818
"pagination": Object {
1919
"maxTotalHits": 1000,
2020
},
21+
"proximityPrecision": "byWord",
2122
"rankingRules": Array [
2223
"words",
2324
"typo",
@@ -63,6 +64,7 @@ Object {
6364
"pagination": Object {
6465
"maxTotalHits": 1000,
6566
},
67+
"proximityPrecision": "byWord",
6668
"rankingRules": Array [
6769
"words",
6870
"typo",
@@ -108,6 +110,7 @@ Object {
108110
"pagination": Object {
109111
"maxTotalHits": 1000,
110112
},
113+
"proximityPrecision": "byWord",
111114
"rankingRules": Array [
112115
"words",
113116
"typo",
@@ -153,6 +156,7 @@ Object {
153156
"pagination": Object {
154157
"maxTotalHits": 1000,
155158
},
159+
"proximityPrecision": "byWord",
156160
"rankingRules": Array [
157161
"words",
158162
"typo",
@@ -198,6 +202,7 @@ Object {
198202
"pagination": Object {
199203
"maxTotalHits": 1000,
200204
},
205+
"proximityPrecision": "byWord",
201206
"rankingRules": Array [
202207
"words",
203208
"typo",
@@ -243,6 +248,7 @@ Object {
243248
"pagination": Object {
244249
"maxTotalHits": 1000,
245250
},
251+
"proximityPrecision": "byWord",
246252
"rankingRules": Array [
247253
"words",
248254
"typo",
@@ -297,6 +303,7 @@ Object {
297303
"pagination": Object {
298304
"maxTotalHits": 1000,
299305
},
306+
"proximityPrecision": "byAttribute",
300307
"rankingRules": Array [
301308
"id:asc",
302309
"typo",
@@ -354,6 +361,7 @@ Object {
354361
"pagination": Object {
355362
"maxTotalHits": 1000,
356363
},
364+
"proximityPrecision": "byWord",
357365
"rankingRules": Array [
358366
"title:asc",
359367
"typo",
@@ -397,6 +405,7 @@ Object {
397405
"pagination": Object {
398406
"maxTotalHits": 1000,
399407
},
408+
"proximityPrecision": "byWord",
400409
"rankingRules": Array [
401410
"words",
402411
"typo",
@@ -442,6 +451,7 @@ Object {
442451
"pagination": Object {
443452
"maxTotalHits": 1000,
444453
},
454+
"proximityPrecision": "byWord",
445455
"rankingRules": Array [
446456
"words",
447457
"typo",
@@ -487,6 +497,7 @@ Object {
487497
"pagination": Object {
488498
"maxTotalHits": 1000,
489499
},
500+
"proximityPrecision": "byWord",
490501
"rankingRules": Array [
491502
"words",
492503
"typo",
@@ -532,6 +543,7 @@ Object {
532543
"pagination": Object {
533544
"maxTotalHits": 1000,
534545
},
546+
"proximityPrecision": "byWord",
535547
"rankingRules": Array [
536548
"words",
537549
"typo",
@@ -577,6 +589,7 @@ Object {
577589
"pagination": Object {
578590
"maxTotalHits": 1000,
579591
},
592+
"proximityPrecision": "byWord",
580593
"rankingRules": Array [
581594
"words",
582595
"typo",
@@ -622,6 +635,7 @@ Object {
622635
"pagination": Object {
623636
"maxTotalHits": 1000,
624637
},
638+
"proximityPrecision": "byWord",
625639
"rankingRules": Array [
626640
"words",
627641
"typo",
@@ -667,6 +681,7 @@ Object {
667681
"pagination": Object {
668682
"maxTotalHits": 1000,
669683
},
684+
"proximityPrecision": "byWord",
670685
"rankingRules": Array [
671686
"words",
672687
"typo",
@@ -721,6 +736,7 @@ Object {
721736
"pagination": Object {
722737
"maxTotalHits": 1000,
723738
},
739+
"proximityPrecision": "byAttribute",
724740
"rankingRules": Array [
725741
"id:asc",
726742
"typo",
@@ -778,6 +794,7 @@ Object {
778794
"pagination": Object {
779795
"maxTotalHits": 1000,
780796
},
797+
"proximityPrecision": "byWord",
781798
"rankingRules": Array [
782799
"title:asc",
783800
"typo",
@@ -821,6 +838,7 @@ Object {
821838
"pagination": Object {
822839
"maxTotalHits": 1000,
823840
},
841+
"proximityPrecision": "byWord",
824842
"rankingRules": Array [
825843
"words",
826844
"typo",

0 commit comments

Comments
 (0)