From 837d2aaca2fc08da74761787da4cf8443a0f65b6 Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Tue, 27 Apr 2021 15:27:17 +0200 Subject: [PATCH 01/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 577aaf5d..80fee598 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ JSON output: ## 🤖 Compatibility with MeiliSearch -This package only guarantees the compatibility with the [version v0.20.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.20.0). +This package only guarantees the compatibility with the [version v0.21.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.21.0). ## 💡 Learn More From 75dfe7957c419d46150c5af46c0212f4fb862283 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 10:39:54 +0200 Subject: [PATCH 02/18] Updating README and code_sample --- .code-samples.meilisearch.yaml | 68 +++++++++++++++++----------------- README.md | 19 +++++----- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 0109d6d0..b086275e 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -9,7 +9,7 @@ list_all_indexes_1: |- client.GetAllIndexes() create_an_index_1: |- client.CreateIndex(&meilisearch.IndexConfig{ - UID: "movies", + Uid: "movies", PrimaryKey: "movie_id", }) update_an_index_1: |- @@ -104,7 +104,7 @@ update_settings_1: |- "logan": []string{"wolverine"}, }, } - client.Index("movies").UpdateSettings(settings) + client.Index("movies").UpdateSettings(&settings) reset_settings_1: |- client.Index("movies").ResetSettings() get_synonyms_1: |- @@ -115,7 +115,7 @@ update_synonyms_1: |- "logan": []string{"wolverine", "xmen"}, "wow": []string{"world of warcraft"}, } - client.Index("movies").UpdateSynonyms(synonyms) + client.Index("movies").UpdateSynonyms(&synonyms) reset_synonyms_1: |- client.Index("movies").ResetSynonyms() get_stop_words_1: |- @@ -138,7 +138,7 @@ update_ranking_rules_1: |- "asc(release_date)", "desc(rank)", } - client.Index("movies").UpdateRankingRules(rankingRules) + client.Index("movies").UpdateRankingRules(&rankingRules) reset_ranking_rules_1: |- client.Index("movies").ResetRankingRules() get_distinct_attribute_1: |- @@ -155,19 +155,19 @@ update_searchable_attributes_1: |- "description", "genre", } - client.Index("movies").UpdateSearchableAttributes(searchableAttributes) + client.Index("movies").UpdateSearchableAttributes(&searchableAttributes) reset_searchable_attributes_1: |- client.Index("movies").ResetSearchableAttributes() get_attributes_for_faceting_1: |- - client.Index("movies").GetAttributesForFaceting() + client.Index("movies").GetFilterableAttributes() update_attributes_for_faceting_1: |- - attributesForFaceting := []string{ + filterableAttributes := []string{ "genres", "director", } - client.Index("movies").UpdateAttributesForFaceting(attributesForFaceting) + client.Index("movies").UpdateFilterableAttributes(&filterableAttributes) reset_attributes_for_faceting_1: |- - client.Index("movies").ResetAttributesForFaceting() + client.Index("movies").ResetFilterableAttributes() get_displayed_attributes_1: |- client.Index("movies").GetDisplayedAttributes() update_displayed_attributes_1: |- @@ -177,7 +177,7 @@ update_displayed_attributes_1: |- "genre", "release_date", } - client.Index("movies").UpdateDisplayedAttributes(displayedAttributes) + client.Index("movies").UpdateDisplayedAttributes(&displayedAttributes) reset_displayed_attributes_1: |- client.Index("movies").ResetDisplayedAttributes() get_index_stats_1: |- @@ -208,22 +208,22 @@ field_properties_guide_displayed_1: |- filtering_guide_1: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "Avengers", - Filters: "release_date > \"795484800\"", + Filter: "release_date > \"795484800\"", }) filtering_guide_2: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "Batman", - Filters: "release_date > 795484800 AND (director = \"Tim Burton\" OR director = \"Christopher Nolan\")", + Filter: "release_date > 795484800 AND (director = \"Tim Burton\" OR director = \"Christopher Nolan\")", }) filtering_guide_3: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "horror", - Filters: "director = \"Jordan Peele\"", + Filter: "director = \"Jordan Peele\"", }) filtering_guide_4: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "Planet of the Apes", - Filters: "rating >= 3 AND (NOT director = \"Tim Burton\"", + Filter: "rating >= 3 AND (NOT director = \"Tim Burton\"", }) search_parameter_guide_query_1: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ @@ -258,17 +258,17 @@ search_parameter_guide_highlight_1: |- search_parameter_guide_filter_1: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "n", - Filters: "title = Nightshift", + Filter: "title = Nightshift", }) search_parameter_guide_filter_2: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "n", - Filters: "title=\"Kung Fu Panda\"", + Filter: "title=\"Kung Fu Panda\"", }) search_parameter_guide_matches_1: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "n", - Filters: "title=\"Kung Fu Panda\"", + Filter: "title=\"Kung Fu Panda\"", AttributesToHighlight: []string{"overview"}, Matches: true, }) @@ -327,7 +327,7 @@ search_guide_1: |- search_guide_2: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "Avengers", - Filters: "release_date > \"795484800\"", + Filter: "release_date > \"795484800\"", }) getting_started_add_documents_md: |- ```bash @@ -381,14 +381,14 @@ faceted_search_update_settings_1: |- "director", "genres", }) -faceted_search_facet_filters_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "thriller", - FacetFilters: [][]string{ - []string{"genres:Horror", "genres:Mystery"}, - []string{"director:Jordan Peele"}, - }, - }) +# faceted_search_facet_filters_1: |- +# results, error := client.Index("movies").Search(meilisearch.SearchRequest{ +# Query: "thriller", +# FacetFilter: [][]string{ +# []string{"genres:Horror", "genres:Mystery"}, +# []string{"director:Jordan Peele"}, +# }, +# }) faceted_search_facets_distribution_1: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "Batman", @@ -403,14 +403,14 @@ faceted_search_walkthrough_attributes_for_faceting_1: |- "genres", "production_companies", }) -faceted_search_walkthrough_facet_filters_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "thriller", - FacetFilters: [][]string{ - []string{"genres:Horror", "genres:Mystery"}, - []string{"director:Jordan Peele"}, - }, - }) +# faceted_search_walkthrough_facet_filters_1: |- +# results, error := client.Index("movies").Search(meilisearch.SearchRequest{ +# Query: "thriller", +# FacetFilter: [][]string{ +# []string{"genres:Horror", "genres:Mystery"}, +# []string{"director:Jordan Peele"}, +# }, +# }) faceted_search_walkthrough_facets_distribution_1: |- results, error := client.Index("movies").Search(meilisearch.SearchRequest{ Query: "Batman", diff --git a/README.md b/README.md index 6d81bfff..abcdfd26 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ func main() { } ``` -With the `updateId`, you can check the status (`enqueued`, `processed` or `failed`) of your documents addition using the [update endpoint](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status). +With the `updateId`, you can check the status (`enqueued`, `processing`, `processed` or `failed`) of your documents addition using the [update endpoint](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status). #### Basic Search @@ -149,10 +149,9 @@ All the supported options are described in the [search parameters](https://docs. ```go func main() { - searchRes, err := client.Index("books").Search("prince", + searchRes, err := client.Index("books").Search("hob", &meilisearch.SearchRequest{ AttributesToHighlight: []string{"*"}, - Filters: "book_id > 10", }) if err != nil { fmt.Println(err) @@ -168,24 +167,24 @@ JSON output: { "hits": [ { - "book_id": 456, - "title": "Le Petit Prince", + "book_id": 1344, + "title": "The Hobbit", "_formatted": { - "book_id": 456, - "title": "Le Petit Prince" + "book_id": 1344, + "title": "The Hobbit" } } ], "offset": 0, - "limit": 1, + "limit": 20, "processingTimeMs": 0, - "query": "prince" + "query": "hob" } ``` ## 🤖 Compatibility with MeiliSearch -This package only guarantees the compatibility with the [version v0.20.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.20.0). +This package only guarantees the compatibility with the [version v0.21.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.21.0). ## 💡 Learn More From 47779e2b906a1c14fd7e8b16fa22bbd13a1fffeb Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 10:57:12 +0200 Subject: [PATCH 03/18] Adding processing step in waitForPendingUpdate method --- index.go | 2 +- types.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.go b/index.go index 68da8ef3..8359499d 100644 --- a/index.go +++ b/index.go @@ -212,7 +212,7 @@ func (i Index) WaitForPendingUpdate( if err != nil { return UpdateStatusUnknown, nil } - if update.Status != UpdateStatusEnqueued { + if update.Status != UpdateStatusEnqueued && update.Status != UpdateStatusProcessing { return update.Status, nil } time.Sleep(interval) diff --git a/types.go b/types.go index d6797ad8..05ba97ca 100644 --- a/types.go +++ b/types.go @@ -75,6 +75,8 @@ const ( UpdateStatusUnknown UpdateStatus = "unknown" // UpdateStatusEnqueued means the server know the update but didn't handle it yet UpdateStatusEnqueued UpdateStatus = "enqueued" + // UpdateStatusProcessing means the server is processing the update and all went well + UpdateStatusProcessing UpdateStatus = "processing" // UpdateStatusProcessed means the server has processed the update and all went well UpdateStatusProcessed UpdateStatus = "processed" // UpdateStatusFailed means the server has processed the update and an error has been reported From 88127141687c9dae4b9e1f15727e99c125e0c395 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 11:06:24 +0200 Subject: [PATCH 04/18] Rename attributes_for_faceting into filterable_attributes --- index.go | 6 +++--- index_settings.go | 18 +++++++++--------- types.go | 14 +++++++------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/index.go b/index.go index 8359499d..72d31fdd 100644 --- a/index.go +++ b/index.go @@ -62,9 +62,9 @@ type IndexInterface interface { GetSynonyms() (resp *map[string][]string, err error) UpdateSynonyms(request *map[string][]string) (resp *AsyncUpdateID, err error) ResetSynonyms() (resp *AsyncUpdateID, err error) - GetAttributesForFaceting() (resp *[]string, err error) - UpdateAttributesForFaceting(request *[]string) (resp *AsyncUpdateID, err error) - ResetAttributesForFaceting() (resp *AsyncUpdateID, err error) + GetFilterableAttributes() (resp *[]string, err error) + UpdateFilterableAttributes(request *[]string) (resp *AsyncUpdateID, err error) + ResetFilterableAttributes() (resp *AsyncUpdateID, err error) WaitForPendingUpdate(ctx context.Context, interval time.Duration, updateID *AsyncUpdateID) (UpdateStatus, error) DefaultWaitForPendingUpdate(updateID *AsyncUpdateID) (UpdateStatus, error) diff --git a/index_settings.go b/index_settings.go index ef7a8e45..d28008ec 100644 --- a/index_settings.go +++ b/index_settings.go @@ -341,15 +341,15 @@ func (i Index) ResetSynonyms() (resp *AsyncUpdateID, err error) { return resp, nil } -func (i Index) GetAttributesForFaceting() (resp *[]string, err error) { +func (i Index) GetFilterableAttributes() (resp *[]string, err error) { resp = &[]string{} req := internalRequest{ - endpoint: "/indexes/" + i.UID + "/settings/attributes-for-faceting", + endpoint: "/indexes/" + i.UID + "/settings/filterable-attributes", method: http.MethodGet, withRequest: nil, withResponse: resp, acceptedStatusCodes: []int{http.StatusOK}, - functionName: "GetAttributesForFaceting", + functionName: "GetFilterableAttributes", } if err := i.client.executeRequest(req); err != nil { return nil, err @@ -357,15 +357,15 @@ func (i Index) GetAttributesForFaceting() (resp *[]string, err error) { return resp, nil } -func (i Index) UpdateAttributesForFaceting(request *[]string) (resp *AsyncUpdateID, err error) { +func (i Index) UpdateFilterableAttributes(request *[]string) (resp *AsyncUpdateID, err error) { resp = &AsyncUpdateID{} req := internalRequest{ - endpoint: "/indexes/" + i.UID + "/settings/attributes-for-faceting", + endpoint: "/indexes/" + i.UID + "/settings/filterable-attributes", method: http.MethodPost, withRequest: &request, withResponse: resp, acceptedStatusCodes: []int{http.StatusAccepted}, - functionName: "UpdateAttributesForFaceting", + functionName: "UpdateFilterableAttributes", } if err := i.client.executeRequest(req); err != nil { return nil, err @@ -373,15 +373,15 @@ func (i Index) UpdateAttributesForFaceting(request *[]string) (resp *AsyncUpdate return resp, nil } -func (i Index) ResetAttributesForFaceting() (resp *AsyncUpdateID, err error) { +func (i Index) ResetFilterableAttributes() (resp *AsyncUpdateID, err error) { resp = &AsyncUpdateID{} req := internalRequest{ - endpoint: "/indexes/" + i.UID + "/settings/attributes-for-faceting", + endpoint: "/indexes/" + i.UID + "/settings/filterable-attributes", method: http.MethodDelete, withRequest: nil, withResponse: resp, acceptedStatusCodes: []int{http.StatusAccepted}, - functionName: "ResetAttributesForFaceting", + functionName: "ResetFilterableAttributes", } if err := i.client.executeRequest(req); err != nil { return nil, err diff --git a/types.go b/types.go index 05ba97ca..abe31fda 100644 --- a/types.go +++ b/types.go @@ -37,13 +37,13 @@ type Index struct { // Settings is the type that represents the settings in MeiliSearch type Settings struct { - RankingRules []string `json:"rankingRules,omitempty"` - DistinctAttribute *string `json:"distinctAttribute,omitempty"` - SearchableAttributes []string `json:"searchableAttributes,omitempty"` - DisplayedAttributes []string `json:"displayedAttributes,omitempty"` - StopWords []string `json:"stopWords,omitempty"` - Synonyms map[string][]string `json:"synonyms,omitempty"` - AttributesForFaceting []string `json:"attributesForFaceting,omitempty"` + RankingRules []string `json:"rankingRules,omitempty"` + DistinctAttribute *string `json:"distinctAttribute,omitempty"` + SearchableAttributes []string `json:"searchableAttributes,omitempty"` + DisplayedAttributes []string `json:"displayedAttributes,omitempty"` + StopWords []string `json:"stopWords,omitempty"` + Synonyms map[string][]string `json:"synonyms,omitempty"` + FilterableAttributes []string `json:"filterableAttributes,omitempty"` } // Version is the type that represents the versions in MeiliSearch From 7c9a100adc477cbd2c307bf623d3255765b469da Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 11:11:15 +0200 Subject: [PATCH 05/18] Rename Filters into Filter --- index_search.go | 7 ++----- types.go | 3 +-- types_easyjson.go | 47 ++++++++++++++--------------------------------- 3 files changed, 17 insertions(+), 40 deletions(-) diff --git a/index_search.go b/index_search.go index 04c3f5d9..38ac46da 100644 --- a/index_search.go +++ b/index_search.go @@ -29,11 +29,8 @@ func (i Index) Search(query string, request *SearchRequest) (*SearchResponse, er if request.Matches { searchPostRequestParams["matches"] = request.Matches } - if request.FacetFilters != nil { - searchPostRequestParams["facetFilters"] = request.FacetFilters - } - if request.Filters != "" { - searchPostRequestParams["filters"] = request.Filters + if request.Filter != "" { + searchPostRequestParams["filter"] = request.Filter } if request.Offset != 0 { searchPostRequestParams["offset"] = request.Offset diff --git a/types.go b/types.go index 05ba97ca..3408c8ea 100644 --- a/types.go +++ b/types.go @@ -137,10 +137,9 @@ type SearchRequest struct { AttributesToCrop []string CropLength int64 AttributesToHighlight []string - Filters string + Filter string Matches bool FacetsDistribution []string - FacetFilters interface{} PlaceholderSearch bool } diff --git a/types_easyjson.go b/types_easyjson.go index 37a9e44b..37e80710 100644 --- a/types_easyjson.go +++ b/types_easyjson.go @@ -696,25 +696,25 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo5(in *jlexer.Lexer, } in.Delim('}') } - case "attributesForFaceting": + case "filterableAttributes": if in.IsNull() { in.Skip() - out.AttributesForFaceting = nil + out.FilterableAttributes = nil } else { in.Delim('[') - if out.AttributesForFaceting == nil { + if out.FilterableAttributes == nil { if !in.IsDelim(']') { - out.AttributesForFaceting = make([]string, 0, 4) + out.FilterableAttributes = make([]string, 0, 4) } else { - out.AttributesForFaceting = []string{} + out.FilterableAttributes = []string{} } } else { - out.AttributesForFaceting = (out.AttributesForFaceting)[:0] + out.FilterableAttributes = (out.FilterableAttributes)[:0] } for !in.IsDelim(']') { var v13 string v13 = string(in.String()) - out.AttributesForFaceting = append(out.AttributesForFaceting, v13) + out.FilterableAttributes = append(out.FilterableAttributes, v13) in.WantComma() } in.Delim(']') @@ -850,8 +850,8 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo5(out *jwriter.Write out.RawByte('}') } } - if len(in.AttributesForFaceting) != 0 { - const prefix string = ",\"attributesForFaceting\":" + if len(in.FilterableAttributes) != 0 { + const prefix string = ",\"filterableAttributes\":" if first { first = false out.RawString(prefix[1:]) @@ -860,7 +860,7 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo5(out *jwriter.Write } { out.RawByte('[') - for v25, v26 := range in.AttributesForFaceting { + for v25, v26 := range in.FilterableAttributes { if v25 > 0 { out.RawByte(',') } @@ -1179,8 +1179,8 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo7(in *jlexer.Lexer, } in.Delim(']') } - case "Filters": - out.Filters = string(in.String()) + case "Filter": + out.Filter = string(in.String()) case "Matches": out.Matches = bool(in.Bool()) case "FacetsDistribution": @@ -1206,14 +1206,6 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo7(in *jlexer.Lexer, } in.Delim(']') } - case "FacetFilters": - if m, ok := out.FacetFilters.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.FacetFilters.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.FacetFilters = in.Interface() - } case "PlaceholderSearch": out.PlaceholderSearch = bool(in.Bool()) default: @@ -1294,9 +1286,9 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo7(out *jwriter.Write } } { - const prefix string = ",\"Filters\":" + const prefix string = ",\"Filter\":" out.RawString(prefix) - out.String(string(in.Filters)) + out.String(string(in.Filter)) } { const prefix string = ",\"Matches\":" @@ -1319,17 +1311,6 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo7(out *jwriter.Write out.RawByte(']') } } - { - const prefix string = ",\"FacetFilters\":" - out.RawString(prefix) - if m, ok := in.FacetFilters.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.FacetFilters.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.FacetFilters)) - } - } { const prefix string = ",\"PlaceholderSearch\":" out.RawString(prefix) From 5950b70bf41148505c80d7505364db694c77358a Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 12:07:41 +0200 Subject: [PATCH 06/18] Rename FieldsFrequency into FieldDistribution --- types.go | 2 +- types_easyjson.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/types.go b/types.go index 7ceee9fa..e4d3f881 100644 --- a/types.go +++ b/types.go @@ -57,7 +57,7 @@ type Version struct { type StatsIndex struct { NumberOfDocuments int64 `json:"numberOfDocuments"` IsIndexing bool `json:"isIndexing"` - FieldsFrequency map[string]int64 `json:"fieldsFrequency"` + FieldDistribution map[string]int64 `json:"fieldDistribution"` } // Stats is the type that represent all stats diff --git a/types_easyjson.go b/types_easyjson.go index 37e80710..8259a36f 100644 --- a/types_easyjson.go +++ b/types_easyjson.go @@ -335,18 +335,18 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo3(in *jlexer.Lexer, out.NumberOfDocuments = int64(in.Int64()) case "isIndexing": out.IsIndexing = bool(in.Bool()) - case "fieldsFrequency": + case "fieldDistribution": if in.IsNull() { in.Skip() } else { in.Delim('{') - out.FieldsFrequency = make(map[string]int64) + out.FieldDistribution = make(map[string]int64) for !in.IsDelim('}') { key := string(in.String()) in.WantColon() var v3 int64 v3 = int64(in.Int64()) - (out.FieldsFrequency)[key] = v3 + (out.FieldDistribution)[key] = v3 in.WantComma() } in.Delim('}') @@ -376,14 +376,14 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo3(out *jwriter.Write out.Bool(bool(in.IsIndexing)) } { - const prefix string = ",\"fieldsFrequency\":" + const prefix string = ",\"fieldDistribution\":" out.RawString(prefix) - if in.FieldsFrequency == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 { + if in.FieldDistribution == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 { out.RawString(`null`) } else { out.RawByte('{') v4First := true - for v4Name, v4Value := range in.FieldsFrequency { + for v4Name, v4Value := range in.FieldDistribution { if v4First { v4First = false } else { From dbec5f7ff4b0fa7ab78c4777aec1c01aa460c163 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 12:52:13 +0200 Subject: [PATCH 07/18] Adding startedAt and finishedAt in dump fields --- types.go | 6 ++++-- types_easyjson.go | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/types.go b/types.go index e4d3f881..1c40bba9 100644 --- a/types.go +++ b/types.go @@ -112,8 +112,10 @@ type Keys struct { // // Documentation: https://docs.meilisearch.com/reference/api/dump.html type Dump struct { - UID string `json:"uid"` - Status string `json:"status"` + UID string `json:"uid"` + Status string `json:"status"` + StartedAt time.Time `json:"startedAt"` + FinishedAt time.Time `json:"finishedAt"` } // diff --git a/types_easyjson.go b/types_easyjson.go index 8259a36f..eb94e5e3 100644 --- a/types_easyjson.go +++ b/types_easyjson.go @@ -1601,6 +1601,14 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo11(in *jlexer.Lexer, out.UID = string(in.String()) case "status": out.Status = string(in.String()) + case "startedAt": + if data := in.Raw(); in.Ok() { + in.AddError((out.StartedAt).UnmarshalJSON(data)) + } + case "finishedAt": + if data := in.Raw(); in.Ok() { + in.AddError((out.FinishedAt).UnmarshalJSON(data)) + } default: in.SkipRecursive() } From 635753d313fed5cb8ff95b5049529309fc6fc27d Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 13:16:08 +0200 Subject: [PATCH 08/18] Change buildDate into commitDate --- types.go | 6 +++--- types_easyjson.go | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/types.go b/types.go index 1c40bba9..c6943005 100644 --- a/types.go +++ b/types.go @@ -48,9 +48,9 @@ type Settings struct { // Version is the type that represents the versions in MeiliSearch type Version struct { - CommitSha string `json:"commitSha"` - BuildDate time.Time `json:"buildDate"` - PkgVersion string `json:"pkgVersion"` + CommitSha string `json:"commitSha"` + CommitDate string `json:"commitDate"` + PkgVersion string `json:"pkgVersion"` } // StatsIndex is the type that represent the stats of an index in MeiliSearch diff --git a/types_easyjson.go b/types_easyjson.go index eb94e5e3..435cd21e 100644 --- a/types_easyjson.go +++ b/types_easyjson.go @@ -38,10 +38,8 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo(in *jlexer.Lexer, o switch key { case "commitSha": out.CommitSha = string(in.String()) - case "buildDate": - if data := in.Raw(); in.Ok() { - in.AddError((out.BuildDate).UnmarshalJSON(data)) - } + case "commitDate": + out.CommitDate = string(in.String()) case "pkgVersion": out.PkgVersion = string(in.String()) default: @@ -64,9 +62,9 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo(out *jwriter.Writer out.String(string(in.CommitSha)) } { - const prefix string = ",\"buildDate\":" + const prefix string = ",\"commitDate\":" out.RawString(prefix) - out.Raw((in.BuildDate).MarshalJSON()) + out.String(string(in.CommitDate)) } { const prefix string = ",\"pkgVersion\":" @@ -1633,6 +1631,16 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo11(out *jwriter.Writ out.RawString(prefix) out.String(string(in.Status)) } + { + const prefix string = ",\"startedAt\":" + out.RawString(prefix) + out.Raw((in.StartedAt).MarshalJSON()) + } + { + const prefix string = ",\"finishedAt\":" + out.RawString(prefix) + out.Raw((in.FinishedAt).MarshalJSON()) + } out.RawByte('}') } From 8bdddfcca2a5060dc1490e4b0bc502379e3161f4 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 13:58:07 +0200 Subject: [PATCH 09/18] Adding and Fixing tests --- client_index_test.go | 24 +-- client_test.go | 1 + index_documents_test.go | 64 ++----- index_search_test.go | 279 ++++++++++++++++----------- index_settings_test.go | 410 ++++++++++++++++++---------------------- index_test.go | 18 +- main_test.go | 41 ++-- 7 files changed, 403 insertions(+), 434 deletions(-) diff --git a/client_index_test.go b/client_index_test.go index b91fc658..3720d139 100644 --- a/client_index_test.go +++ b/client_index_test.go @@ -116,9 +116,9 @@ func TestClient_CreateIndex(t *testing.T) { Method: "POST", Function: "CreateIndex", RequestToString: "{\"uid\":\"indexUID\"}", - ResponseToString: "{\"message\":\"Index indexUID already exists\",\"errorCode\":\"index_already_exists\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_already_exists\"}", + ResponseToString: "{\"message\":\"Index already exists.\",\"errorCode\":\"index_already_exists\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_already_exists\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index indexUID already exists", + Message: "Index already exists.", ErrorCode: "index_already_exists", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_already_exists", @@ -233,9 +233,9 @@ func TestClient_DeleteIndex(t *testing.T) { Method: "DELETE", Function: "DeleteIndex", RequestToString: "empty request", - ResponseToString: "{\"message\":\"Index 1 not found\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", + ResponseToString: "{\"message\":\"Index \\\"1\\\" not found.\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index 1 not found", + Message: "Index \"1\" not found.", ErrorCode: "index_not_found", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_not_found", @@ -260,9 +260,9 @@ func TestClient_DeleteIndex(t *testing.T) { Method: "DELETE", Function: "DeleteIndex", RequestToString: "empty request", - ResponseToString: "{\"message\":\"Index 2 not found\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", + ResponseToString: "{\"message\":\"Index \\\"2\\\" not found.\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index 2 not found", + Message: "Index \"2\" not found.", ErrorCode: "index_not_found", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_not_found"}, @@ -277,9 +277,9 @@ func TestClient_DeleteIndex(t *testing.T) { Method: "DELETE", Function: "DeleteIndex", RequestToString: "empty request", - ResponseToString: "{\"message\":\"Index 3 not found\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", + ResponseToString: "{\"message\":\"Index \\\"3\\\" not found.\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index 3 not found", + Message: "Index \"3\" not found.", ErrorCode: "index_not_found", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_not_found"}, @@ -291,9 +291,9 @@ func TestClient_DeleteIndex(t *testing.T) { Method: "DELETE", Function: "DeleteIndex", RequestToString: "empty request", - ResponseToString: "{\"message\":\"Index 4 not found\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", + ResponseToString: "{\"message\":\"Index \\\"4\\\" not found.\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index 4 not found", + Message: "Index \"4\" not found.", ErrorCode: "index_not_found", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_not_found"}, @@ -308,9 +308,9 @@ func TestClient_DeleteIndex(t *testing.T) { Method: "DELETE", Function: "DeleteIndex", RequestToString: "empty request", - ResponseToString: "{\"message\":\"Index 5 not found\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", + ResponseToString: "{\"message\":\"Index \\\"5\\\" not found.\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index 5 not found", + Message: "Index \"5\" not found.", ErrorCode: "index_not_found", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_not_found"}, diff --git a/client_test.go b/client_test.go index f11db762..c69f88f5 100644 --- a/client_test.go +++ b/client_test.go @@ -28,6 +28,7 @@ func TestClient_Version(t *testing.T) { gotResp, err := tt.client.GetVersion() require.NoError(t, err) require.NotNil(t, gotResp, "Version() should not return nil value") + require.Equal(t, "0.21.0", gotResp.PkgVersion) }) } } diff --git a/index_documents_test.go b/index_documents_test.go index a9a65c69..d3ad82cd 100644 --- a/index_documents_test.go +++ b/index_documents_test.go @@ -17,7 +17,6 @@ func TestIndex_AddDocuments(t *testing.T) { name string args args wantResp *AsyncUpdateID - wantErr bool expectedError Error }{ { @@ -52,9 +51,9 @@ func TestIndex_AddDocuments(t *testing.T) { UID: "2", client: defaultClient, documentsPtr: []map[string]interface{}{ + {"ID": "1", "Name": "Alice In Wonderland"}, {"ID": "123", "Name": "Pride and Prejudice"}, {"ID": "456", "Name": "Le Petit Prince"}, - {"ID": "1", "Name": "Alice In Wonderland"}, }, }, wantResp: &AsyncUpdateID{ @@ -93,49 +92,15 @@ func TestIndex_AddDocuments(t *testing.T) { UID: "5", client: defaultClient, documentsPtr: []map[string]interface{}{ + {"BookID": float64(1), "Title": "Alice In Wonderland"}, {"BookID": float64(123), "Title": "Pride and Prejudice"}, {"BookID": float64(456), "Title": "Le Petit Prince", "Tag": "Conte"}, - {"BookID": float64(1), "Title": "Alice In Wonderland"}, }, }, wantResp: &AsyncUpdateID{ UpdateID: 0, }, }, - { - name: "TestIndexAddDocumentsMissingPrimaryKey", - args: args{ - UID: "6", - client: defaultClient, - documentsPtr: []map[string]interface{}{ - {"Key": float64(123), "Title": "Pride and Prejudice"}, - {"Key": float64(456), "Title": "Le Petit Prince", "Tag": "Conte"}, - {"Key": float64(1), "Title": "Alice In Wonderland"}, - }, - }, - wantResp: &AsyncUpdateID{ - UpdateID: 0, - }, - wantErr: true, - expectedError: Error(Error{ - Endpoint: "/indexes/6/documents", - Method: "POST", - Function: "AddDocuments", - RequestToString: "[{\"Key\":123,\"Title\":\"Pride and Prejudice\"},{\"Key\":456,\"Tag\":\"Conte\",\"Title\":\"Le Petit Prince\"},{\"Key\":1,\"Title\":\"Alice In Wonderland\"}]", - ResponseToString: "{\"message\":\"schema cannot be built without a primary key\",\"errorCode\":\"missing_primary_key\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#missing_primary_key\"}", - MeilisearchApiMessage: meilisearchApiMessage{ - Message: "schema cannot be built without a primary key", - ErrorCode: "missing_primary_key", - ErrorType: "invalid_request_error", - ErrorLink: "https://docs.meilisearch.com/errors#missing_primary_key", - }, - StatusCode: 400, - StatusCodeExpected: []int{202}, - rawMessage: "unaccepted status code found: ${statusCode} expected: ${statusCodeExpected}, MeilisearchApiError Message: ${message}, ErrorCode: ${errorCode}, ErrorType: ${errorType}, ErrorLink: ${errorLink} (path \"${method} ${endpoint}\" with method \"${function}\")", - OriginError: error(nil), - ErrCode: 4, - }), - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -143,20 +108,15 @@ func TestIndex_AddDocuments(t *testing.T) { i := c.Index(tt.args.UID) gotResp, err := i.AddDocuments(tt.args.documentsPtr) - if tt.wantErr { - require.Error(t, err) - require.Equal(t, &tt.expectedError, err) - } else { - require.GreaterOrEqual(t, gotResp.UpdateID, tt.wantResp.UpdateID) - require.NoError(t, err) - i.DefaultWaitForPendingUpdate(gotResp) + require.GreaterOrEqual(t, gotResp.UpdateID, tt.wantResp.UpdateID) + require.NoError(t, err) + i.DefaultWaitForPendingUpdate(gotResp) + var documents []map[string]interface{} + i.GetDocuments(&DocumentsRequest{ + Limit: 3, + }, &documents) + require.Equal(t, tt.args.documentsPtr, documents) - var documents []map[string]interface{} - i.GetDocuments(&DocumentsRequest{ - Limit: 3, - }, &documents) - require.Equal(t, tt.args.documentsPtr, documents) - } deleteAllIndexes(c) }) } @@ -208,9 +168,9 @@ func TestIndex_AddDocumentsWithPrimaryKey(t *testing.T) { UID: "3", client: defaultClient, documentsPtr: []map[string]interface{}{ + {"key": "1", "Name": "Alice In Wonderland"}, {"key": "123", "Name": "Pride and Prejudice"}, {"key": "456", "Name": "Le Petit Prince"}, - {"key": "1", "Name": "Alice In Wonderland"}, }, primaryKey: "key", }, @@ -238,9 +198,9 @@ func TestIndex_AddDocumentsWithPrimaryKey(t *testing.T) { UID: "5", client: defaultClient, documentsPtr: []map[string]interface{}{ + {"key": float64(1), "Name": "Alice In Wonderland"}, {"key": float64(123), "Name": "Pride and Prejudice"}, {"key": float64(456), "Name": "Le Petit Prince"}, - {"key": float64(1), "Name": "Alice In Wonderland"}, }, primaryKey: "key", }, diff --git a/index_search_test.go b/index_search_test.go index 7cdf1605..2139b185 100644 --- a/index_search_test.go +++ b/index_search_test.go @@ -100,7 +100,7 @@ func TestIndex_Search(t *testing.T) { want: &SearchResponse{ Hits: []interface{}{ map[string]interface{}{ - "book_id": float64(123), "title": "Pride and Prejudice", + "book_id": float64(1), "title": "Alice In Wonderland", }, }, NbHits: 20, @@ -179,28 +179,6 @@ func TestIndex_Search(t *testing.T) { ExhaustiveNbHits: false, }, }, - { - name: "TestIndexSearchWithFilters", - args: args{ - UID: "indexUID", - client: defaultClient, - query: "and", - request: SearchRequest{ - Filters: "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: "TestIndexSearchWithMatches", args: args{ @@ -214,13 +192,13 @@ func TestIndex_Search(t *testing.T) { want: &SearchResponse{ Hits: []interface{}{ map[string]interface{}{ - "book_id": float64(123), "title": "Pride and Prejudice", + "book_id": float64(1032), "title": "Crime and Punishment", }, map[string]interface{}{ - "book_id": float64(730), "title": "War and Peace", + "book_id": float64(123), "title": "Pride and Prejudice", }, map[string]interface{}{ - "book_id": float64(1032), "title": "Crime and Punishment", + "book_id": float64(730), "title": "War and Peace", }, map[string]interface{}{ "book_id": float64(4), "title": "Harry Potter and the Half-Blood Prince", @@ -233,20 +211,17 @@ func TestIndex_Search(t *testing.T) { }, }, { - name: "TestIndexSearchWithAttributeToHighlight", + name: "TestIndexSearchWithQuoteInQUery", args: args{ - UID: "indexUID", - client: defaultClient, - query: "prince", - request: SearchRequest{ - AttributesToHighlight: []string{"*"}, - Filters: "book_id > 10", - }, + UID: "indexUID", + client: defaultClient, + query: "and \"harry\"", + request: SearchRequest{}, }, want: &SearchResponse{ Hits: []interface{}{ map[string]interface{}{ - "book_id": float64(456), "title": "Le Petit Prince", + "book_id": float64(4), "title": "Harry Potter and the Half-Blood Prince", }, }, NbHits: 1, @@ -281,14 +256,14 @@ func TestIndex_Search(t *testing.T) { } } -func TestIndex_SearchFacets(t *testing.T) { +func TestIndex_SearchWithFilters(t *testing.T) { type args struct { - UID string - PrimaryKey string - client *Client - query string - request SearchRequest - facet []string + UID string + PrimaryKey string + client *Client + query string + filterableAttributes []string + request SearchRequest } tests := []struct { name string @@ -296,57 +271,68 @@ func TestIndex_SearchFacets(t *testing.T) { want *SearchResponse }{ { - name: "TestIndexSearchWithFacetsDistribution", + name: "TestIndexBasicSearchWithFilter", args: args{ UID: "indexUID", client: defaultClient, - query: "prince", + query: "and", + filterableAttributes: []string{ + "tag", + }, request: SearchRequest{ - FacetsDistribution: []string{"*"}, + Filter: "tag = romance", }, - facet: []string{"tag"}, }, want: &SearchResponse{ Hits: []interface{}{ map[string]interface{}{ - "book_id": float64(456), "title": "Le Petit Prince", + "book_id": float64(123), "title": "Pride and Prejudice", }, + }, + NbHits: 1, + Offset: 0, + Limit: 20, + ExhaustiveNbHits: false, + }, + }, + { + name: "TestIndexSearchWithFilterInInt", + args: args{ + UID: "indexUID", + client: defaultClient, + query: "and", + filterableAttributes: []string{ + "year", + }, + request: SearchRequest{ + Filter: "year = 2005", + }, + }, + want: &SearchResponse{ + Hits: []interface{}{ map[string]interface{}{ "book_id": float64(4), "title": "Harry Potter and the Half-Blood Prince", }, }, - NbHits: 2, + NbHits: 1, Offset: 0, Limit: 20, ExhaustiveNbHits: false, - FacetsDistribution: map[string]interface{}( - map[string]interface{}{ - "tag": map[string]interface{}{ - "Crime fiction": float64(0), - "Epic": float64(0), - "Epic fantasy": float64(1), - "Historical fiction": float64(0), - "Modernist literature": float64(0), - "Novel": float64(0), - "Tale": float64(1), - "Romance": float64(0), - "Satiric": float64(0), - "Tragedy": float64(0), - }, - }), - ExhaustiveFacetsCount: interface{}(true), }, }, { - name: "TestIndexSearchWithFacetsDistributionWithCustomClient", + name: "TestIndexSearchWithMultipleFilter", args: args{ UID: "indexUID", - client: customClient, + client: defaultClient, query: "prince", + filterableAttributes: []string{ + "tag", + "year", + }, request: SearchRequest{ - FacetsDistribution: []string{"*"}, + Filter: "year > 1930", }, - facet: []string{"tag"}, }, want: &SearchResponse{ Hits: []interface{}{ @@ -361,72 +347,147 @@ func TestIndex_SearchFacets(t *testing.T) { Offset: 0, Limit: 20, ExhaustiveNbHits: false, - FacetsDistribution: map[string]interface{}( + }, + }, + { + name: "TestIndexSearchWithOneFilterAnd", + args: args{ + UID: "indexUID", + client: defaultClient, + query: "", + filterableAttributes: []string{ + "year", + }, + request: SearchRequest{ + Filter: "year < 1930 AND year > 1910", + }, + }, + want: &SearchResponse{ + Hits: []interface{}{ + map[string]interface{}{ + "book_id": float64(17), "title": "In Search of Lost Time", + }, + map[string]interface{}{ + "book_id": float64(204), "title": "Ulysses", + }, map[string]interface{}{ - "tag": map[string]interface{}{ - "Crime fiction": float64(0), - "Epic": float64(0), - "Epic fantasy": float64(1), - "Historical fiction": float64(0), - "Modernist literature": float64(0), - "Novel": float64(0), - "Tale": float64(1), - "Romance": float64(0), - "Satiric": float64(0), - "Tragedy": float64(0), - }, - }), - ExhaustiveFacetsCount: interface{}(true), + "book_id": float64(742), "title": "The Great Gatsby", + }, + }, + NbHits: 3, + Offset: 0, + Limit: 20, + ExhaustiveNbHits: false, }, }, { - name: "TestIndexSearchWithFacetsDistributionWithTag", + name: "TestIndexSearchWithMultipleFilterAnd", args: args{ UID: "indexUID", client: defaultClient, - query: "prince", + query: "", + filterableAttributes: []string{ + "tag", + "year", + }, request: SearchRequest{ - FacetFilters: []string{"tag:Epic fantasy"}, + Filter: "year < 1930 AND tag = Tale", }, - facet: []string{"tag", "title"}, }, want: &SearchResponse{ Hits: []interface{}{ + map[string]interface{}{ + "book_id": float64(1), "title": "Alice In Wonderland", + }, + }, + NbHits: 1, + Offset: 0, + Limit: 20, + ExhaustiveNbHits: false, + }, + }, + { + name: "TestIndexSearchWithFilterOr", + args: args{ + UID: "indexUID", + client: defaultClient, + query: "", + filterableAttributes: []string{ + "year", + "tag", + }, + request: SearchRequest{ + Filter: "year > 2000 OR tag = Tale", + }, + }, + want: &SearchResponse{ + Hits: []interface{}{ + map[string]interface{}{ + "book_id": float64(1), "title": "Alice In Wonderland", + }, map[string]interface{}{ "book_id": float64(4), "title": "Harry Potter and the Half-Blood Prince", }, + map[string]interface{}{ + "book_id": float64(456), "title": "Le Petit Prince", + }, }, - NbHits: 1, - Offset: 0, - Limit: 20, - ExhaustiveNbHits: false, - FacetsDistribution: nil, - ExhaustiveFacetsCount: interface{}(nil), + NbHits: 3, + Offset: 0, + Limit: 20, + ExhaustiveNbHits: false, }, }, + // { + // name: "TestIndexSearchWithArrayFilter", + // args: args{ + // UID: "indexUID", + // client: defaultClient, + // query: "", + // filterableAttributes: []string{ + // "tag", + // "year", + // }, + // request: SearchRequest{ + // Filter: "tag = fantasy, year = 2005", + // }, + // }, + // want: &SearchResponse{ + // Hits: []interface{}{ + // map[string]interface{}{ + // "book_id": float64(1), "title": "Alice In Wonderland", + // }, + // }, + // NbHits: 1, + // Offset: 0, + // Limit: 20, + // ExhaustiveNbHits: false, + // }, + // }, { - name: "TestIndexSearchWithFacetsDistributionWithTagAndOneFacet", + name: "TestIndexSearchWithAttributeToHighlight", args: args{ UID: "indexUID", client: defaultClient, query: "prince", + filterableAttributes: []string{ + "book_id", + }, request: SearchRequest{ - FacetFilters: []string{"tag:Epic fantasy"}, + AttributesToHighlight: []string{"*"}, + Filter: "book_id > 10", }, - facet: []string{"tag"}, }, want: &SearchResponse{ Hits: []interface{}{ map[string]interface{}{ - "book_id": float64(4), "title": "Harry Potter and the Half-Blood Prince", + "book_id": float64(456), "title": "Le Petit Prince", }, }, - NbHits: 1, - Offset: 0, - Limit: 20, - ExhaustiveNbHits: false, - FacetsDistribution: nil, - ExhaustiveFacetsCount: interface{}(nil), + NbHits: 1, + Offset: 0, + Limit: 20, + ExhaustiveNbHits: false, }, }, } @@ -436,12 +497,14 @@ func TestIndex_SearchFacets(t *testing.T) { c := tt.args.client i := c.Index(tt.args.UID) - update, _ := i.UpdateAttributesForFaceting(&tt.args.facet) - i.DefaultWaitForPendingUpdate(update) + updateFilter, err := i.UpdateFilterableAttributes(&tt.args.filterableAttributes) + require.NoError(t, err) + i.DefaultWaitForPendingUpdate(updateFilter) got, err := i.Search(tt.args.query, &tt.args.request) require.NoError(t, err) require.Equal(t, len(tt.want.Hits), len(got.Hits)) + for len := range got.Hits { require.Equal(t, tt.want.Hits[len].(map[string]interface{})["title"], got.Hits[len].(map[string]interface{})["title"]) require.Equal(t, tt.want.Hits[len].(map[string]interface{})["book_id"], got.Hits[len].(map[string]interface{})["book_id"]) @@ -450,13 +513,7 @@ func TestIndex_SearchFacets(t *testing.T) { require.Equal(t, tt.want.Offset, got.Offset) require.Equal(t, tt.want.Limit, got.Limit) require.Equal(t, tt.want.ExhaustiveNbHits, got.ExhaustiveNbHits) - require.Equal(t, tt.want.FacetsDistribution, got.FacetsDistribution) - if got.FacetsDistribution != nil { - require.Equal(t, tt.want.FacetsDistribution.(map[string]interface{})["tag"].(map[string]interface{})["Epic fantasy"], got.FacetsDistribution.(map[string]interface{})["tag"].(map[string]interface{})["Epic fantasy"]) - require.Equal(t, tt.want.FacetsDistribution.(map[string]interface{})["tag"].(map[string]interface{})["Tragedy"], got.FacetsDistribution.(map[string]interface{})["tag"].(map[string]interface{})["Tragedy"]) - require.Equal(t, tt.want.FacetsDistribution.(map[string]interface{})["tag"].(map[string]interface{})["Romance"], got.FacetsDistribution.(map[string]interface{})["tag"].(map[string]interface{})["Romance"]) - } require.Equal(t, tt.want.ExhaustiveFacetsCount, got.ExhaustiveFacetsCount) deleteAllIndexes(c) diff --git a/index_settings_test.go b/index_settings_test.go index c896add5..cec0f78f 100644 --- a/index_settings_test.go +++ b/index_settings_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestIndex_GetAttributesForFaceting(t *testing.T) { +func TestIndex_GetFilterableAttributes(t *testing.T) { type args struct { UID string client *Client @@ -16,14 +16,14 @@ func TestIndex_GetAttributesForFaceting(t *testing.T) { args args }{ { - name: "TestIndexBasicGetAttributesForFaceting", + name: "TestIndexBasicGetFilterableAttributes", args: args{ UID: "indexUID", client: defaultClient, }, }, { - name: "TestIndexGetAttributesForFacetingWithCustomClient", + name: "TestIndexGetFilterableAttributesWithCustomClient", args: args{ UID: "indexUID", client: customClient, @@ -36,7 +36,7 @@ func TestIndex_GetAttributesForFaceting(t *testing.T) { c := tt.args.client i := c.Index(tt.args.UID) - gotResp, err := i.GetAttributesForFaceting() + gotResp, err := i.GetFilterableAttributes() require.NoError(t, err) require.Empty(t, gotResp) }) @@ -138,7 +138,7 @@ func TestIndex_GetRankingRules(t *testing.T) { UID: "indexUID", client: defaultClient, }, - wantResp: &[]string{"typo", "words", "proximity", "attribute", "wordsPosition", "exactness"}, + wantResp: &[]string{"words", "typo", "proximity", "attribute", "exactness"}, }, { name: "TestIndexGetRankingRulesWithCustomClient", @@ -146,7 +146,7 @@ func TestIndex_GetRankingRules(t *testing.T) { UID: "indexUID", client: defaultClient, }, - wantResp: &[]string{"typo", "words", "proximity", "attribute", "wordsPosition", "exactness"}, + wantResp: &[]string{"words", "typo", "proximity", "attribute", "exactness"}, }, } for _, tt := range tests { @@ -222,14 +222,14 @@ func TestIndex_GetSettings(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, { @@ -240,14 +240,14 @@ func TestIndex_GetSettings(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, } @@ -341,7 +341,7 @@ func TestIndex_GetSynonyms(t *testing.T) { } } -func TestIndex_ResetAttributesForFaceting(t *testing.T) { +func TestIndex_ResetFilterableAttributes(t *testing.T) { type args struct { UID string client *Client @@ -352,7 +352,7 @@ func TestIndex_ResetAttributesForFaceting(t *testing.T) { wantUpdate *AsyncUpdateID }{ { - name: "TestIndexBasicResetAttributesForFaceting", + name: "TestIndexBasicResetFilterableAttributes", args: args{ UID: "indexUID", client: defaultClient, @@ -362,7 +362,7 @@ func TestIndex_ResetAttributesForFaceting(t *testing.T) { }, }, { - name: "TestIndexResetAttributesForFacetingCustomClient", + name: "TestIndexResetFilterableAttributesCustomClient", args: args{ UID: "indexUID", client: customClient, @@ -378,12 +378,12 @@ func TestIndex_ResetAttributesForFaceting(t *testing.T) { c := tt.args.client i := c.Index(tt.args.UID) - gotUpdate, err := i.ResetAttributesForFaceting() + gotUpdate, err := i.ResetFilterableAttributes() require.NoError(t, err) require.Equal(t, tt.wantUpdate, gotUpdate) i.DefaultWaitForPendingUpdate(gotUpdate) - gotResp, err := i.GetAttributesForFaceting() + gotResp, err := i.GetFilterableAttributes() require.NoError(t, err) require.Empty(t, gotResp) @@ -434,7 +434,7 @@ func TestIndex_ResetDisplayedAttributes(t *testing.T) { gotUpdate, err := i.ResetDisplayedAttributes() require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err := i.GetDisplayedAttributes() @@ -485,7 +485,7 @@ func TestIndex_ResetDistinctAttribute(t *testing.T) { gotUpdate, err := i.ResetDistinctAttribute() require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err := i.GetDistinctAttribute() @@ -516,7 +516,7 @@ func TestIndex_ResetRankingRules(t *testing.T) { wantUpdate: &AsyncUpdateID{ UpdateID: 1, }, - wantResp: &[]string{"typo", "words", "proximity", "attribute", "wordsPosition", "exactness"}, + wantResp: &[]string{"words", "typo", "proximity", "attribute", "exactness"}, }, { name: "TestIndexResetRankingRulesWithCustomClient", @@ -527,7 +527,7 @@ func TestIndex_ResetRankingRules(t *testing.T) { wantUpdate: &AsyncUpdateID{ UpdateID: 1, }, - wantResp: &[]string{"typo", "words", "proximity", "attribute", "wordsPosition", "exactness"}, + wantResp: &[]string{"words", "typo", "proximity", "attribute", "exactness"}, }, } for _, tt := range tests { @@ -538,7 +538,7 @@ func TestIndex_ResetRankingRules(t *testing.T) { gotUpdate, err := i.ResetRankingRules() require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err := i.GetRankingRules() @@ -591,7 +591,7 @@ func TestIndex_ResetSearchableAttributes(t *testing.T) { gotUpdate, err := i.ResetSearchableAttributes() require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err := i.GetSearchableAttributes() @@ -624,14 +624,14 @@ func TestIndex_ResetSettings(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, { @@ -645,14 +645,14 @@ func TestIndex_ResetSettings(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, } @@ -664,7 +664,7 @@ func TestIndex_ResetSettings(t *testing.T) { gotUpdate, err := i.ResetSettings() require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err := i.GetSettings() @@ -714,7 +714,7 @@ func TestIndex_ResetStopWords(t *testing.T) { gotUpdate, err := i.ResetStopWords() require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err := i.GetStopWords() @@ -764,7 +764,7 @@ func TestIndex_ResetSynonyms(t *testing.T) { gotUpdate, err := i.ResetSynonyms() require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err := i.GetSynonyms() @@ -775,7 +775,7 @@ func TestIndex_ResetSynonyms(t *testing.T) { } } -func TestIndex_UpdateAttributesForFaceting(t *testing.T) { +func TestIndex_UpdateFilterableAttributes(t *testing.T) { type args struct { UID string client *Client @@ -787,12 +787,12 @@ func TestIndex_UpdateAttributesForFaceting(t *testing.T) { wantUpdate *AsyncUpdateID }{ { - name: "TestIndexBasicUpdateAttributesForFaceting", + name: "TestIndexBasicUpdateFilterableAttributes", args: args{ UID: "indexUID", client: defaultClient, request: []string{ - "title", "tag", + "title", }, }, wantUpdate: &AsyncUpdateID{ @@ -800,12 +800,12 @@ func TestIndex_UpdateAttributesForFaceting(t *testing.T) { }, }, { - name: "TestIndexUpdateAttributesForFacetingWithCustomClient", + name: "TestIndexUpdateFilterableAttributesWithCustomClient", args: args{ UID: "indexUID", client: customClient, request: []string{ - "title", "tag", + "title", }, }, wantUpdate: &AsyncUpdateID{ @@ -819,16 +819,16 @@ func TestIndex_UpdateAttributesForFaceting(t *testing.T) { c := tt.args.client i := c.Index(tt.args.UID) - gotResp, err := i.GetAttributesForFaceting() + gotResp, err := i.GetFilterableAttributes() require.NoError(t, err) require.Empty(t, gotResp) - gotUpdate, err := i.UpdateAttributesForFaceting(&tt.args.request) + gotUpdate, err := i.UpdateFilterableAttributes(&tt.args.request) require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.Equal(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) - gotResp, err = i.GetAttributesForFaceting() + gotResp, err = i.GetFilterableAttributes() require.NoError(t, err) require.Equal(t, &tt.args.request, gotResp) deleteAllIndexes(c) @@ -889,7 +889,7 @@ func TestIndex_UpdateDisplayedAttributes(t *testing.T) { gotUpdate, err := i.UpdateDisplayedAttributes(&tt.args.request) require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err = i.GetDisplayedAttributes() @@ -916,7 +916,7 @@ func TestIndex_UpdateDistinctAttribute(t *testing.T) { args: args{ UID: "indexUID", client: defaultClient, - request: "", + request: "movie_id", }, wantUpdate: &AsyncUpdateID{ UpdateID: 1, @@ -927,7 +927,7 @@ func TestIndex_UpdateDistinctAttribute(t *testing.T) { args: args{ UID: "indexUID", client: customClient, - request: "", + request: "movie_id", }, wantUpdate: &AsyncUpdateID{ UpdateID: 1, @@ -946,7 +946,7 @@ func TestIndex_UpdateDistinctAttribute(t *testing.T) { gotUpdate, err := i.UpdateDistinctAttribute(tt.args.request) require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err = i.GetDistinctAttribute() @@ -981,7 +981,7 @@ func TestIndex_UpdateRankingRules(t *testing.T) { wantUpdate: &AsyncUpdateID{ UpdateID: 1, }, - wantResp: &[]string{"typo", "words", "proximity", "attribute", "wordsPosition", "exactness"}, + wantResp: &[]string{"words", "typo", "proximity", "attribute", "exactness"}, }, { name: "TestIndexUpdateRankingRulesWithCustomClient", @@ -995,7 +995,7 @@ func TestIndex_UpdateRankingRules(t *testing.T) { wantUpdate: &AsyncUpdateID{ UpdateID: 1, }, - wantResp: &[]string{"typo", "words", "proximity", "attribute", "wordsPosition", "exactness"}, + wantResp: &[]string{"words", "typo", "proximity", "attribute", "exactness"}, }, } for _, tt := range tests { @@ -1010,7 +1010,7 @@ func TestIndex_UpdateRankingRules(t *testing.T) { gotUpdate, err := i.UpdateRankingRules(&tt.args.request) require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err = i.GetRankingRules() @@ -1074,7 +1074,7 @@ func TestIndex_UpdateSearchableAttributes(t *testing.T) { gotUpdate, err := i.UpdateSearchableAttributes(&tt.args.request) require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err = i.GetSearchableAttributes() @@ -1119,7 +1119,7 @@ func TestIndex_UpdateSettings(t *testing.T) { Synonyms: map[string][]string{ "hp": {"harry potter"}, }, - AttributesForFaceting: []string{ + FilterableAttributes: []string{ "title", }, }, @@ -1129,14 +1129,14 @@ func TestIndex_UpdateSettings(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, { @@ -1161,7 +1161,7 @@ func TestIndex_UpdateSettings(t *testing.T) { Synonyms: map[string][]string{ "hp": {"harry potter"}, }, - AttributesForFaceting: []string{ + FilterableAttributes: []string{ "title", }, }, @@ -1171,14 +1171,14 @@ func TestIndex_UpdateSettings(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, } @@ -1194,7 +1194,7 @@ func TestIndex_UpdateSettings(t *testing.T) { gotUpdate, err := i.UpdateSettings(&tt.args.request) require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err = i.GetSettings() @@ -1221,7 +1221,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { wantResp *Settings }{ { - name: "TestIndexUpdateSynonyms", + name: "TestIndexUpdateJustSynonyms", args: args{ UID: "indexUID", client: defaultClient, @@ -1244,7 +1244,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { Synonyms: map[string][]string{ "hp": {"harry potter"}, }, - AttributesForFaceting: []string{}, + FilterableAttributes: []string{}, }, secondRequest: Settings{ Synonyms: map[string][]string{ @@ -1262,7 +1262,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { Synonyms: map[string][]string{ "al": {"alice"}, }, - AttributesForFaceting: []string{}, + FilterableAttributes: []string{}, }, }, wantUpdate: &AsyncUpdateID{ @@ -1270,18 +1270,18 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, { - name: "TestIndexUpdateSynonymsWithCustomClient", + name: "TestIndexUpdateJustSynonymsWithCustomClient", args: args{ UID: "indexUID", client: customClient, @@ -1304,7 +1304,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { Synonyms: map[string][]string{ "hp": {"harry potter"}, }, - AttributesForFaceting: []string{}, + FilterableAttributes: []string{}, }, secondRequest: Settings{ Synonyms: map[string][]string{ @@ -1322,7 +1322,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { Synonyms: map[string][]string{ "al": {"alice"}, }, - AttributesForFaceting: []string{}, + FilterableAttributes: []string{}, }, }, wantUpdate: &AsyncUpdateID{ @@ -1330,14 +1330,14 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, { @@ -1350,7 +1350,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { "typo", "words", }, SearchableAttributes: []string{ - "title", "tag", + "tag", }, }, firstResponse: Settings{ @@ -1359,12 +1359,12 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, DistinctAttribute: (*string)(nil), SearchableAttributes: []string{ - "title", "tag", + "tag", }, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, secondRequest: Settings{ SearchableAttributes: []string{ @@ -1379,10 +1379,10 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { SearchableAttributes: []string{ "title", }, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, wantUpdate: &AsyncUpdateID{ @@ -1390,14 +1390,14 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, { @@ -1422,9 +1422,9 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { DisplayedAttributes: []string{ "book_id", "tag", "title", }, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, secondRequest: Settings{ DisplayedAttributes: []string{ @@ -1440,9 +1440,9 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { DisplayedAttributes: []string{ "book_id", "tag", }, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, wantUpdate: &AsyncUpdateID{ @@ -1450,14 +1450,14 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, { @@ -1483,8 +1483,8 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { StopWords: []string{ "of", "the", }, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, secondRequest: Settings{ StopWords: []string{ @@ -1501,68 +1501,8 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { StopWords: []string{ "of", "the", }, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, - }, - }, - wantUpdate: &AsyncUpdateID{ - UpdateID: 1, - }, - wantResp: &Settings{ - RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", - }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, - }, - }, - { - name: "TestIndexUpdateJustAttributesForFaceting", - args: args{ - UID: "indexUID", - client: defaultClient, - firstRequest: Settings{ - RankingRules: []string{ - "typo", "words", - }, - AttributesForFaceting: []string{ - "title", - }, - }, - firstResponse: Settings{ - RankingRules: []string{ - "typo", "words", - }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{ - "title", - }, - }, - secondRequest: Settings{ - AttributesForFaceting: []string{ - "title", "tag", - }, - }, - secondResponse: Settings{ - RankingRules: []string{ - "typo", "words", - }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{ - "title", "tag", - }, + FilterableAttributes: []string{}, }, }, wantUpdate: &AsyncUpdateID{ @@ -1570,18 +1510,18 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, { - name: "TestIndexUpdateJustAttributesForFaceting", + name: "TestIndexUpdateJustFilterableAttributes", args: args{ UID: "indexUID", client: defaultClient, @@ -1589,7 +1529,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { RankingRules: []string{ "typo", "words", }, - AttributesForFaceting: []string{ + FilterableAttributes: []string{ "title", }, }, @@ -1602,13 +1542,13 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { DisplayedAttributes: []string{"*"}, StopWords: []string{}, Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{ + FilterableAttributes: []string{ "title", }, }, secondRequest: Settings{ - AttributesForFaceting: []string{ - "title", "tag", + FilterableAttributes: []string{ + "title", }, }, secondResponse: Settings{ @@ -1620,8 +1560,8 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { DisplayedAttributes: []string{"*"}, StopWords: []string{}, Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{ - "title", "tag", + FilterableAttributes: []string{ + "title", }, }, }, @@ -1630,14 +1570,14 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { }, wantResp: &Settings{ RankingRules: []string{ - "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", + "words", "typo", "proximity", "attribute", "exactness", }, - DistinctAttribute: (*string)(nil), - SearchableAttributes: []string{"*"}, - DisplayedAttributes: []string{"*"}, - StopWords: []string{}, - Synonyms: map[string][]string(nil), - AttributesForFaceting: []string{}, + DistinctAttribute: (*string)(nil), + SearchableAttributes: []string{"*"}, + DisplayedAttributes: []string{"*"}, + StopWords: []string{}, + Synonyms: map[string][]string(nil), + FilterableAttributes: []string{}, }, }, } @@ -1653,7 +1593,7 @@ func TestIndex_UpdateSettingsOneByOne(t *testing.T) { gotUpdate, err := i.UpdateSettings(&tt.args.firstRequest) require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err = i.GetSettings() @@ -1687,9 +1627,11 @@ func TestIndex_UpdateStopWords(t *testing.T) { { name: "TestIndexBasicUpdateStopWords", args: args{ - UID: "indexUID", - client: defaultClient, - request: []string{}, + UID: "indexUID", + client: defaultClient, + request: []string{ + "of", "the", "to", + }, }, wantUpdate: &AsyncUpdateID{ UpdateID: 1, @@ -1698,9 +1640,11 @@ func TestIndex_UpdateStopWords(t *testing.T) { { name: "TestIndexUpdateStopWordsWithCustomClient", args: args{ - UID: "indexUID", - client: customClient, - request: []string{}, + UID: "indexUID", + client: customClient, + request: []string{ + "of", "the", "to", + }, }, wantUpdate: &AsyncUpdateID{ UpdateID: 1, @@ -1719,7 +1663,7 @@ func TestIndex_UpdateStopWords(t *testing.T) { gotUpdate, err := i.UpdateStopWords(&tt.args.request) require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err = i.GetStopWords() @@ -1744,9 +1688,11 @@ func TestIndex_UpdateSynonyms(t *testing.T) { { name: "TestIndexBasicUpdateSynonyms", args: args{ - UID: "indexUID", - client: defaultClient, - request: map[string][]string{}, + UID: "indexUID", + client: defaultClient, + request: map[string][]string{ + "wolverine": []string{"logan", "xmen"}, + }, }, wantUpdate: &AsyncUpdateID{ UpdateID: 1, @@ -1755,9 +1701,11 @@ func TestIndex_UpdateSynonyms(t *testing.T) { { name: "TestIndexUpdateSynonymsWithCustomClient", args: args{ - UID: "indexUID", - client: customClient, - request: map[string][]string{}, + UID: "indexUID", + client: customClient, + request: map[string][]string{ + "wolverine": []string{"logan", "xmen"}, + }, }, wantUpdate: &AsyncUpdateID{ UpdateID: 1, @@ -1776,7 +1724,7 @@ func TestIndex_UpdateSynonyms(t *testing.T) { gotUpdate, err := i.UpdateSynonyms(&tt.args.request) require.NoError(t, err) - require.Equal(t, tt.wantUpdate, gotUpdate) + require.GreaterOrEqual(t, gotUpdate.UpdateID, tt.wantUpdate.UpdateID) i.DefaultWaitForPendingUpdate(gotUpdate) gotResp, err = i.GetSynonyms() diff --git a/index_test.go b/index_test.go index 8713f139..c494cadf 100644 --- a/index_test.go +++ b/index_test.go @@ -60,9 +60,9 @@ func TestIndex_Delete(t *testing.T) { Method: "DELETE", Function: "Delete", RequestToString: "empty request", - ResponseToString: "{\"message\":\"Index 1 not found\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", + ResponseToString: "{\"message\":\"Index \\\"1\\\" not found.\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index 1 not found", + Message: "Index \"1\" not found.", ErrorCode: "index_not_found", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_not_found", @@ -88,9 +88,9 @@ func TestIndex_Delete(t *testing.T) { Method: "DELETE", Function: "Delete", RequestToString: "empty request", - ResponseToString: "{\"message\":\"Index 1 not found\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", + ResponseToString: "{\"message\":\"Index \\\"1\\\" not found.\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index 1 not found", + Message: "Index \"1\" not found.", ErrorCode: "index_not_found", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_not_found", @@ -106,9 +106,9 @@ func TestIndex_Delete(t *testing.T) { Method: "DELETE", Function: "Delete", RequestToString: "empty request", - ResponseToString: "{\"message\":\"Index 2 not found\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", + ResponseToString: "{\"message\":\"Index \\\"2\\\" not found.\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index 2 not found", + Message: "Index \"2\" not found.", ErrorCode: "index_not_found", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_not_found"}, @@ -123,9 +123,9 @@ func TestIndex_Delete(t *testing.T) { Method: "DELETE", Function: "Delete", RequestToString: "empty request", - ResponseToString: "{\"message\":\"Index 3 not found\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", + ResponseToString: "{\"message\":\"Index \\\"3\\\" not found.\",\"errorCode\":\"index_not_found\",\"errorType\":\"invalid_request_error\",\"errorLink\":\"https://docs.meilisearch.com/errors#index_not_found\"}", MeilisearchApiMessage: meilisearchApiMessage{ - Message: "Index 3 not found", + Message: "Index \"3\" not found.", ErrorCode: "index_not_found", ErrorType: "invalid_request_error", ErrorLink: "https://docs.meilisearch.com/errors#index_not_found"}, @@ -179,6 +179,7 @@ func TestIndex_GetStats(t *testing.T) { wantResp: &StatsIndex{ NumberOfDocuments: 6, IsIndexing: false, + FieldDistribution: map[string]int64{"book_id": 6, "title": 6}, }, }, { @@ -190,6 +191,7 @@ func TestIndex_GetStats(t *testing.T) { wantResp: &StatsIndex{ NumberOfDocuments: 6, IsIndexing: false, + FieldDistribution: map[string]int64{"book_id": 6, "title": 6}, }, }, } diff --git a/main_test.go b/main_test.go index 31c24288..2adde360 100644 --- a/main_test.go +++ b/main_test.go @@ -18,6 +18,7 @@ type docTestBooks struct { BookID int `json:"book_id"` Title string `json:"title"` Tag string `json:"tag"` + Year int `json:"year"` } func deleteAllIndexes(client ClientInterface) (ok bool, err error) { @@ -67,26 +68,26 @@ func SetUpIndexForFaceting() { index := client.Index("indexUID") booksTest := []docTestBooks{ - {BookID: 123, Title: "Pride and Prejudice", Tag: "Romance"}, - {BookID: 456, Title: "Le Petit Prince", Tag: "Tale"}, - {BookID: 1, Title: "Alice In Wonderland", Tag: "Tale"}, - {BookID: 1344, Title: "The Hobbit", Tag: "Epic fantasy"}, - {BookID: 4, Title: "Harry Potter and the Half-Blood Prince", Tag: "Epic fantasy"}, - {BookID: 42, Title: "The Hitchhiker's Guide to the Galaxy", Tag: "Epic fantasy"}, - {BookID: 742, Title: "The Great Gatsby", Tag: "Tragedy"}, - {BookID: 834, Title: "One Hundred Years of Solitude", Tag: "Tragedy"}, - {BookID: 17, Title: "In Search of Lost Time", Tag: "Modernist literature"}, - {BookID: 204, Title: "Ulysses", Tag: "Novel"}, - {BookID: 7, Title: "Don Quixote", Tag: "Satiric"}, - {BookID: 10, Title: "Moby Dick", Tag: "Novel"}, - {BookID: 730, Title: "War and Peace", Tag: "Historical fiction"}, - {BookID: 69, Title: "Hamlet", Tag: "Tragedy"}, - {BookID: 32, Title: "The Odyssey", Tag: "Epic"}, - {BookID: 71, Title: "Madame Bovary", Tag: "Novel"}, - {BookID: 56, Title: "The Divine Comedy", Tag: "Epic"}, - {BookID: 254, Title: "Lolita", Tag: "Novel"}, - {BookID: 921, Title: "The Brothers Karamazov", Tag: "Novel"}, - {BookID: 1032, Title: "Crime and Punishment", Tag: "Crime fiction"}, + {BookID: 123, Title: "Pride and Prejudice", Tag: "Romance", Year: 1813}, + {BookID: 456, Title: "Le Petit Prince", Tag: "Tale", Year: 1943}, + {BookID: 1, Title: "Alice In Wonderland", Tag: "Tale", Year: 1865}, + {BookID: 1344, Title: "The Hobbit", Tag: "Epic fantasy", Year: 1937}, + {BookID: 4, Title: "Harry Potter and the Half-Blood Prince", Tag: "Epic fantasy", Year: 2005}, + {BookID: 42, Title: "The Hitchhiker's Guide to the Galaxy", Tag: "Epic fantasy", Year: 1978}, + {BookID: 742, Title: "The Great Gatsby", Tag: "Tragedy", Year: 1925}, + {BookID: 834, Title: "One Hundred Years of Solitude", Tag: "Tragedy", Year: 1967}, + {BookID: 17, Title: "In Search of Lost Time", Tag: "Modernist literature", Year: 1913}, + {BookID: 204, Title: "Ulysses", Tag: "Novel", Year: 1922}, + {BookID: 7, Title: "Don Quixote", Tag: "Satiric", Year: 1605}, + {BookID: 10, Title: "Moby Dick", Tag: "Novel", Year: 1851}, + {BookID: 730, Title: "War and Peace", Tag: "Historical fiction", Year: 1865}, + {BookID: 69, Title: "Hamlet", Tag: "Tragedy", Year: 1598}, + {BookID: 32, Title: "The Odyssey", Tag: "Epic", Year: 1571}, + {BookID: 71, Title: "Madame Bovary", Tag: "Novel", Year: 1857}, + {BookID: 56, Title: "The Divine Comedy", Tag: "Epic", Year: 1303}, + {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}, } update, err := index.AddDocuments(booksTest) if err != nil { From 6413e4f5de556c1411f1efd69a67b0d341c5fb29 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 14:33:32 +0200 Subject: [PATCH 10/18] Adding facetDistribution --- index_search_test.go | 139 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 113 insertions(+), 26 deletions(-) diff --git a/index_search_test.go b/index_search_test.go index 2139b185..8e6f0b5c 100644 --- a/index_search_test.go +++ b/index_search_test.go @@ -256,6 +256,119 @@ func TestIndex_Search(t *testing.T) { } } +func TestIndex_SearchFacets(t *testing.T) { + type args struct { + UID string + PrimaryKey string + client *Client + query string + request SearchRequest + filterableAttributes []string + } + tests := []struct { + name string + args args + want *SearchResponse + }{ + { + name: "TestIndexSearchWithFacetsDistribution", + args: args{ + UID: "indexUID", + client: defaultClient, + query: "prince", + request: SearchRequest{ + FacetsDistribution: []string{"*"}, + }, + filterableAttributes: []string{"tag"}, + }, + want: &SearchResponse{ + Hits: []interface{}{ + map[string]interface{}{ + "book_id": float64(456), "title": "Le Petit Prince", + }, + map[string]interface{}{ + "book_id": float64(4), "title": "Harry Potter and the Half-Blood Prince", + }, + }, + NbHits: 2, + Offset: 0, + Limit: 20, + ExhaustiveNbHits: false, + FacetsDistribution: map[string]interface{}( + map[string]interface{}{ + "tag": map[string]interface{}{ + "epic fantasy": float64(1), + "tale": float64(1), + }, + }), + ExhaustiveFacetsCount: interface{}(false), + }, + }, + { + name: "TestIndexSearchWithFacetsDistributionWithCustomClient", + args: args{ + UID: "indexUID", + client: customClient, + query: "prince", + request: SearchRequest{ + FacetsDistribution: []string{"*"}, + }, + filterableAttributes: []string{"tag"}, + }, + want: &SearchResponse{ + Hits: []interface{}{ + map[string]interface{}{ + "book_id": float64(456), "title": "Le Petit Prince", + }, + map[string]interface{}{ + "book_id": float64(4), "title": "Harry Potter and the Half-Blood Prince", + }, + }, + NbHits: 2, + Offset: 0, + Limit: 20, + ExhaustiveNbHits: false, + FacetsDistribution: map[string]interface{}( + map[string]interface{}{ + "tag": map[string]interface{}{ + "epic fantasy": float64(1), + "tale": float64(1), + }, + }), + ExhaustiveFacetsCount: interface{}(false), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + SetUpIndexForFaceting() + c := tt.args.client + i := c.Index(tt.args.UID) + + updateFilter, err := i.UpdateFilterableAttributes(&tt.args.filterableAttributes) + require.NoError(t, err) + i.DefaultWaitForPendingUpdate(updateFilter) + + got, err := i.Search(tt.args.query, &tt.args.request) + require.NoError(t, err) + require.Equal(t, len(tt.want.Hits), len(got.Hits)) + for len := range got.Hits { + require.Equal(t, tt.want.Hits[len].(map[string]interface{})["title"], got.Hits[len].(map[string]interface{})["title"]) + require.Equal(t, tt.want.Hits[len].(map[string]interface{})["book_id"], got.Hits[len].(map[string]interface{})["book_id"]) + } + require.Equal(t, tt.want.NbHits, got.NbHits) + require.Equal(t, tt.want.Offset, got.Offset) + require.Equal(t, tt.want.Limit, got.Limit) + require.Equal(t, tt.want.ExhaustiveNbHits, got.ExhaustiveNbHits) + + require.Equal(t, tt.want.FacetsDistribution, got.FacetsDistribution) + require.Equal(t, tt.want.ExhaustiveFacetsCount, got.ExhaustiveFacetsCount) + + deleteAllIndexes(c) + }) + } +} + func TestIndex_SearchWithFilters(t *testing.T) { type args struct { UID string @@ -438,32 +551,6 @@ func TestIndex_SearchWithFilters(t *testing.T) { ExhaustiveNbHits: false, }, }, - // { - // name: "TestIndexSearchWithArrayFilter", - // args: args{ - // UID: "indexUID", - // client: defaultClient, - // query: "", - // filterableAttributes: []string{ - // "tag", - // "year", - // }, - // request: SearchRequest{ - // Filter: "tag = fantasy, year = 2005", - // }, - // }, - // want: &SearchResponse{ - // Hits: []interface{}{ - // map[string]interface{}{ - // "book_id": float64(1), "title": "Alice In Wonderland", - // }, - // }, - // NbHits: 1, - // Offset: 0, - // Limit: 20, - // ExhaustiveNbHits: false, - // }, - // }, { name: "TestIndexSearchWithAttributeToHighlight", args: args{ From fc93b132cba767136f8bbe4fb2ced67b2a88d3bc Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 7 Jul 2021 18:44:51 +0200 Subject: [PATCH 11/18] update code samples --- .code-samples.meilisearch.yaml | 187 ++++++++++++++------------------- 1 file changed, 81 insertions(+), 106 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 02e15988..39a740b4 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -13,7 +13,7 @@ create_an_index_1: |- PrimaryKey: "movie_id", }) update_an_index_1: |- - client.Index("movies").UpdateIndex(response.UID, "movie_id") + client.Index("movies").UpdateIndex("movie_review_id") delete_an_index_1: |- client.DeleteIndex("movies") // OR @@ -23,7 +23,7 @@ get_one_document_1: |- client.Index("movies").GetDocument("25684", &a) get_documents_1: |- var a []interface{} - client.Index("movies").GetDocuments(meilisearch.DocumentsRequest{ + client.Index("movies").GetDocuments(&meilisearch.DocumentsRequest{ Limit: 2, }, &a) add_or_replace_documents_1: |- @@ -41,7 +41,7 @@ add_or_update_documents_1: |- documents := []map[string]interface{}{ { "id": 287947, - "title": "Shazam", + "title": "Shazam ⚡️", "genres": "comedy", }, } @@ -58,11 +58,11 @@ delete_documents_1: |- "363869", }) search_post_1: |- - client.Index("movies").Search(SearchRequest{ - Query: "American ninja", - }) + client.Index("movies").Search("american ninja", nil) +search_get_1: |- + get_update_1: |- - client.Index("movies").GetUpdateStatus(0) + client.Index("movies").GetUpdateStatus(1) get_all_updates_1: |- client.Index("movies").GetAllUpdateStatus() get_keys_1: |- @@ -73,11 +73,10 @@ update_settings_1: |- distinctAttribute := "movie_id" settings := meilisearch.Settings{ RankingRules: []string{ - "typo", "words", + "typo", "proximity", "attribute", - "wordsPosition", "exactness", "desc(release_date)", "desc(rank)", @@ -122,18 +121,17 @@ get_stop_words_1: |- client.Index("movies").GetStopWords() update_stop_words_1: |- stopWords := []string{"of", "the", "to"} - client.Index("movies").UpdateStopWords(stopWords) + client.Index("movies").UpdateStopWords(&stopWords) reset_stop_words_1: |- client.Index("movies").ResetStopWords() get_ranking_rules_1: |- client.Index("movies").GetRankingRules() update_ranking_rules_1: |- rankingRules := []string{ - "typo", "words", + "typo", "proximity", "attribute", - "wordsPosition", "exactness", "asc(release_date)", "desc(rank)", @@ -147,6 +145,16 @@ update_distinct_attribute_1: |- client.Index("movies").UpdateDistinctAttribute("movie_id") reset_distinct_attribute_1: |- client.Index("movies").ResetDistinctAttribute() +get_filterable_attributes_1: |- + client.Index("movies").GetFilterableAttributes() +update_filterable_attributes_1: |- + filterableAttributes := []string{ + "genres", + "director", + } + client.Index("movies").UpdateFilterableAttributes(&filterableAttributes) +reset_filterable_attributes_1: |- + client.Index("movies").ResetFilterableAttributes() get_searchable_attributes_1: |- client.Index("movies").GetSearchableAttributes() update_searchable_attributes_1: |- @@ -158,16 +166,6 @@ update_searchable_attributes_1: |- client.Index("movies").UpdateSearchableAttributes(&searchableAttributes) reset_searchable_attributes_1: |- client.Index("movies").ResetSearchableAttributes() -get_attributes_for_faceting_1: |- - client.Index("movies").GetFilterableAttributes() -update_attributes_for_faceting_1: |- - filterableAttributes := []string{ - "genres", - "director", - } - client.Index("movies").UpdateFilterableAttributes(&filterableAttributes) -reset_attributes_for_faceting_1: |- - client.Index("movies").ResetFilterableAttributes() get_displayed_attributes_1: |- client.Index("movies").GetDisplayedAttributes() update_displayed_attributes_1: |- @@ -196,7 +194,7 @@ field_properties_guide_searchable_1: |- "description", "genre", } - client.Index("movies").UpdateSearchableAttributes(searchableAttributes) + client.Index("movies").UpdateSearchableAttributes(&searchableAttributes) field_properties_guide_displayed_1: |- displayedAttributes := []string{ "title", @@ -204,72 +202,56 @@ field_properties_guide_displayed_1: |- "genre", "release_date", } - client.Index("movies").UpdateDisplayedAttributes(displayedAttributes) + client.Index("movies").UpdateDisplayedAttributes(&displayedAttributes) filtering_guide_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "Avengers", + results, err := client.Index("movies").Search("Avengers", &meilisearch.SearchRequest{ Filter: "release_date > \"795484800\"", }) filtering_guide_2: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "Batman", + results, err := client.Index("movies").Search("Batman", &meilisearch.SearchRequest{ Filter: "release_date > 795484800 AND (director = \"Tim Burton\" OR director = \"Christopher Nolan\")", }) filtering_guide_3: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "horror", + results, err := client.Index("movies").Search("horror", &meilisearch.SearchRequest{ Filter: "director = \"Jordan Peele\"", }) filtering_guide_4: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "Planet of the Apes", + results, err := client.Index("movies").Search("Planet of the Apes", &meilisearch.SearchRequest{ Filter: "rating >= 3 AND (NOT director = \"Tim Burton\"", }) search_parameter_guide_query_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "shifu", - }) + results, err := client.Index("movies").Search("shifu", &meilisearch.SearchRequest{}) search_parameter_guide_offset_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "shifu", + results, err := client.Index("movies").Search("shifu", &meilisearch.SearchRequest{ Offset: 1, }) search_parameter_guide_limit_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "shifu", + results, err := client.Index("movies").Search("shifu", &meilisearch.SearchRequest{ Limit: 2, }) search_parameter_guide_retrieve_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "shifu", + results, err := client.Index("movies").Search("shifu", &meilisearch.SearchRequest{ AttributesToRetrieve: []string{"overview", "title"}, }) search_parameter_guide_crop_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "shifu", + results, err := client.Index("movies").Search("shifu" &meilisearch.SearchRequest{ AttributesToCrop: []string{"overview"}, CropLength: 10, }) search_parameter_guide_highlight_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "shifu", + results, err := client.Index("movies").Search("winter feast", &meilisearch.SearchRequest{ AttributesToHighlight: []string{"overview"}, }) search_parameter_guide_filter_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "n", + results, err := client.Index("movies").Search("n", &meilisearch.SearchRequest{ Filter: "title = Nightshift", }) search_parameter_guide_filter_2: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "n", + results, err := client.Index("movies").Search("n", &meilisearch.SearchRequest{ Filter: "title=\"Kung Fu Panda\"", }) search_parameter_guide_matches_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "n", - Filter: "title=\"Kung Fu Panda\"", - AttributesToHighlight: []string{"overview"}, + results, err := client.Index("movies").Search("winter feast", &meilisearch.SearchRequest{ Matches: true, }) settings_guide_synonyms_1: |- @@ -277,22 +259,21 @@ settings_guide_synonyms_1: |- "sweater": []string{"jumper"}, "jumper": []string{"sweater"}, } - client.Index("movies").UpdateSynonyms(synonyms) + client.Index("movies").UpdateSynonyms(&synonyms) settings_guide_stop_words_1: |- stopWords := []string{"the", "a", "an"} - client.Index("movies").UpdateStopWords(stopWords) + client.Index("movies").UpdateStopWords(&stopWords) settings_guide_ranking_rules_1: |- rankingRules := []string{ - "typo", "words", + "typo", "proximity", "attribute", - "wordsPosition", "exactness", "asc(release_date)", "desc(rank)", } - client.Index("movies").UpdateRankingRules(rankingRules) + client.Index("movies").UpdateRankingRules(&rankingRules) settings_guide_distinct_1: |- client.Index("movies").UpdateDistinctAttribute("movie_id") settings_guide_searchable_1: |- @@ -301,7 +282,7 @@ settings_guide_searchable_1: |- "description", "genre", } - client.Index("movies").UpdateSearchableAttributes(searchableAttributes) + client.Index("movies").UpdateSearchableAttributes(&searchableAttributes) settings_guide_displayed_1: |- displayedAttributes := []string{ "title", @@ -309,7 +290,19 @@ settings_guide_displayed_1: |- "genre", "release_date", } - client.Index("movies").UpdateDisplayedAttributes(displayedAttributes) + client.Index("movies").UpdateDisplayedAttributes(&displayedAttributes) +add_movies_json_1: |- + import ( + "encoding/json" + "io/ioutil" + ) + + file, _ := ioutil.ReadFile("movies.json") + + var movies interface{} + json.Unmarshal([]byte(file), &movies) + + index.AddDocuments(&movies) documents_guide_add_movie_1: |- documents := []map[string]interface{}{ { @@ -319,14 +312,12 @@ documents_guide_add_movie_1: |- } client.Index("movies").AddDocuments(documents) search_guide_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "shifu", + results, err := client.Index("movies").Search("shifu", &meilisearch.SearchRequest{ Limit: 5, Offset: 10, }) search_guide_2: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "Avengers", + results, err := client.Index("movies").Search("Avengers", &meilisearch.SearchRequest{ Filter: "release_date > \"795484800\"", }) getting_started_add_documents_md: |- @@ -346,7 +337,7 @@ getting_started_add_documents_md: |- ) func main() { - client = meilisearch.NewClient(meilisearch.ClientConfig{ + client := meilisearch.NewClient(meilisearch.ClientConfig{ Host: "http://127.0.0.1:7700", }) @@ -357,7 +348,7 @@ getting_started_add_documents_md: |- var movies []map[string]interface{} json.Unmarshal(byteValue, &movies) - update, err := client.Index("movies").AddDocuments(movies) + _, err := client.Index("movies").AddDocuments(movies) if err != nil { panic(err) } @@ -367,9 +358,7 @@ getting_started_add_documents_md: |- [About this SDK](https://github.com/meilisearch/meilisearch-go/) getting_started_search_md: |- ```go - results, err := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "botman", - }) + results, err := client.Index("movies").Search("botman", &meilisearch.SearchRequest{}) if err != nil { panic(err) } @@ -377,60 +366,46 @@ getting_started_search_md: |- [About this SDK](https://github.com/meilisearch/meilisearch-go/) faceted_search_update_settings_1: |- - response, error := client.Index("movies").UpdateAttributesForFaceting([]string{ + response, err := client.Index("movies").UpdateFilterableAttributes(&[]string{ "director", "genres", }) -# faceted_search_facet_filters_1: |- -# results, error := client.Index("movies").Search(meilisearch.SearchRequest{ -# Query: "thriller", -# FacetFilter: [][]string{ -# []string{"genres:Horror", "genres:Mystery"}, -# []string{"director:Jordan Peele"}, -# }, -# }) +faceted_search_filter_1: |- + results, err := client.Index("movies").Search("thriller", &meilisearch.SearchRequest{ + Filter: [][]string{ + []string{"genres:Horror", "genres:Mystery"}, + []string{"director:Jordan Peele"}, + }, + }) faceted_search_facets_distribution_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "Batman", + results, err := client.Index("movies").Search("Batman", &meilisearch.SearchRequest{ FacetsDistribution: []string{ "genres", }, }) -faceted_search_walkthrough_attributes_for_faceting_1: |- - response, error := client.Index("movies").UpdateAttributesForFaceting([]string{ +faceted_search_walkthrough_filterable_attributes_1: |- + response, err := client.Index("movies").UpdateFilterableAttributes(&[]string{ "director", "producer", "genres", "production_companies", }) -# faceted_search_walkthrough_facet_filters_1: |- -# results, error := client.Index("movies").Search(meilisearch.SearchRequest{ -# Query: "thriller", -# FacetFilter: [][]string{ -# []string{"genres:Horror", "genres:Mystery"}, -# []string{"director:Jordan Peele"}, -# }, -# }) +faceted_search_walkthrough_filter_1: |- + results, err := client.Index("movies").Search("thriller", &meilisearch.SearchRequest{ + Filter: [][]string{ + []string{"genres:Horror", "genres:Mystery"}, + []string{"director:Jordan Peele"}, + }, + }) faceted_search_walkthrough_facets_distribution_1: |- - results, error := client.Index("movies").Search(meilisearch.SearchRequest{ - Query: "Batman", + results, err := client.Index("movies").Search("Batman", &meilisearch.SearchRequest{ FacetsDistribution: []string{ "genres", }, }) post_dump_1: |- - results, error := client.CreateDump() + results, err := client.CreateDump() get_dump_status_1: |- - results, error := client.GetDumpStatus("dump-uid") -add_movies_json_1: |- - import ( - "encoding/json" - "io/ioutil" - ) - - file, _ := ioutil.ReadFile("movies.json") - - var movies interface{} - json.Unmarshal([]byte(file), &movies) - - index.AddDocuments(&movies) + results, err := client.GetDumpStatus("dump-uid") +phrase_search_1: |- +results, err := client.Index("movies").Search("\"neo\"", &meilisearch.SearchRequest{}) From 3af54a7db4151c2bf68d0f61a32e2e5957936b46 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 7 Jul 2021 19:00:05 +0200 Subject: [PATCH 12/18] update code samples --- .code-samples.meilisearch.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 39a740b4..574b3559 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -248,7 +248,7 @@ search_parameter_guide_filter_1: |- }) search_parameter_guide_filter_2: |- results, err := client.Index("movies").Search("n", &meilisearch.SearchRequest{ - Filter: "title=\"Kung Fu Panda\"", + Filter: "title = \"Kung Fu Panda\"", }) search_parameter_guide_matches_1: |- results, err := client.Index("movies").Search("winter feast", &meilisearch.SearchRequest{ @@ -373,8 +373,8 @@ faceted_search_update_settings_1: |- faceted_search_filter_1: |- results, err := client.Index("movies").Search("thriller", &meilisearch.SearchRequest{ Filter: [][]string{ - []string{"genres:Horror", "genres:Mystery"}, - []string{"director:Jordan Peele"}, + []string{"genres = Horror", "genres = Mystery"}, + []string{"director = \"Jordan Peele\""}, }, }) faceted_search_facets_distribution_1: |- @@ -393,8 +393,8 @@ faceted_search_walkthrough_filterable_attributes_1: |- faceted_search_walkthrough_filter_1: |- results, err := client.Index("movies").Search("thriller", &meilisearch.SearchRequest{ Filter: [][]string{ - []string{"genres:Horror", "genres:Mystery"}, - []string{"director:Jordan Peele"}, + []string{"genres = Horror", "genres = Mystery"}, + []string{"director = \"Jordan Peele\""}, }, }) faceted_search_walkthrough_facets_distribution_1: |- From 06185ced01b7b0dc534e97757a192e3b555b70fc Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 8 Jul 2021 15:27:56 +0200 Subject: [PATCH 13/18] Fix error in code sample --- .code-samples.meilisearch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 574b3559..93069610 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -58,7 +58,7 @@ delete_documents_1: |- "363869", }) search_post_1: |- - client.Index("movies").Search("american ninja", nil) + client.Index("movies").Search("american ninja", &meilisearch.SearchRequest{}) search_get_1: |- get_update_1: |- From b92bfb85b8a043eac138ac21aa24147958055212 Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 13 Jul 2021 14:35:36 +0200 Subject: [PATCH 14/18] Fix error in code samples --- .code-samples.meilisearch.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 93069610..6c78ff82 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -60,7 +60,7 @@ delete_documents_1: |- search_post_1: |- client.Index("movies").Search("american ninja", &meilisearch.SearchRequest{}) search_get_1: |- - + client.Index("movies").Search("american ninja", &meilisearch.SearchRequest{}) get_update_1: |- client.Index("movies").GetUpdateStatus(1) get_all_updates_1: |- @@ -259,7 +259,7 @@ settings_guide_synonyms_1: |- "sweater": []string{"jumper"}, "jumper": []string{"sweater"}, } - client.Index("movies").UpdateSynonyms(&synonyms) + client.Index("tops").UpdateSynonyms(&synonyms) settings_guide_stop_words_1: |- stopWords := []string{"the", "a", "an"} client.Index("movies").UpdateStopWords(&stopWords) From 2d3af15a2381c3449fbc7b1aaddf72eb54e1d136 Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 20 Jul 2021 16:20:06 +0200 Subject: [PATCH 15/18] Update Filter to allow string an array --- .code-samples.meilisearch.yaml | 4 +-- index_search.go | 2 +- index_search_test.go | 56 ++++++++++++++++++++++++++++++++++ types.go | 2 +- types_easyjson.go | 16 ++++++++-- 5 files changed, 74 insertions(+), 6 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 4375c9e1..c30cda79 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -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", @@ -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{}) diff --git a/index_search.go b/index_search.go index 38ac46da..10030f24 100644 --- a/index_search.go +++ b/index_search.go @@ -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 { diff --git a/index_search_test.go b/index_search_test.go index 8e6f0b5c..11b9ea7d 100644 --- a/index_search_test.go +++ b/index_search_test.go @@ -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{ diff --git a/types.go b/types.go index c6943005..826b1bb2 100644 --- a/types.go +++ b/types.go @@ -139,7 +139,7 @@ type SearchRequest struct { AttributesToCrop []string CropLength int64 AttributesToHighlight []string - Filter string + Filter interface{} Matches bool FacetsDistribution []string PlaceholderSearch bool diff --git a/types_easyjson.go b/types_easyjson.go index 435cd21e..dcf54ba9 100644 --- a/types_easyjson.go +++ b/types_easyjson.go @@ -1178,7 +1178,13 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo7(in *jlexer.Lexer, in.Delim(']') } case "Filter": - out.Filter = string(in.String()) + if m, ok := out.Filter.(easyjson.Unmarshaler); ok { + m.UnmarshalEasyJSON(in) + } else if m, ok := out.Filter.(json.Unmarshaler); ok { + _ = m.UnmarshalJSON(in.Raw()) + } else { + out.Filter = in.Interface() + } case "Matches": out.Matches = bool(in.Bool()) case "FacetsDistribution": @@ -1286,7 +1292,13 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo7(out *jwriter.Write { const prefix string = ",\"Filter\":" out.RawString(prefix) - out.String(string(in.Filter)) + if m, ok := in.Filter.(easyjson.Marshaler); ok { + m.MarshalEasyJSON(out) + } else if m, ok := in.Filter.(json.Marshaler); ok { + out.Raw(m.MarshalJSON()) + } else { + out.Raw(json.Marshal(in.Filter)) + } } { const prefix string = ",\"Matches\":" From bf415f61d07d0af6cf2c29855e3839b37ed22fe9 Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 20 Jul 2021 16:37:13 +0200 Subject: [PATCH 16/18] Fix code sample --- .code-samples.meilisearch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 6c78ff82..0285f21b 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -275,7 +275,7 @@ settings_guide_ranking_rules_1: |- } client.Index("movies").UpdateRankingRules(&rankingRules) settings_guide_distinct_1: |- - client.Index("movies").UpdateDistinctAttribute("movie_id") + client.Index("jackets").UpdateDistinctAttribute("product_id") settings_guide_searchable_1: |- searchableAttributes := []string{ "title", From 2a348f68c711d195dcbe28579a8224df643335cd Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 21 Jul 2021 11:43:08 +0200 Subject: [PATCH 17/18] Fix code sample --- .code-samples.meilisearch.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 0285f21b..05f4ae26 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -59,8 +59,6 @@ delete_documents_1: |- }) search_post_1: |- client.Index("movies").Search("american ninja", &meilisearch.SearchRequest{}) -search_get_1: |- - client.Index("movies").Search("american ninja", &meilisearch.SearchRequest{}) get_update_1: |- client.Index("movies").GetUpdateStatus(1) get_all_updates_1: |- From 79401f4f7cc27115a5a0ebfb6b32b3e13d2f6d61 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 29 Jul 2021 18:40:42 +0200 Subject: [PATCH 18/18] Fix FacetsDistribution --- index_search_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index_search_test.go b/index_search_test.go index 11b9ea7d..d699d12c 100644 --- a/index_search_test.go +++ b/index_search_test.go @@ -297,8 +297,8 @@ func TestIndex_SearchFacets(t *testing.T) { FacetsDistribution: map[string]interface{}( map[string]interface{}{ "tag": map[string]interface{}{ - "epic fantasy": float64(1), - "tale": float64(1), + "Epic fantasy": float64(1), + "Tale": float64(1), }, }), ExhaustiveFacetsCount: interface{}(false), @@ -331,8 +331,8 @@ func TestIndex_SearchFacets(t *testing.T) { FacetsDistribution: map[string]interface{}( map[string]interface{}{ "tag": map[string]interface{}{ - "epic fantasy": float64(1), - "tale": float64(1), + "Epic fantasy": float64(1), + "Tale": float64(1), }, }), ExhaustiveFacetsCount: interface{}(false),