Skip to content

Commit

Permalink
Merge #559
Browse files Browse the repository at this point in the history
559: Feat support text-separator customization r=curquiza a=Ja7ad

# Pull Request

## Related issue
Fixes #488

## What does this PR do?
- Support text-separator customization

## 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 15, 2024
2 parents 9af71df + b6f48e5 commit 17cedba
Show file tree
Hide file tree
Showing 6 changed files with 740 additions and 340 deletions.
18 changes: 18 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -887,3 +887,21 @@ update_search_cutoff_1: |-
client.Index("movies").UpdateSearchCutoffMs(150)
reset_search_cutoff_1: |-
client.Index("books").ResetSearchCutoffMs()
get_separator_tokens_1: |-
client.Index("articles").GetSeparatorTokens()
update_separator_tokens_1: |-
client.Index("articles").UpdateSeparatorTokens([]string{
"|",
"&hellip;",
})
reset_separator_tokens_1: |-
client.Index("articles").ResetSeparatorTokens()
get_non_separator_tokens_1: |-
client.Index("articles").GetNonSeparatorTokens()
update_non_separator_tokens_1: |-
client.Index("articles").UpdateNonSeparatorTokens([]string{
"@",
"#",
})
reset_non_separator_tokens_1: |-
client.Index("articles").ResetNonSeparatorTokens()
48 changes: 48 additions & 0 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,54 @@ type IndexManager interface {
// ResetSearchCutoffMsWithContext resets the search cutoff time in milliseconds to default value using the provided context for cancellation.
ResetSearchCutoffMsWithContext(ctx context.Context) (*TaskInfo, error)

// GetSeparatorTokens returns separators tokens
// https://www.meilisearch.com/docs/reference/api/settings#get-separator-tokens
GetSeparatorTokens() ([]string, error)

// GetSeparatorTokensWithContext returns separator tokens and support parent context
// https://www.meilisearch.com/docs/reference/api/settings#get-separator-tokens
GetSeparatorTokensWithContext(ctx context.Context) ([]string, error)

// UpdateSeparatorTokens update separator tokens
// https://www.meilisearch.com/docs/reference/api/settings#update-separator-tokens
UpdateSeparatorTokens(tokens []string) (*TaskInfo, error)

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

// ResetSeparatorTokens reset separator tokens
// https://www.meilisearch.com/docs/reference/api/settings#reset-separator-tokens
ResetSeparatorTokens() (*TaskInfo, error)

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

// GetNonSeparatorTokens returns non-separator tokens
// https://www.meilisearch.com/docs/reference/api/settings#get-non-separator-tokens
GetNonSeparatorTokens() ([]string, error)

// GetNonSeparatorTokensWithContext returns non-separator tokens and support parent context
// https://www.meilisearch.com/docs/reference/api/settings#get-non-separator-tokens
GetNonSeparatorTokensWithContext(ctx context.Context) ([]string, error)

// UpdateNonSeparatorTokens update non-separator tokens
// https://www.meilisearch.com/docs/reference/api/settings#update-non-separator-tokens
UpdateNonSeparatorTokens(tokens []string) (*TaskInfo, error)

// UpdateNonSeparatorTokensWithContext update non-separator tokens and support parent context
// https://www.meilisearch.com/docs/reference/api/settings#update-non-separator-tokens
UpdateNonSeparatorTokensWithContext(ctx context.Context, tokens []string) (*TaskInfo, error)

// ResetNonSeparatorTokens reset non-separator tokens
// https://www.meilisearch.com/docs/reference/api/settings#reset-non-separator-tokens
ResetNonSeparatorTokens() (*TaskInfo, error)

// ResetNonSeparatorTokensWithContext reset non-separator tokens and support parent context
// https://www.meilisearch.com/docs/reference/api/settings#reset-non-separator-tokens
ResetNonSeparatorTokensWithContext(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
122 changes: 122 additions & 0 deletions index_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,125 @@ func (i *index) ResetSearchCutoffMsWithContext(ctx context.Context) (*TaskInfo,
}
return resp, nil
}

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

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

func (i *index) UpdateSeparatorTokens(req []string) (*TaskInfo, error) {
return i.UpdateSeparatorTokensWithContext(context.Background(), req)
}

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

func (i *index) ResetSeparatorTokens() (*TaskInfo, error) {
return i.ResetSeparatorTokensWithContext(context.Background())
}

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

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

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

func (i *index) UpdateNonSeparatorTokens(req []string) (*TaskInfo, error) {
return i.UpdateNonSeparatorTokensWithContext(context.Background(), req)
}

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

func (i *index) ResetNonSeparatorTokens() (*TaskInfo, error) {
return i.ResetNonSeparatorTokensWithContext(context.Background())
}

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

0 comments on commit 17cedba

Please sign in to comment.