Skip to content

Commit

Permalink
Merge #564
Browse files Browse the repository at this point in the history
564: Feat support proximityPrecision setting r=curquiza a=Ja7ad

# Pull Request

## Related issue
Fixes #507

## What does this PR do?
- This PR support `proximityPrecision` setting

## 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 <[email protected]>
  • Loading branch information
meili-bors[bot] and Ja7ad authored Aug 21, 2024
2 parents db30204 + ab899b2 commit 1dfc51b
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -924,3 +924,9 @@ update_non_separator_tokens_1: |-
})
reset_non_separator_tokens_1: |-
client.Index("articles").ResetNonSeparatorTokens()
get_proximity_precision_settings_1: |-
client.Index("books").GetProximityPrecision()
update_proximity_precision_settings_1: |-
client.Index("books").UpdateProximityPrecision(ByAttribute)
reset_proximity_precision_settings_1: |-
client.Index("books").ResetProximityPrecision()
24 changes: 24 additions & 0 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,30 @@ type IndexManager interface {
// https://www.meilisearch.com/docs/reference/api/settings#reset-dictionary
ResetDictionaryWithContext(ctx context.Context) (*TaskInfo, error)

// GetProximityPrecision returns ProximityPrecision configuration value
// https://www.meilisearch.com/docs/reference/api/settings#get-proximity-precision-settings
GetProximityPrecision() (ProximityPrecisionType, error)

// GetProximityPrecisionWithContext returns ProximityPrecision configuration value and support parent context
// https://www.meilisearch.com/docs/reference/api/settings#get-proximity-precision-settings
GetProximityPrecisionWithContext(ctx context.Context) (ProximityPrecisionType, error)

// UpdateProximityPrecision set ProximityPrecision value ByWord or ByAttribute
// https://www.meilisearch.com/docs/reference/api/settings#update-proximity-precision-settings
UpdateProximityPrecision(proximityType ProximityPrecisionType) (*TaskInfo, error)

// UpdateProximityPrecisionWithContext set ProximityPrecision value ByWord or ByAttribute and support parent context
// https://www.meilisearch.com/docs/reference/api/settings#update-proximity-precision-settings
UpdateProximityPrecisionWithContext(ctx context.Context, proximityType ProximityPrecisionType) (*TaskInfo, error)

// ResetProximityPrecision reset ProximityPrecision to default ByWord
// https://www.meilisearch.com/docs/reference/api/settings#reset-proximity-precision-settings
ResetProximityPrecision() (*TaskInfo, error)

// ResetProximityPrecisionWithContext reset ProximityPrecision to default ByWord and support parent context
// https://www.meilisearch.com/docs/reference/api/settings#reset-proximity-precision-settings
ResetProximityPrecisionWithContext(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 @@ -1041,3 +1041,64 @@ func (i *index) ResetNonSeparatorTokensWithContext(ctx context.Context) (*TaskIn
}
return resp, nil
}

func (i *index) GetProximityPrecision() (ProximityPrecisionType, error) {
return i.GetProximityPrecisionWithContext(context.Background())
}

func (i *index) GetProximityPrecisionWithContext(ctx context.Context) (ProximityPrecisionType, error) {
resp := new(ProximityPrecisionType)
req := &internalRequest{
endpoint: "/indexes/" + i.uid + "/settings/proximity-precision",
method: http.MethodGet,
withRequest: nil,
withResponse: resp,
acceptedStatusCodes: []int{http.StatusOK},
functionName: "GetProximityPrecision",
}
if err := i.client.executeRequest(ctx, req); err != nil {
return "", err
}
return *resp, nil
}

func (i *index) UpdateProximityPrecision(proximityType ProximityPrecisionType) (*TaskInfo, error) {
return i.UpdateProximityPrecisionWithContext(context.Background(), proximityType)
}

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

func (i *index) ResetProximityPrecision() (*TaskInfo, error) {
return i.ResetProximityPrecisionWithContext(context.Background())
}

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

0 comments on commit 1dfc51b

Please sign in to comment.