Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add proximity precision settings #1619

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -903,64 +903,84 @@ client.index('myIndex').resetTypoTolerance(): Promise<EnqueuedTask>

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

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

```ts
client.index('myIndex').getSeparatorTokens(): Promise<SeparatorTokens>
```

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

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

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

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

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

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

```ts
client.index('myIndex').getNonSeparatorTokens(): Promise<NonSeparatorTokens>
```

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

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

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

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

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

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

```ts
client.index('myIndex').getDictionary(): Promise<Dictionary>
```

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

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

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

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

### Proximity Precision <!-- omit in toc -->

#### [Get proximity precision](https://www.meilisearch.com/docs/reference/api/settings#get-prximity-precision)

```ts
client.index('myIndex').getProximityPrecision(): Promise<ProximityPrecision>
```

#### [Update proximity precision](https://www.meilisearch.com/docs/reference/api/settings#update-proximity-precision)

```ts
client.index('myIndex').updateProximityPrecision(proximityPrecision: ProximityPrecision): Promise<EnqueuedTask>
```

#### [Reset proximity precision](https://www.meilisearch.com/docs/reference/api/settings#reset-proximity-precision)

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

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

#### [Get keys](https://www.meilisearch.com/docs/reference/api/keys#get-all-keys)
Expand Down
47 changes: 46 additions & 1 deletion src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
SeparatorTokens,
NonSeparatorTokens,
Dictionary,
ProximityPrecision,
} from './types'
import { removeUndefinedFromObject } from './utils'
import { HttpRequests } from './http-requests'
Expand Down Expand Up @@ -1222,7 +1223,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
}

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

return task
}

///
/// PROXIMITY PRECISION
///

/**
* Get the proximity precision settings of a Meilisearch index.
*
* @returns Promise containing the proximity precision settings
*/
async getProximityPrecision(): Promise<ProximityPrecision> {
const url = `indexes/${this.uid}/settings/proximity-precision`
return await this.httpRequest.get<ProximityPrecision>(url)
}

/**
* Update the proximity precision settings. Overwrite the old settings.
*
* @param proximityPrecision - String that contains the new proximity
* precision settings.
* @returns Promise containing an EnqueuedTask or null
*/
async updateProximityPrecision(
proximityPrecision: ProximityPrecision
): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/proximity-precision`
const task = await this.httpRequest.put(url, proximityPrecision)

return new EnqueuedTask(task)
}

/**
* Reset the proximity precision settings to its default value
*
* @returns Promise containing an EnqueuedTask
*/
async resetProximityPrecision(): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/proximity-precision`
const task = await this.httpRequest.delete<EnqueuedTask>(url)

task.enqueuedAt = new Date(task.enqueuedAt)

return task
}
}

export { Index }
2 changes: 2 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export type TypoTolerance = {
export type SeparatorTokens = string[] | null
export type NonSeparatorTokens = string[] | null
export type Dictionary = string[] | null
export type ProximityPrecision = 'byWord' | 'byAttribute'

export type FacetOrder = 'alpha' | 'count'

Expand Down Expand Up @@ -343,6 +344,7 @@ export type Settings = {
separatorTokens?: SeparatorTokens
nonSeparatorTokens?: NonSeparatorTokens
dictionary?: Dictionary
proximityPrecision?: ProximityPrecision
}

/*
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 @@ -18,6 +18,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -63,6 +64,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -108,6 +110,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -153,6 +156,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -198,6 +202,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -243,6 +248,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -297,6 +303,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byAttribute",
"rankingRules": Array [
"id:asc",
"typo",
Expand Down Expand Up @@ -354,6 +361,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"title:asc",
"typo",
Expand Down Expand Up @@ -397,6 +405,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -442,6 +451,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -487,6 +497,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -532,6 +543,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -577,6 +589,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -622,6 +635,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -667,6 +681,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down Expand Up @@ -721,6 +736,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byAttribute",
"rankingRules": Array [
"id:asc",
"typo",
Expand Down Expand Up @@ -778,6 +794,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"title:asc",
"typo",
Expand Down Expand Up @@ -821,6 +838,7 @@ Object {
"pagination": Object {
"maxTotalHits": 1000,
},
"proximityPrecision": "byWord",
"rankingRules": Array [
"words",
"typo",
Expand Down
Loading
Loading