Skip to content

Commit

Permalink
Merge #418
Browse files Browse the repository at this point in the history
418: Changes related to the next Meilisearch release (v1.1.0) r=bidoubiwa a=meili-bot

Related to this issue: meilisearch/integration-guides#251

This PR:
- gathers the changes related to the next Meilisearch release (v1.1.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases).
- might eventually contain test failures until the Meilisearch v1.1.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.1.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._

Done:
- #422 
- #423
- #424

Co-authored-by: meili-bot <[email protected]>
Co-authored-by: alallema <[email protected]>
Co-authored-by: Amélie <[email protected]>
  • Loading branch information
4 people authored Apr 3, 2023
2 parents 9c70e36 + f650227 commit 9576ecf
Show file tree
Hide file tree
Showing 9 changed files with 1,308 additions and 349 deletions.
30 changes: 30 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ClientInterface interface {
CreateIndex(config *IndexConfig) (resp *TaskInfo, err error)
DeleteIndex(uid string) (resp *TaskInfo, err error)
CreateKey(request *Key) (resp *Key, err error)
MultiSearch(queries *MultiSearchRequest) (*MultiSearchResponse, error)
GetKey(identifier string) (resp *Key, err error)
GetKeys(param *KeysQuery) (resp *KeysResults, err error)
UpdateKey(keyOrUID string, request *Key) (resp *Key, err error)
Expand Down Expand Up @@ -252,6 +253,35 @@ func (c *Client) CreateDump() (resp *TaskInfo, err error) {
return resp, nil
}

func (c *Client) MultiSearch(queries *MultiSearchRequest) (*MultiSearchResponse, error) {
resp := &MultiSearchResponse{}

searchPostQueries := make(map[string][]map[string]interface{}, 1)

for i := 0; i < len(queries.Queries); i++ {
if queries.Queries[i].Limit == 0 {
queries.Queries[i].Limit = DefaultLimit
}
searchPostQueries["queries"] = append(searchPostQueries["queries"], searchPostRequestParams(queries.Queries[i].Query, &queries.Queries[i]))
}

req := internalRequest{
endpoint: "/multi-search",
method: http.MethodPost,
contentType: contentTypeJSON,
withRequest: searchPostQueries,
withResponse: resp,
acceptedStatusCodes: []int{http.StatusOK},
functionName: "MultiSearch",
}

if err := c.executeRequest(req); err != nil {
return nil, err
}

return resp, nil
}

func (c *Client) GetTask(taskUID int64) (resp *Task, err error) {
resp = &Task{}
req := internalRequest{
Expand Down
151 changes: 146 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package meilisearch

import (
"context"
"reflect"
"strings"

"sync"
"testing"
"time"
Expand Down Expand Up @@ -861,7 +861,7 @@ func TestClient_CancelTasks(t *testing.T) {
want: "?statuses=succeeded",
},
{
name: "TestCancelTasksWithIndexUidFilter",
name: "TestCancelTasksWithIndexUIDFilter",
args: args{
UID: "indexUID",
client: defaultClient,
Expand All @@ -872,7 +872,7 @@ func TestClient_CancelTasks(t *testing.T) {
want: "?indexUids=0",
},
{
name: "TestCancelTasksWithMultipleIndexUidsFilter",
name: "TestCancelTasksWithMultipleIndexUIDsFilter",
args: args{
UID: "indexUID",
client: defaultClient,
Expand Down Expand Up @@ -1006,7 +1006,7 @@ func TestClient_DeleteTasks(t *testing.T) {
want: "?uids=0%2C1",
},
{
name: "TestDeleteTasksWithIndexUidFilter",
name: "TestDeleteTasksWithIndexUIDFilter",
args: args{
UID: "indexUID",
client: defaultClient,
Expand All @@ -1017,7 +1017,7 @@ func TestClient_DeleteTasks(t *testing.T) {
want: "?indexUids=0",
},
{
name: "TestDeleteTasksWithMultipleIndexUidsFilter",
name: "TestDeleteTasksWithMultipleIndexUIDsFilter",
args: args{
UID: "indexUID",
client: defaultClient,
Expand Down Expand Up @@ -1569,3 +1569,144 @@ func TestClient_GenerateTenantToken(t *testing.T) {
})
}
}

func TestClient_MultiSearch(t *testing.T) {
type args struct {
client *Client
queries *MultiSearchRequest
UIDS []string
}
tests := []struct {
name string
args args
want *MultiSearchResponse
wantErr bool
}{
{
name: "TestClientMultiSearchOneIndex",
args: args{
client: defaultClient,
queries: &MultiSearchRequest{
[]SearchRequest{
{
IndexUID: "TestClientMultiSearchOneIndex",
Query: "wonder",
},
},
},
UIDS: []string{"TestClientMultiSearchOneIndex"},
},
want: &MultiSearchResponse{
Results: []SearchResponse{
{
Hits: []interface{}{
map[string]interface{}{
"book_id": float64(1),
"title": "Alice In Wonderland",
},
},
EstimatedTotalHits: 1,
Offset: 0,
Limit: 20,
Query: "wonder",
IndexUID: "TestClientMultiSearchOneIndex",
},
},
},
},
{
name: "TestClientMultiSearchOnTwoIndexes",
args: args{
client: defaultClient,
queries: &MultiSearchRequest{
[]SearchRequest{
{
IndexUID: "TestClientMultiSearchOnTwoIndexes1",
Query: "wonder",
},
{
IndexUID: "TestClientMultiSearchOnTwoIndexes2",
Query: "prince",
},
},
},
UIDS: []string{"TestClientMultiSearchOnTwoIndexes1", "TestClientMultiSearchOnTwoIndexes2"},
},
want: &MultiSearchResponse{
Results: []SearchResponse{
{
Hits: []interface{}{
map[string]interface{}{
"book_id": float64(1),
"title": "Alice In Wonderland",
},
},
EstimatedTotalHits: 1,
Offset: 0,
Limit: 20,
Query: "wonder",
IndexUID: "TestClientMultiSearchOnTwoIndexes1",
},
{
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",
},
},
EstimatedTotalHits: 2,
Offset: 0,
Limit: 20,
Query: "prince",
IndexUID: "TestClientMultiSearchOnTwoIndexes2",
},
},
},
},
{
name: "TestClientMultiSearchNoIndex",
args: args{
client: defaultClient,
queries: &MultiSearchRequest{
[]SearchRequest{
{
Query: "",
},
},
},
UIDS: []string{"TestClientMultiSearchNoIndex"},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, UID := range tt.args.UIDS {
SetUpBasicIndex(UID)
}
c := tt.args.client
t.Cleanup(cleanup(c))

got, err := c.MultiSearch(tt.args.queries)

if tt.wantErr {
require.Error(t, err)
} else {
for i := 0; i < len(tt.want.Results); i++ {
if !reflect.DeepEqual(got.Results[i].Hits, tt.want.Results[i].Hits) {
t.Errorf("Client.MultiSearch() = %v, want %v", got.Results[i].Hits, tt.want.Results[i].Hits)
}
require.Equal(t, tt.want.Results[i].EstimatedTotalHits, got.Results[i].EstimatedTotalHits)
require.Equal(t, tt.want.Results[i].Offset, got.Results[i].Offset)
require.Equal(t, tt.want.Results[i].Limit, got.Results[i].Limit)
require.Equal(t, tt.want.Results[i].Query, got.Results[i].Query)
require.Equal(t, tt.want.Results[i].IndexUID, got.Results[i].IndexUID)
}
}
})
}
}
8 changes: 4 additions & 4 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ type IndexInterface interface {

AddDocuments(documentsPtr interface{}, primaryKey ...string) (resp *TaskInfo, err error)
AddDocumentsInBatches(documentsPtr interface{}, batchSize int, primaryKey ...string) (resp []TaskInfo, err error)
AddDocumentsCsv(documents []byte, primaryKey ...string) (resp *TaskInfo, err error)
AddDocumentsCsvInBatches(documents []byte, batchSize int, primaryKey ...string) (resp []TaskInfo, err error)
AddDocumentsCsv(documents []byte, options *CsvDocumentsQuery) (resp *TaskInfo, err error)
AddDocumentsCsvInBatches(documents []byte, batchSize int, options *CsvDocumentsQuery) (resp []TaskInfo, err error)
AddDocumentsNdjson(documents []byte, primaryKey ...string) (resp *TaskInfo, err error)
AddDocumentsNdjsonInBatches(documents []byte, batchSize int, primaryKey ...string) (resp []TaskInfo, err error)
UpdateDocuments(documentsPtr interface{}, primaryKey ...string) (resp *TaskInfo, err error)
UpdateDocumentsInBatches(documentsPtr interface{}, batchSize int, primaryKey ...string) (resp []TaskInfo, err error)
UpdateDocumentsCsv(documents []byte, primaryKey ...string) (resp *TaskInfo, err error)
UpdateDocumentsCsvInBatches(documents []byte, batchsize int, primaryKey ...string) (resp []TaskInfo, err error)
UpdateDocumentsCsv(documents []byte, options *CsvDocumentsQuery) (resp *TaskInfo, err error)
UpdateDocumentsCsvInBatches(documents []byte, batchsize int, options *CsvDocumentsQuery) (resp []TaskInfo, err error)
UpdateDocumentsNdjson(documents []byte, primaryKey ...string) (resp *TaskInfo, err error)
UpdateDocumentsNdjsonInBatches(documents []byte, batchsize int, primaryKey ...string) (resp []TaskInfo, err error)
GetDocument(uid string, request *DocumentQuery, documentPtr interface{}) error
Expand Down
Loading

0 comments on commit 9576ecf

Please sign in to comment.