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

Changes related to the next Meilisearch release (v1.4.0) #1573

Merged
merged 4 commits into from
Sep 25, 2023
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
18 changes: 18 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,28 @@ update_faceting_settings_1: |-
})
reset_faceting_settings_1: |-
client.index('books').resetFaceting()
get_dictionary_1: |-
client.index('books').getDictionary()
update_dictionary_1: |-
client.index('books').updateDictionary(['J. R. R.', 'W. E. B.'])
reset_dictionary_1: |-
client.index('books').resetDictionary()
search_parameter_guide_sort_1: |-
client.index('books').search('science fiction', {
sort: ['price:asc'],
})
get_separator_tokens_1: |-
client.index('books').getSeparatorTokens()
update_separator_tokens_1: |-
client.index('books').updateSeparatorTokens(['|', '…'])
reset_separator_tokens_1: |-
client.index('books').resetSeparatorTokens()
get_non_separator_tokens_1: |-
client.index('books').getNonSeparatorTokens()
update_non_separator_tokens_1: |-
client.index('books').updateNonSeparatorTokens(['@', '#'])
reset_non_separator_tokens_1: |-
client.index('books').resetNonSeparatorTokens()
search_parameter_guide_facet_stats_1: |-
client.index('movie_ratings').search('Batman', { facets: ['genres', 'rating'] })
geosearch_guide_filter_settings_1: |-
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
*.md
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,67 @@ client.index('myIndex').updateTypoTolerance(typoTolerance: TypoTolerance | null)
client.index('myIndex').resetTypoTolerance(): Promise<EnqueuedTask>
```


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

#### Get separator tokens

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

#### Update separator tokens

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

#### Reset separator tokens

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

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

#### Get non separator tokens

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

#### Update non separator tokens

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

#### Reset non separator tokens

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

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

#### Get dictionary

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

#### Update dictionary

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

#### Reset dictionary

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

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

#### [Get keys](https://www.meilisearch.com/docs/reference/api/keys#get-all-keys)
Expand Down
130 changes: 130 additions & 0 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ import {
DocumentsDeletionQuery,
SearchForFacetValuesParams,
SearchForFacetValuesResponse,
SeparatorTokens,
NonSeparatorTokens,
Dictionary,
} from './types'
import { removeUndefinedFromObject } from './utils'
import { HttpRequests } from './http-requests'
Expand Down Expand Up @@ -1117,6 +1120,133 @@ class Index<T extends Record<string, any> = Record<string, any>> {

return new EnqueuedTask(task)
}

///
/// SEPARATOR TOKENS
///

/**
* Get the list of all separator tokens.
*
* @returns Promise containing array of separator tokens
*/
async getSeparatorTokens(): Promise<string[]> {
const url = `indexes/${this.uid}/settings/separator-tokens`
return await this.httpRequest.get<string[]>(url)
}

/**
* Update the list of separator tokens. Overwrite the old list.
*
* @param separatorTokens - Array that contains separator tokens.
* @returns Promise containing an EnqueuedTask or null
*/
async updateSeparatorTokens(
separatorTokens: SeparatorTokens
): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/separator-tokens`
const task = await this.httpRequest.put(url, separatorTokens)

return new EnqueuedTask(task)
}

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

task.enqueuedAt = new Date(task.enqueuedAt)

return task
}

///
/// NON-SEPARATOR TOKENS
///

/**
* Get the list of all non-separator tokens.
*
* @returns Promise containing array of non-separator tokens
*/
async getNonSeparatorTokens(): Promise<string[]> {
const url = `indexes/${this.uid}/settings/non-separator-tokens`
return await this.httpRequest.get<string[]>(url)
}

/**
* Update the list of non-separator tokens. Overwrite the old list.
*
* @param nonSeparatorTokens - Array that contains non-separator tokens.
* @returns Promise containing an EnqueuedTask or null
*/
async updateNonSeparatorTokens(
nonSeparatorTokens: NonSeparatorTokens
): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/non-separator-tokens`
const task = await this.httpRequest.put(url, nonSeparatorTokens)

return new EnqueuedTask(task)
}

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

task.enqueuedAt = new Date(task.enqueuedAt)

return task
}

///
/// DICTIONARY
///

/**
* Get the dictionary settings of a Meilisearch index.
*
* @returns Promise containing the dictionary settings
*/
async getDictionary(): Promise<string[]> {
const url = `indexes/${this.uid}/settings/dictionary`
return await this.httpRequest.get<string[]>(url)
}

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

return new EnqueuedTask(task)
}

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

task.enqueuedAt = new Date(task.enqueuedAt)

return task
}
}

export { Index }
6 changes: 6 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ export type TypoTolerance = {
twoTypos?: number | null
}
} | null
export type SeparatorTokens = string[] | null
export type NonSeparatorTokens = string[] | null
export type Dictionary = string[] | null

export type FacetOrder = 'alpha' | 'count'

Expand All @@ -336,6 +339,9 @@ export type Settings = {
typoTolerance?: TypoTolerance
faceting?: Faceting
pagination?: PaginationSettings
separatorTokens?: SeparatorTokens
nonSeparatorTokens?: NonSeparatorTokens
dictionary?: Dictionary
}

/*
Expand Down
Loading
Loading