Skip to content

Commit

Permalink
feat: support proximityPrecision setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad committed Aug 21, 2024
1 parent db30204 commit ab899b2
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

Check warning on line 1060 in index_settings.go

View check run for this annotation

Codecov / codecov/patch

index_settings.go#L1060

Added line #L1060 was not covered by tests
}
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

Check warning on line 1081 in index_settings.go

View check run for this annotation

Codecov / codecov/patch

index_settings.go#L1081

Added line #L1081 was not covered by tests
}
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

Check warning on line 1101 in index_settings.go

View check run for this annotation

Codecov / codecov/patch

index_settings.go#L1101

Added line #L1101 was not covered by tests
}
return resp, nil
}
Loading

0 comments on commit ab899b2

Please sign in to comment.