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 483e2ad0..abcdfd26 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ import ( func main() { client := meilisearch.NewClient(meilisearch.ClientConfig{ Host: "http://127.0.0.1:7700", - ApiKey: "masterKey", + APIKey: "masterKey", }) // An index is where the documents are stored. index := client.Index("indexUID") @@ -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,18 +167,18 @@ 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" } ``` diff --git a/client.go b/client.go index 85ca46ed..11b7b4cf 100644 --- a/client.go +++ b/client.go @@ -14,8 +14,8 @@ type ClientConfig struct { // Example: 'http://localhost:7700' Host string - // ApiKey is optional - ApiKey string + // APIKey is optional + APIKey string // Timeout is optional Timeout time.Duration diff --git a/client_request.go b/client_request.go index b48312e0..f2952baa 100644 --- a/client_request.go +++ b/client_request.go @@ -104,8 +104,8 @@ func (c *Client) sendRequest(req *internalRequest, internalError *Error, respons // adding request headers request.Header.Set("Content-Type", "application/json") - if c.config.ApiKey != "" { - request.Header.Set("X-Meili-API-Key", c.config.ApiKey) + if c.config.APIKey != "" { + request.Header.Set("X-Meili-API-Key", c.config.APIKey) } // request is sent diff --git a/client_test.go b/client_test.go index 1cbd7646..f11db762 100644 --- a/client_test.go +++ b/client_test.go @@ -146,7 +146,7 @@ func TestClient_Health(t *testing.T) { client: &Client{ config: ClientConfig{ Host: "http://wrongurl:1234", - ApiKey: masterKey, + APIKey: masterKey, }, httpClient: &fasthttp.Client{ Name: "meilsearch-client", @@ -213,7 +213,7 @@ func TestClient_IsHealthy(t *testing.T) { client: &Client{ config: ClientConfig{ Host: "http://wrongurl:1234", - ApiKey: masterKey, + APIKey: masterKey, }, httpClient: &fasthttp.Client{ Name: "meilsearch-client", diff --git a/main_test.go b/main_test.go index 24087202..31c24288 100644 --- a/main_test.go +++ b/main_test.go @@ -36,7 +36,7 @@ func deleteAllIndexes(client ClientInterface) (ok bool, err error) { func SetUpBasicIndex() { client := NewClient(ClientConfig{ Host: "http://localhost:7700", - ApiKey: masterKey, + APIKey: masterKey, }) index := client.Index("indexUID") @@ -62,7 +62,7 @@ func SetUpBasicIndex() { func SetUpIndexForFaceting() { client := NewClient(ClientConfig{ Host: "http://localhost:7700", - ApiKey: masterKey, + APIKey: masterKey, }) index := client.Index("indexUID") @@ -103,12 +103,12 @@ var masterKey = "masterKey" var primaryKey = "primaryKey" var defaultClient = NewClient(ClientConfig{ Host: "http://localhost:7700", - ApiKey: masterKey, + APIKey: masterKey, }) var customClient = NewFastHTTPCustomClient(ClientConfig{ Host: "http://localhost:7700", - ApiKey: masterKey, + APIKey: masterKey, }, &fasthttp.Client{ TLSConfig: &tls.Config{InsecureSkipVerify: true}, @@ -117,7 +117,7 @@ var customClient = NewFastHTTPCustomClient(ClientConfig{ var timeoutClient = NewClient(ClientConfig{ Host: "http://localhost:7700", - ApiKey: masterKey, + APIKey: masterKey, Timeout: 1, })