Skip to content

Commit

Permalink
Merge branch 'main' into chore/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad authored Aug 21, 2024
2 parents c51af72 + 7bd9c23 commit 11b1bd5
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 25 deletions.
15 changes: 13 additions & 2 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,17 @@ search_parameter_guide_show_ranking_score_details_1: |-
})
search_parameter_guide_matching_strategy_1: |-
resp, err := client.Index("movies").Search("big fat liar", &meilisearch.SearchRequest{
MatchingStrategy: "last",
MatchingStrategy: Last,
})
search_parameter_guide_matching_strategy_2: |-
resp, err := client.Index("movies").Search("big fat liar", &meilisearch.SearchRequest{
MatchingStrategy: "all",
MatchingStrategy: All,
})
search_parameter_guide_matching_strategy_3: |-
client.Index("movies").Search("white shirt", &meilisearch.SearchRequest{
MatchingStrategy: Frequency,
})
search_parameter_guide_hitsperpage_1: |-
client.Index("movies").Search("", &meilisearch.SearchRequest{
HitsPerPage: 15,
Expand Down Expand Up @@ -924,3 +929,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
26 changes: 24 additions & 2 deletions index_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestIndex_Search(t *testing.T) {
"book_id": float64(123), "title": "Pride and Prejudice",
},
},
EstimatedTotalHits: 20,
EstimatedTotalHits: 21,
Offset: 0,
Limit: 1,
},
Expand Down Expand Up @@ -553,6 +553,28 @@ func TestIndex_Search(t *testing.T) {
},
wantErr: false,
},
{
name: "TestIndexSearchWithMatchStrategyFrequency",
args: args{
UID: "indexUID",
client: sv,
query: "white shirt",
request: &SearchRequest{
MatchingStrategy: Frequency,
},
},
want: &SearchResponse{
Hits: []interface{}{
map[string]interface{}{
"book_id": float64(1039), "title": "The Girl in the white shirt",
},
},
EstimatedTotalHits: 1,
Offset: 0,
Limit: 20,
},
wantErr: false,
},
{
name: "TestIndexSearchWithInvalidIndex",
args: args{
Expand Down Expand Up @@ -1296,7 +1318,7 @@ func TestIndex_SearchWithSort(t *testing.T) {
"book_id": float64(7), "title": "Don Quixote",
},
},
EstimatedTotalHits: 20,
EstimatedTotalHits: 21,
Offset: 0,
Limit: 4,
},
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 11b1bd5

Please sign in to comment.