Skip to content

Commit

Permalink
Merge pull request #165 from meilisearch/update-readme-and-sample
Browse files Browse the repository at this point in the history
Update readme and code sample
  • Loading branch information
alallema authored Jul 5, 2021
2 parents 23b7c07 + 75dfe79 commit 20c79db
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 55 deletions.
68 changes: 34 additions & 34 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down Expand Up @@ -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: |-
Expand All @@ -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: |-
Expand All @@ -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: |-
Expand All @@ -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: |-
Expand All @@ -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: |-
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 <!-- omit in toc -->

Expand Down Expand Up @@ -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)
Expand All @@ -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 <em>Prince</em>"
"book_id": 1344,
"title": "The <em>Hob</em>bit"
}
}
],
"offset": 0,
"limit": 1,
"limit": 20,
"processingTimeMs": 0,
"query": "prince"
"query": "hob"
}
```

Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions client_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -62,7 +62,7 @@ func SetUpBasicIndex() {
func SetUpIndexForFaceting() {
client := NewClient(ClientConfig{
Host: "http://localhost:7700",
ApiKey: masterKey,
APIKey: masterKey,
})
index := client.Index("indexUID")

Expand Down Expand Up @@ -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},
Expand All @@ -117,7 +117,7 @@ var customClient = NewFastHTTPCustomClient(ClientConfig{

var timeoutClient = NewClient(ClientConfig{
Host: "http://localhost:7700",
ApiKey: masterKey,
APIKey: masterKey,
Timeout: 1,
})

Expand Down

0 comments on commit 20c79db

Please sign in to comment.