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

prototype-beta: Tokenizer customization #1563

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
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 @@ -897,6 +897,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
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bidoubiwa do we really need to release a meilisearch-js beta? Should we test it with instant-meilisearch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instant-meilisearch is not impacted by this new change!

I released it as it is part of the prototyping process, so that people can try it out. If you think it's not necessary, it is less work for us to not release it hehe

Copy link
Member

@curquiza curquiza Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the process is too complex for what we want to do
We just want to test the prototype is working with the library. Can we have a risk of not releasing it? I mean, can we have a difference of usage between using it from source, or by using the NPM package?

From my POV, releasing a NPM package is useful only if you want to use it with another library, like IS? Am I right?
For example, we will not release a beta for the PHP integration.
I also can understand sometimes it's useful for the users to test the beta version of the library however, especially for front end oriented features!

So I would say: if you agree, let's show the full process to @atoulmet (so release the beta version) even if it's not necessary, but in the future, we would rather go to simplicity and do only what is useful for us: ensuring the library can be compatible with the prototype.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, can we have a difference of usage between using it from source, or by using the NPM package?

No reasons there should be any difference.

From my POV, releasing a NPM package is useful only if you want to use it with another library, like IS? Am I right?

This would be the biggest reason. Another reason we had in the past is if we wanted users to be able to try the feature in their javascript environment without having to use a HTTP lib.

f you agree, let's show the full process to @atoulmet (so release the beta version) even if it's not necessary, but in the future, we would rather go to simplicity and do only what is useful for us: ensuring the library can be compatible with the prototype.

i completely agree!

"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
Loading