Skip to content

Commit

Permalink
proto-beta: Tokenizer customization
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulmet committed Aug 9, 2023
1 parent d82d350 commit 774ef7b
Show file tree
Hide file tree
Showing 9 changed files with 612 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meilisearch",
"version": "0.34.1",
"version": "0.34.2-tokenizer-customization.0",
"description": "The Meilisearch JS client for Node.js and the browser.",
"keywords": [
"meilisearch",
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 }
2 changes: 1 addition & 1 deletion src/package-version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PACKAGE_VERSION = '0.34.1'
export const PACKAGE_VERSION = '0.34.2-tokenizer-customization.0'
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

0 comments on commit 774ef7b

Please sign in to comment.