@@ -2,8 +2,8 @@ package meilisearch
2
2
3
3
import (
4
4
"context"
5
+ "reflect"
5
6
"strings"
6
-
7
7
"sync"
8
8
"testing"
9
9
"time"
@@ -861,7 +861,7 @@ func TestClient_CancelTasks(t *testing.T) {
861
861
want : "?statuses=succeeded" ,
862
862
},
863
863
{
864
- name : "TestCancelTasksWithIndexUidFilter " ,
864
+ name : "TestCancelTasksWithIndexUIDFilter " ,
865
865
args : args {
866
866
UID : "indexUID" ,
867
867
client : defaultClient ,
@@ -872,7 +872,7 @@ func TestClient_CancelTasks(t *testing.T) {
872
872
want : "?indexUids=0" ,
873
873
},
874
874
{
875
- name : "TestCancelTasksWithMultipleIndexUidsFilter " ,
875
+ name : "TestCancelTasksWithMultipleIndexUIDsFilter " ,
876
876
args : args {
877
877
UID : "indexUID" ,
878
878
client : defaultClient ,
@@ -1006,7 +1006,7 @@ func TestClient_DeleteTasks(t *testing.T) {
1006
1006
want : "?uids=0%2C1" ,
1007
1007
},
1008
1008
{
1009
- name : "TestDeleteTasksWithIndexUidFilter " ,
1009
+ name : "TestDeleteTasksWithIndexUIDFilter " ,
1010
1010
args : args {
1011
1011
UID : "indexUID" ,
1012
1012
client : defaultClient ,
@@ -1017,7 +1017,7 @@ func TestClient_DeleteTasks(t *testing.T) {
1017
1017
want : "?indexUids=0" ,
1018
1018
},
1019
1019
{
1020
- name : "TestDeleteTasksWithMultipleIndexUidsFilter " ,
1020
+ name : "TestDeleteTasksWithMultipleIndexUIDsFilter " ,
1021
1021
args : args {
1022
1022
UID : "indexUID" ,
1023
1023
client : defaultClient ,
@@ -1569,3 +1569,144 @@ func TestClient_GenerateTenantToken(t *testing.T) {
1569
1569
})
1570
1570
}
1571
1571
}
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
+ }
0 commit comments