diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml
index 0704cf7a..48562f4a 100644
--- a/.code-samples.meilisearch.yaml
+++ b/.code-samples.meilisearch.yaml
@@ -71,11 +71,10 @@ update_settings_1: |-
distinctAttribute := "movie_id"
settings := meilisearch.Settings{
RankingRules: []string{
- "typo",
"words",
+ "typo",
"proximity",
"attribute",
- "wordsPosition",
"exactness",
"desc(release_date)",
"desc(rank)",
@@ -127,11 +126,10 @@ 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)",
@@ -145,6 +143,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: |-
@@ -156,16 +164,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").GetAttributesForFaceting()
-update_attributes_for_faceting_1: |-
- attributesForFaceting := []string{
- "genres",
- "director",
- }
- client.Index("movies").UpdateAttributesForFaceting(&attributesForFaceting)
-reset_attributes_for_faceting_1: |-
- client.Index("movies").ResetAttributesForFaceting()
get_displayed_attributes_1: |-
client.Index("movies").GetDisplayedAttributes()
update_displayed_attributes_1: |-
@@ -205,19 +203,19 @@ field_properties_guide_displayed_1: |-
client.Index("movies").UpdateDisplayedAttributes(&displayedAttributes)
filtering_guide_1: |-
resp, err := client.Index("movies").Search("Avengers", &meilisearch.SearchRequest{
- Filters: "release_date > \"795484800\"",
+ Filter: "release_date > \"795484800\"",
})
filtering_guide_2: |-
resp, err := client.Index("movies").Search("Batman", &meilisearch.SearchRequest{
- 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: |-
resp, err := client.Index("movies").Search("horror", &meilisearch.SearchRequest{
- Filters: "director = \"Jordan Peele\"",
+ Filter: "director = \"Jordan Peele\"",
})
filtering_guide_4: |-
resp, err := client.Index("movies").Search("Planet of the Apes", &meilisearch.SearchRequest{
- Filters: "rating >= 3 AND (NOT director = \"Tim Burton\"",
+ Filter: "rating >= 3 AND (NOT director = \"Tim Burton\"",
})
search_parameter_guide_query_1: |-
resp, err := client.Index("movies").Search("shifu", &meilisearch.SearchRequest{})
@@ -239,21 +237,19 @@ search_parameter_guide_crop_1: |-
CropLength: 10,
})
search_parameter_guide_highlight_1: |-
- resp, err := client.Index("movies").Search("shifu", &meilisearch.SearchRequest{
+ resp, err := client.Index("movies").Search("winter feast", &meilisearch.SearchRequest{
AttributesToHighlight: []string{"overview"},
})
search_parameter_guide_filter_1: |-
resp, err := client.Index("movies").Search("n", &meilisearch.SearchRequest{
- Filters: "title = Nightshift",
+ Filter: "title = Nightshift",
})
search_parameter_guide_filter_2: |-
resp, err := client.Index("movies").Search("n", &meilisearch.SearchRequest{
- Filters: "title = \"Kung Fu Panda\"",
+ Filter: "title = \"Kung Fu Panda\"",
})
search_parameter_guide_matches_1: |-
- resp, err := client.Index("movies").Search("n", &meilisearch.SearchRequest{
- Filters: "title=\"Kung Fu Panda\"",
- AttributesToHighlight: []string{"overview"},
+ resp, err := client.Index("movies").Search("winter feast", &meilisearch.SearchRequest{
Matches: true,
})
settings_guide_synonyms_1: |-
@@ -267,11 +263,10 @@ settings_guide_stop_words_1: |-
client.Index("movies").UpdateStopWords(&stopWords)
settings_guide_ranking_rules_1: |-
rankingRules := []string{
- "typo",
"words",
+ "typo",
"proximity",
"attribute",
- "wordsPosition",
"exactness",
"asc(release_date)",
"desc(rank)",
@@ -321,7 +316,7 @@ search_guide_1: |-
})
search_guide_2: |-
resp, err := client.Index("movies").Search("Avengers", &meilisearch.SearchRequest{
- Filters: "release_date > \"795484800\"",
+ Filter: "release_date > \"795484800\"",
})
getting_started_add_documents_md: |-
```bash
@@ -358,6 +353,7 @@ getting_started_add_documents_md: |-
}
```
+
[About this SDK](https://github.com/meilisearch/meilisearch-go/)
getting_started_search_md: |-
```go
@@ -369,15 +365,15 @@ getting_started_search_md: |-
[About this SDK](https://github.com/meilisearch/meilisearch-go/)
faceted_search_update_settings_1: |-
- resp, err := client.Index("movies").UpdateAttributesForFaceting(&[]string{
+ resp, err := client.Index("movies").UpdateFilterableAttributes(&[]string{
"director",
"genres",
})
-faceted_search_facet_filters_1: |-
+faceted_search_filter_1: |-
resp, err := client.Index("movies").Search("thriller", &meilisearch.SearchRequest{
- FacetFilters: [][]string{
- []string{"genres:Horror", "genres:Mystery"},
- []string{"director:Jordan Peele"},
+ Filter: [][]string{
+ []string{"genres = Horror", "genres = Mystery"},
+ []string{"director = \"Jordan Peele\""},
},
})
faceted_search_facets_distribution_1: |-
@@ -386,18 +382,18 @@ faceted_search_facets_distribution_1: |-
"genres",
},
})
-faceted_search_walkthrough_attributes_for_faceting_1: |-
- resp, err := client.Index("movies").UpdateAttributesForFaceting(&[]string{
+faceted_search_walkthrough_filterable_attributes_1: |-
+ resp, err := client.Index("movies").UpdateFilterableAttributes(&[]string{
"director",
"producer",
"genres",
"production_companies",
})
-faceted_search_walkthrough_facet_filters_1: |-
+faceted_search_walkthrough_filter_1: |-
resp, err := client.Index("movies").Search("thriller", &meilisearch.SearchRequest{
- FacetFilters: [][]string{
- []string{"genres:Horror", "genres:Mystery"},
- []string{"director:Jordan Peele"},
+ Filter: [][]string{
+ []string{"genres = Horror", "genres = Mystery"},
+ []string{"director = \"Jordan Peele\""},
},
})
faceted_search_walkthrough_facets_distribution_1: |-
@@ -410,3 +406,5 @@ post_dump_1: |-
resp, err := client.CreateDump()
get_dump_status_1: |-
resp, err := client.GetDumpStatus("dump-uid")
+phrase_search_1: |-
+ resp, err := client.Index("movies").Search("\"african american\" horror", &meilisearch.SearchRequest{})
diff --git a/README.md b/README.md
index 52cd39c0..49018cf4 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
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.go b/index.go
index 68da8ef3..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)
@@ -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/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.go b/index_search.go
index 04c3f5d9..10030f24 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 != nil {
+ searchPostRequestParams["filter"] = request.Filter
}
if request.Offset != 0 {
searchPostRequestParams["offset"] = request.Offset
diff --git a/index_search_test.go b/index_search_test.go
index 7cdf1605..d699d12c 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,
@@ -283,12 +258,12 @@ 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
- facet []string
+ UID string
+ PrimaryKey string
+ client *Client
+ query string
+ request SearchRequest
+ filterableAttributes []string
}
tests := []struct {
name string
@@ -304,7 +279,7 @@ func TestIndex_SearchFacets(t *testing.T) {
request: SearchRequest{
FacetsDistribution: []string{"*"},
},
- facet: []string{"tag"},
+ filterableAttributes: []string{"tag"},
},
want: &SearchResponse{
Hits: []interface{}{
@@ -322,19 +297,11 @@ func TestIndex_SearchFacets(t *testing.T) {
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),
+ "Epic fantasy": float64(1),
+ "Tale": float64(1),
},
}),
- ExhaustiveFacetsCount: interface{}(true),
+ ExhaustiveFacetsCount: interface{}(false),
},
},
{
@@ -346,7 +313,7 @@ func TestIndex_SearchFacets(t *testing.T) {
request: SearchRequest{
FacetsDistribution: []string{"*"},
},
- facet: []string{"tag"},
+ filterableAttributes: []string{"tag"},
},
want: &SearchResponse{
Hits: []interface{}{
@@ -364,31 +331,122 @@ func TestIndex_SearchFacets(t *testing.T) {
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),
+ "Epic fantasy": float64(1),
+ "Tale": float64(1),
},
}),
- ExhaustiveFacetsCount: interface{}(true),
+ 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
+ PrimaryKey string
+ client *Client
+ query string
+ filterableAttributes []string
+ request SearchRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ want *SearchResponse
+ }{
+ {
+ name: "TestIndexBasicSearchWithFilter",
+ args: args{
+ UID: "indexUID",
+ client: defaultClient,
+ query: "and",
+ filterableAttributes: []string{
+ "tag",
+ },
+ request: SearchRequest{
+ Filter: "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: "TestIndexSearchWithFacetsDistributionWithTag",
+ name: "TestIndexSearchWithFilterInInt",
args: args{
UID: "indexUID",
client: defaultClient,
- query: "prince",
+ query: "and",
+ filterableAttributes: []string{
+ "year",
+ },
request: SearchRequest{
- FacetFilters: []string{"tag:Epic fantasy"},
+ Filter: "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: "TestIndexSearchWithFilterArray",
+ args: args{
+ UID: "indexUID",
+ client: defaultClient,
+ query: "and",
+ filterableAttributes: []string{
+ "year",
+ },
+ request: SearchRequest{
+ Filter: []string{
+ "year = 2005",
+ },
},
- facet: []string{"tag", "title"},
},
want: &SearchResponse{
Hits: []interface{}{
@@ -396,37 +454,183 @@ func TestIndex_SearchFacets(t *testing.T) {
"book_id": float64(4), "title": "Harry Potter and the Half-Blood Prince",
},
},
- NbHits: 1,
- Offset: 0,
- Limit: 20,
- ExhaustiveNbHits: false,
- FacetsDistribution: nil,
- ExhaustiveFacetsCount: interface{}(nil),
+ 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: "TestIndexSearchWithFacetsDistributionWithTagAndOneFacet",
+ name: "TestIndexSearchWithMultipleFilter",
args: args{
UID: "indexUID",
client: defaultClient,
query: "prince",
+ filterableAttributes: []string{
+ "tag",
+ "year",
+ },
+ request: SearchRequest{
+ Filter: "year > 1930",
+ },
+ },
+ 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,
+ },
+ },
+ {
+ 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{}{
+ "book_id": float64(742), "title": "The Great Gatsby",
+ },
+ },
+ NbHits: 3,
+ Offset: 0,
+ Limit: 20,
+ ExhaustiveNbHits: false,
+ },
+ },
+ {
+ name: "TestIndexSearchWithMultipleFilterAnd",
+ args: args{
+ UID: "indexUID",
+ client: defaultClient,
+ query: "",
+ filterableAttributes: []string{
+ "tag",
+ "year",
+ },
+ request: SearchRequest{
+ Filter: "year < 1930 AND tag = Tale",
+ },
+ },
+ 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{
- FacetFilters: []string{"tag:Epic fantasy"},
+ Filter: "year > 2000 OR tag = Tale",
},
- facet: []string{"tag"},
},
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: "TestIndexSearchWithAttributeToHighlight",
+ args: args{
+ UID: "indexUID",
+ client: defaultClient,
+ query: "prince",
+ filterableAttributes: []string{
+ "book_id",
+ },
+ request: SearchRequest{
+ AttributesToHighlight: []string{"*"},
+ Filter: "book_id > 10",
+ },
+ },
+ want: &SearchResponse{
+ Hits: []interface{}{
+ map[string]interface{}{
+ "book_id": float64(456), "title": "Le Petit Prince",
+ },
+ },
+ NbHits: 1,
+ Offset: 0,
+ Limit: 20,
+ ExhaustiveNbHits: false,
},
},
}
@@ -436,12 +640,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 +656,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.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/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 {
diff --git a/types.go b/types.go
index d6797ad8..826b1bb2 100644
--- a/types.go
+++ b/types.go
@@ -37,27 +37,27 @@ 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
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
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
@@ -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
@@ -110,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"`
}
//
@@ -135,10 +139,9 @@ type SearchRequest struct {
AttributesToCrop []string
CropLength int64
AttributesToHighlight []string
- Filters string
+ Filter interface{}
Matches bool
FacetsDistribution []string
- FacetFilters interface{}
PlaceholderSearch bool
}
diff --git a/types_easyjson.go b/types_easyjson.go
index 37a9e44b..dcf54ba9 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\":"
@@ -335,18 +333,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 +374,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 {
@@ -696,25 +694,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 +848,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 +858,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 +1177,14 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo7(in *jlexer.Lexer,
}
in.Delim(']')
}
- case "Filters":
- out.Filters = string(in.String())
+ case "Filter":
+ 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":
@@ -1206,14 +1210,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 +1290,15 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo7(out *jwriter.Write
}
}
{
- const prefix string = ",\"Filters\":"
+ const prefix string = ",\"Filter\":"
out.RawString(prefix)
- out.String(string(in.Filters))
+ 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\":"
@@ -1319,17 +1321,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)
@@ -1620,6 +1611,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()
}
@@ -1644,6 +1643,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('}')
}