Skip to content

Commit

Permalink
Merge #565
Browse files Browse the repository at this point in the history
565: Feat accept the frequency value for the matchingStrategy search r=curquiza a=Ja7ad

# Pull Request

## Related issue
Fixes #540

## What does this PR do?
- This PR accept the frequency value for the matchingStrategy search

## 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>
  • Loading branch information
meili-bors[bot] and Ja7ad authored Aug 21, 2024
2 parents 1dfc51b + 13d1554 commit 7bd9c23
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
9 changes: 7 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
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
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func setUpIndexForFaceting(client ServiceManager) {
{BookID: 254, Title: "Lolita", Tag: "Novel", Year: 1955},
{BookID: 921, Title: "The Brothers Karamazov", Tag: "Novel", Year: 1879},
{BookID: 1032, Title: "Crime and Punishment", Tag: "Crime fiction", Year: 1866},
{BookID: 1039, Title: "The Girl in the white shirt", Tag: "white shirt", Year: 1999},
}
task, err := idx.AddDocuments(booksTest)
if err != nil {
Expand Down
18 changes: 17 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ type (
SortFacetType string // SortFacetType is type of facet sorting, alpha or count
TaskStatus string // TaskStatus is the status of a task.
ProximityPrecisionType string // ProximityPrecisionType accepts one of the ByWord or ByAttribute
MatchingStrategy string // MatchingStrategy one of the Last, All, Frequency
)

const (
// Last returns documents containing all the query terms first. If there are not enough results containing all
// query terms to meet the requested limit, Meilisearch will remove one query term at a time,
// starting from the end of the query.
Last MatchingStrategy = "last"
// All only returns documents that contain all query terms. Meilisearch will not match any more documents even
// if there aren't enough to meet the requested limit.
All MatchingStrategy = "all"
// Frequency returns documents containing all the query terms first. If there are not enough results containing
//all query terms to meet the requested limit, Meilisearch will remove one query term at a time, starting
//with the word that is the most frequent in the dataset. frequency effectively gives more weight to terms
//that appear less frequently in a set of results.
Frequency MatchingStrategy = "frequency"
)

const (
Expand Down Expand Up @@ -372,7 +388,7 @@ type SearchRequest struct {
AttributesToHighlight []string `json:"attributesToHighlight,omitempty"`
HighlightPreTag string `json:"highlightPreTag,omitempty"`
HighlightPostTag string `json:"highlightPostTag,omitempty"`
MatchingStrategy string `json:"matchingStrategy,omitempty"`
MatchingStrategy MatchingStrategy `json:"matchingStrategy,omitempty"`
Filter interface{} `json:"filter,omitempty"`
ShowMatchesPosition bool `json:"showMatchesPosition,omitempty"`
ShowRankingScore bool `json:"showRankingScore,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion types_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7bd9c23

Please sign in to comment.