Skip to content

Commit

Permalink
Merge #562
Browse files Browse the repository at this point in the history
562: Add dictionary settings r=curquiza a=Ja7ad

# Pull Request

## Related issue
Fixes #489

## What does this PR do?
- This PR Support user-dictionary loading

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: Javad <ja7ad@live.com>
Co-authored-by: Clémentine <clementine@meilisearch.com>
  • Loading branch information
3 people authored Aug 20, 2024
2 parents 310e6b9 + 1014867 commit db30204
Show file tree
Hide file tree
Showing 6 changed files with 571 additions and 372 deletions.
9 changes: 9 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,15 @@ update_search_cutoff_1: |-
client.Index("movies").UpdateSearchCutoffMs(150)
reset_search_cutoff_1: |-
client.Index("books").ResetSearchCutoffMs()
get_dictionary_1: |-
client.Index("books").GetDictionary()
update_dictionary_1: |-
client.Index("books").UpdateDictionary([]string{
"J. R. R.",
"W. E. B.",
})
reset_dictionary_1: |-
client.Index("books").ResetDictionary()
get_separator_tokens_1: |-
client.Index("articles").GetSeparatorTokens()
update_separator_tokens_1: |-
Expand Down
40 changes: 40 additions & 0 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,46 @@ type IndexManager interface {
// https://www.meilisearch.com/docs/reference/api/settings#reset-non-separator-tokens
ResetNonSeparatorTokensWithContext(ctx context.Context) (*TaskInfo, error)

// GetDictionary returns user dictionary
//
//Allows users to instruct Meilisearch to consider groups of strings as a
//single term by adding a supplementary dictionary of user-defined terms.
//This is particularly useful when working with datasets containing many domain-specific
//words, and in languages where words are not separated by whitespace such as Japanese.
//Custom dictionaries are also useful in a few use-cases for space-separated languages,
//such as datasets with names such as "J. R. R. Tolkien" and "W. E. B. Du Bois".
//
// https://www.meilisearch.com/docs/reference/api/settings#get-dictionary
GetDictionary() ([]string, error)

// GetDictionaryWithContext returns user dictionary and support parent context
//
//Allows users to instruct Meilisearch to consider groups of strings as a
//single term by adding a supplementary dictionary of user-defined terms.
//This is particularly useful when working with datasets containing many domain-specific
//words, and in languages where words are not separated by whitespace such as Japanese.
//Custom dictionaries are also useful in a few use-cases for space-separated languages,
//such as datasets with names such as "J. R. R. Tolkien" and "W. E. B. Du Bois".
//
// https://www.meilisearch.com/docs/reference/api/settings#get-dictionary
GetDictionaryWithContext(ctx context.Context) ([]string, error)

// UpdateDictionary update user dictionary
// https://www.meilisearch.com/docs/reference/api/settings#update-dictionary
UpdateDictionary(words []string) (*TaskInfo, error)

// UpdateDictionaryWithContext update user dictionary and support parent context
// https://www.meilisearch.com/docs/reference/api/settings#update-dictionary
UpdateDictionaryWithContext(ctx context.Context, words []string) (*TaskInfo, error)

// ResetDictionary reset user dictionary
// https://www.meilisearch.com/docs/reference/api/settings#reset-dictionary
ResetDictionary() (*TaskInfo, error)

// ResetDictionaryWithContext reset user dictionary and support parent context
// https://www.meilisearch.com/docs/reference/api/settings#reset-dictionary
ResetDictionaryWithContext(ctx context.Context) (*TaskInfo, error)

// WaitForTask waits for a task to complete by its UID with the given interval.
WaitForTask(taskUID int64, interval time.Duration) (*Task, error)

Expand Down
61 changes: 61 additions & 0 deletions index_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,67 @@ func (i *index) ResetSearchCutoffMsWithContext(ctx context.Context) (*TaskInfo,
return resp, nil
}

func (i *index) GetDictionary() ([]string, error) {
return i.GetDictionaryWithContext(context.Background())
}

func (i *index) GetDictionaryWithContext(ctx context.Context) ([]string, error) {
resp := make([]string, 0)
req := &internalRequest{
endpoint: "/indexes/" + i.uid + "/settings/dictionary",
method: http.MethodGet,
withRequest: nil,
withResponse: &resp,
acceptedStatusCodes: []int{http.StatusOK},
functionName: "GetDictionary",
}
if err := i.client.executeRequest(ctx, req); err != nil {
return nil, err
}
return resp, nil
}

func (i *index) UpdateDictionary(words []string) (*TaskInfo, error) {
return i.UpdateDictionaryWithContext(context.Background(), words)
}

func (i *index) UpdateDictionaryWithContext(ctx context.Context, words []string) (*TaskInfo, error) {
resp := new(TaskInfo)
req := &internalRequest{
endpoint: "/indexes/" + i.uid + "/settings/dictionary",
method: http.MethodPut,
contentType: contentTypeJSON,
withRequest: &words,
withResponse: resp,
acceptedStatusCodes: []int{http.StatusAccepted},
functionName: "UpdateDictionary",
}
if err := i.client.executeRequest(ctx, req); err != nil {
return nil, err
}
return resp, nil
}

func (i *index) ResetDictionary() (*TaskInfo, error) {
return i.ResetDictionaryWithContext(context.Background())
}

func (i *index) ResetDictionaryWithContext(ctx context.Context) (*TaskInfo, error) {
resp := new(TaskInfo)
req := &internalRequest{
endpoint: "/indexes/" + i.uid + "/settings/dictionary",
method: http.MethodDelete,
withRequest: nil,
withResponse: resp,
acceptedStatusCodes: []int{http.StatusAccepted},
functionName: "ResetDictionary",
}
if err := i.client.executeRequest(ctx, req); err != nil {
return nil, err
}
return resp, nil
}

func (i *index) GetSeparatorTokens() ([]string, error) {
return i.GetSeparatorTokensWithContext(context.Background())
}
Expand Down
Loading

0 comments on commit db30204

Please sign in to comment.