Skip to content

Commit

Permalink
Merge pull request #181 from meilisearch/update-filter
Browse files Browse the repository at this point in the history
Update Filter field
  • Loading branch information
alallema authored Jul 20, 2021
2 parents 3b42444 + 2d3af15 commit 3e0e3be
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ get_health_1: |-
get_version_1: |-
client.GetVersion()
distinct_attribute_guide_1: |-
client.Index("movies").UpdateDistinctAttribute("product_id")
client.Index("jackets").UpdateDistinctAttribute("product_id")
field_properties_guide_searchable_1: |-
searchableAttributes := []string{
"title",
Expand Down Expand Up @@ -409,4 +409,4 @@ post_dump_1: |-
get_dump_status_1: |-
results, err := client.GetDumpStatus("dump-uid")
phrase_search_1: |-
results, err := client.Index("movies").Search("\"neo\"", &meilisearch.SearchRequest{})
results, err := client.Index("movies").Search("\"african american\" horror", &meilisearch.SearchRequest{})
2 changes: 1 addition & 1 deletion index_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (i Index) Search(query string, request *SearchRequest) (*SearchResponse, er
if request.Matches {
searchPostRequestParams["matches"] = request.Matches
}
if request.Filter != "" {
if request.Filter != nil {
searchPostRequestParams["filter"] = request.Filter
}
if request.Offset != 0 {
Expand Down
56 changes: 56 additions & 0 deletions index_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,62 @@ func TestIndex_SearchWithFilters(t *testing.T) {
ExhaustiveNbHits: false,
},
},
{
name: "TestIndexSearchWithFilterArray",
args: args{
UID: "indexUID",
client: defaultClient,
query: "and",
filterableAttributes: []string{
"year",
},
request: SearchRequest{
Filter: []string{
"year = 2005",
},
},
},
want: &SearchResponse{
Hits: []interface{}{
map[string]interface{}{
"book_id": float64(4), "title": "Harry Potter and the Half-Blood Prince",
},
},
NbHits: 1,
Offset: 0,
Limit: 20,
ExhaustiveNbHits: false,
},
},
{
name: "TestIndexSearchWithFilterMultipleArray",
args: args{
UID: "indexUID",
client: defaultClient,
query: "and",
filterableAttributes: []string{
"year",
"tag",
},
request: SearchRequest{
Filter: [][]string{
[]string{"year < 1850"},
[]string{"tag = romance"},
},
},
},
want: &SearchResponse{
Hits: []interface{}{
map[string]interface{}{
"book_id": float64(123), "title": "Pride and Prejudice",
},
},
NbHits: 1,
Offset: 0,
Limit: 20,
ExhaustiveNbHits: false,
},
},
{
name: "TestIndexSearchWithMultipleFilter",
args: args{
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type SearchRequest struct {
AttributesToCrop []string
CropLength int64
AttributesToHighlight []string
Filter string
Filter interface{}
Matches bool
FacetsDistribution []string
PlaceholderSearch bool
Expand Down
16 changes: 14 additions & 2 deletions types_easyjson.go

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

0 comments on commit 3e0e3be

Please sign in to comment.