Skip to content

Commit 9576ecf

Browse files
bors[bot]meili-botalallema
authored
Merge #418
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]>
2 parents 9c70e36 + f650227 commit 9576ecf

File tree

9 files changed

+1308
-349
lines changed

9 files changed

+1308
-349
lines changed

client.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type ClientInterface interface {
4242
CreateIndex(config *IndexConfig) (resp *TaskInfo, err error)
4343
DeleteIndex(uid string) (resp *TaskInfo, err error)
4444
CreateKey(request *Key) (resp *Key, err error)
45+
MultiSearch(queries *MultiSearchRequest) (*MultiSearchResponse, error)
4546
GetKey(identifier string) (resp *Key, err error)
4647
GetKeys(param *KeysQuery) (resp *KeysResults, err error)
4748
UpdateKey(keyOrUID string, request *Key) (resp *Key, err error)
@@ -252,6 +253,35 @@ func (c *Client) CreateDump() (resp *TaskInfo, err error) {
252253
return resp, nil
253254
}
254255

256+
func (c *Client) MultiSearch(queries *MultiSearchRequest) (*MultiSearchResponse, error) {
257+
resp := &MultiSearchResponse{}
258+
259+
searchPostQueries := make(map[string][]map[string]interface{}, 1)
260+
261+
for i := 0; i < len(queries.Queries); i++ {
262+
if queries.Queries[i].Limit == 0 {
263+
queries.Queries[i].Limit = DefaultLimit
264+
}
265+
searchPostQueries["queries"] = append(searchPostQueries["queries"], searchPostRequestParams(queries.Queries[i].Query, &queries.Queries[i]))
266+
}
267+
268+
req := internalRequest{
269+
endpoint: "/multi-search",
270+
method: http.MethodPost,
271+
contentType: contentTypeJSON,
272+
withRequest: searchPostQueries,
273+
withResponse: resp,
274+
acceptedStatusCodes: []int{http.StatusOK},
275+
functionName: "MultiSearch",
276+
}
277+
278+
if err := c.executeRequest(req); err != nil {
279+
return nil, err
280+
}
281+
282+
return resp, nil
283+
}
284+
255285
func (c *Client) GetTask(taskUID int64) (resp *Task, err error) {
256286
resp = &Task{}
257287
req := internalRequest{

client_test.go

Lines changed: 146 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package meilisearch
22

33
import (
44
"context"
5+
"reflect"
56
"strings"
6-
77
"sync"
88
"testing"
99
"time"
@@ -861,7 +861,7 @@ func TestClient_CancelTasks(t *testing.T) {
861861
want: "?statuses=succeeded",
862862
},
863863
{
864-
name: "TestCancelTasksWithIndexUidFilter",
864+
name: "TestCancelTasksWithIndexUIDFilter",
865865
args: args{
866866
UID: "indexUID",
867867
client: defaultClient,
@@ -872,7 +872,7 @@ func TestClient_CancelTasks(t *testing.T) {
872872
want: "?indexUids=0",
873873
},
874874
{
875-
name: "TestCancelTasksWithMultipleIndexUidsFilter",
875+
name: "TestCancelTasksWithMultipleIndexUIDsFilter",
876876
args: args{
877877
UID: "indexUID",
878878
client: defaultClient,
@@ -1006,7 +1006,7 @@ func TestClient_DeleteTasks(t *testing.T) {
10061006
want: "?uids=0%2C1",
10071007
},
10081008
{
1009-
name: "TestDeleteTasksWithIndexUidFilter",
1009+
name: "TestDeleteTasksWithIndexUIDFilter",
10101010
args: args{
10111011
UID: "indexUID",
10121012
client: defaultClient,
@@ -1017,7 +1017,7 @@ func TestClient_DeleteTasks(t *testing.T) {
10171017
want: "?indexUids=0",
10181018
},
10191019
{
1020-
name: "TestDeleteTasksWithMultipleIndexUidsFilter",
1020+
name: "TestDeleteTasksWithMultipleIndexUIDsFilter",
10211021
args: args{
10221022
UID: "indexUID",
10231023
client: defaultClient,
@@ -1569,3 +1569,144 @@ func TestClient_GenerateTenantToken(t *testing.T) {
15691569
})
15701570
}
15711571
}
1572+
1573+
func TestClient_MultiSearch(t *testing.T) {
1574+
type args struct {
1575+
client *Client
1576+
queries *MultiSearchRequest
1577+
UIDS []string
1578+
}
1579+
tests := []struct {
1580+
name string
1581+
args args
1582+
want *MultiSearchResponse
1583+
wantErr bool
1584+
}{
1585+
{
1586+
name: "TestClientMultiSearchOneIndex",
1587+
args: args{
1588+
client: defaultClient,
1589+
queries: &MultiSearchRequest{
1590+
[]SearchRequest{
1591+
{
1592+
IndexUID: "TestClientMultiSearchOneIndex",
1593+
Query: "wonder",
1594+
},
1595+
},
1596+
},
1597+
UIDS: []string{"TestClientMultiSearchOneIndex"},
1598+
},
1599+
want: &MultiSearchResponse{
1600+
Results: []SearchResponse{
1601+
{
1602+
Hits: []interface{}{
1603+
map[string]interface{}{
1604+
"book_id": float64(1),
1605+
"title": "Alice In Wonderland",
1606+
},
1607+
},
1608+
EstimatedTotalHits: 1,
1609+
Offset: 0,
1610+
Limit: 20,
1611+
Query: "wonder",
1612+
IndexUID: "TestClientMultiSearchOneIndex",
1613+
},
1614+
},
1615+
},
1616+
},
1617+
{
1618+
name: "TestClientMultiSearchOnTwoIndexes",
1619+
args: args{
1620+
client: defaultClient,
1621+
queries: &MultiSearchRequest{
1622+
[]SearchRequest{
1623+
{
1624+
IndexUID: "TestClientMultiSearchOnTwoIndexes1",
1625+
Query: "wonder",
1626+
},
1627+
{
1628+
IndexUID: "TestClientMultiSearchOnTwoIndexes2",
1629+
Query: "prince",
1630+
},
1631+
},
1632+
},
1633+
UIDS: []string{"TestClientMultiSearchOnTwoIndexes1", "TestClientMultiSearchOnTwoIndexes2"},
1634+
},
1635+
want: &MultiSearchResponse{
1636+
Results: []SearchResponse{
1637+
{
1638+
Hits: []interface{}{
1639+
map[string]interface{}{
1640+
"book_id": float64(1),
1641+
"title": "Alice In Wonderland",
1642+
},
1643+
},
1644+
EstimatedTotalHits: 1,
1645+
Offset: 0,
1646+
Limit: 20,
1647+
Query: "wonder",
1648+
IndexUID: "TestClientMultiSearchOnTwoIndexes1",
1649+
},
1650+
{
1651+
Hits: []interface{}{
1652+
map[string]interface{}{
1653+
"book_id": float64(456),
1654+
"title": "Le Petit Prince",
1655+
},
1656+
map[string]interface{}{
1657+
"book_id": float64(4),
1658+
"title": "Harry Potter and the Half-Blood Prince",
1659+
},
1660+
},
1661+
EstimatedTotalHits: 2,
1662+
Offset: 0,
1663+
Limit: 20,
1664+
Query: "prince",
1665+
IndexUID: "TestClientMultiSearchOnTwoIndexes2",
1666+
},
1667+
},
1668+
},
1669+
},
1670+
{
1671+
name: "TestClientMultiSearchNoIndex",
1672+
args: args{
1673+
client: defaultClient,
1674+
queries: &MultiSearchRequest{
1675+
[]SearchRequest{
1676+
{
1677+
Query: "",
1678+
},
1679+
},
1680+
},
1681+
UIDS: []string{"TestClientMultiSearchNoIndex"},
1682+
},
1683+
wantErr: true,
1684+
},
1685+
}
1686+
for _, tt := range tests {
1687+
t.Run(tt.name, func(t *testing.T) {
1688+
for _, UID := range tt.args.UIDS {
1689+
SetUpBasicIndex(UID)
1690+
}
1691+
c := tt.args.client
1692+
t.Cleanup(cleanup(c))
1693+
1694+
got, err := c.MultiSearch(tt.args.queries)
1695+
1696+
if tt.wantErr {
1697+
require.Error(t, err)
1698+
} else {
1699+
for i := 0; i < len(tt.want.Results); i++ {
1700+
if !reflect.DeepEqual(got.Results[i].Hits, tt.want.Results[i].Hits) {
1701+
t.Errorf("Client.MultiSearch() = %v, want %v", got.Results[i].Hits, tt.want.Results[i].Hits)
1702+
}
1703+
require.Equal(t, tt.want.Results[i].EstimatedTotalHits, got.Results[i].EstimatedTotalHits)
1704+
require.Equal(t, tt.want.Results[i].Offset, got.Results[i].Offset)
1705+
require.Equal(t, tt.want.Results[i].Limit, got.Results[i].Limit)
1706+
require.Equal(t, tt.want.Results[i].Query, got.Results[i].Query)
1707+
require.Equal(t, tt.want.Results[i].IndexUID, got.Results[i].IndexUID)
1708+
}
1709+
}
1710+
})
1711+
}
1712+
}

index.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ type IndexInterface interface {
2828

2929
AddDocuments(documentsPtr interface{}, primaryKey ...string) (resp *TaskInfo, err error)
3030
AddDocumentsInBatches(documentsPtr interface{}, batchSize int, primaryKey ...string) (resp []TaskInfo, err error)
31-
AddDocumentsCsv(documents []byte, primaryKey ...string) (resp *TaskInfo, err error)
32-
AddDocumentsCsvInBatches(documents []byte, batchSize int, primaryKey ...string) (resp []TaskInfo, err error)
31+
AddDocumentsCsv(documents []byte, options *CsvDocumentsQuery) (resp *TaskInfo, err error)
32+
AddDocumentsCsvInBatches(documents []byte, batchSize int, options *CsvDocumentsQuery) (resp []TaskInfo, err error)
3333
AddDocumentsNdjson(documents []byte, primaryKey ...string) (resp *TaskInfo, err error)
3434
AddDocumentsNdjsonInBatches(documents []byte, batchSize int, primaryKey ...string) (resp []TaskInfo, err error)
3535
UpdateDocuments(documentsPtr interface{}, primaryKey ...string) (resp *TaskInfo, err error)
3636
UpdateDocumentsInBatches(documentsPtr interface{}, batchSize int, primaryKey ...string) (resp []TaskInfo, err error)
37-
UpdateDocumentsCsv(documents []byte, primaryKey ...string) (resp *TaskInfo, err error)
38-
UpdateDocumentsCsvInBatches(documents []byte, batchsize int, primaryKey ...string) (resp []TaskInfo, err error)
37+
UpdateDocumentsCsv(documents []byte, options *CsvDocumentsQuery) (resp *TaskInfo, err error)
38+
UpdateDocumentsCsvInBatches(documents []byte, batchsize int, options *CsvDocumentsQuery) (resp []TaskInfo, err error)
3939
UpdateDocumentsNdjson(documents []byte, primaryKey ...string) (resp *TaskInfo, err error)
4040
UpdateDocumentsNdjsonInBatches(documents []byte, batchsize int, primaryKey ...string) (resp []TaskInfo, err error)
4141
GetDocument(uid string, request *DocumentQuery, documentPtr interface{}) error

0 commit comments

Comments
 (0)