Skip to content

Commit 007f40f

Browse files
committed
Updating test cases and docstring
1 parent b45f482 commit 007f40f

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

meilisearch/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def multi_search(self, queries: Sequence[Mapping[str, Any]], federation: Optiona
228228
List of dictionaries containing the specified indexes and their search queries
229229
https://www.meilisearch.com/docs/reference/api/search#search-in-an-index
230230
federation: (optional):
231-
List of dictionaries containing offset and limit
231+
Dictionary containing offset and limit
232232
https://www.meilisearch.com/docs/reference/api/multi_search
233233
234234
Returns

tests/client/test_client_multi_search_meilisearch.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from meilisearch.errors import MeilisearchApiError
4+
from tests.common import INDEX_UID
45

56

67
def test_basic_multi_search(client, empty_index):
@@ -34,26 +35,40 @@ def test_multi_search_on_no_index(client):
3435
client.multi_search([{"indexUid": "indexDoesNotExist", "q": ""}])
3536

3637

37-
def test_multi_search_with_no_value_in_federation(client, empty_index):
38+
def test_multi_search_with_no_value_in_federation(client, empty_index, index_with_documents):
3839
"""Tests multi-search with federation, but no value"""
39-
empty_index("indexA")
40-
response = client.multi_search([{"indexUid": "indexA", "q": ""}], {})
41-
42-
assert response["hits"][0]["_federation"]['indexUid'] == "indexA" if len(response["hits"]) >= 1 else isinstance(response, dict)
43-
40+
index_with_documents()
41+
empty_index("indexB")
42+
response = client.multi_search(
43+
[{"indexUid": INDEX_UID, "q": ""}, {"indexUid": "indexB", "q": ""}], {}
44+
)
45+
assert "results" not in response
46+
assert len(response["hits"]) > 0
47+
assert "_federation" in response["hits"][0]
48+
assert response["limit"] == 20
49+
assert response["offset"] == 0
4450

45-
def test_multi_search_with_offset_and_limit_in_federation(client, empty_index):
51+
def test_multi_search_with_offset_and_limit_in_federation(client, index_with_documents):
4652
"""Tests multi-search with federation, with offset and limit value"""
47-
empty_index("indexA")
48-
response = client.multi_search([{"indexUid": "indexA", "q": ""}], {"offset": 2, "limit": 2})
53+
index_with_documents()
54+
response = client.multi_search([{"indexUid": INDEX_UID, "q": ""}], {"offset": 2, "limit": 2})
4955

50-
assert len(response["hits"]) == 2 if response['hits'] else True
56+
assert "results" not in response
57+
assert len(response["hits"]) == 2
58+
assert "_federation" in response["hits"][0]
59+
assert response["limit"] == 2
60+
assert response["offset"] == 2
5161

5262

53-
def test_multi_search_with_federation_options(client, empty_index):
63+
def test_multi_search_with_federation_options(client, index_with_documents):
5464
"""Tests multi-search with federation, with federation options"""
55-
empty_index("indexA")
56-
response = client.multi_search([{"indexUid": "indexA", "q": "", "federationOptions": {"weight": 0.99}}], {"offset": 2, "limit": 2})
65+
index_with_documents()
66+
response = client.multi_search([{"indexUid": INDEX_UID, "q": "", "federationOptions": {"weight": 0.99}}], {"limit": 2})
5767

68+
assert "results" not in response
69+
assert response["hits"][0]["_federation"]["indexUid"] == INDEX_UID
5870
assert isinstance(response["hits"], list)
59-
assert response["hits"][0]["_federation"]["weightedRankingScore"] < 0.99 if len(response["hits"]) >= 1 else True
71+
assert response["hits"][0]["_federation"]["weightedRankingScore"] >= 0.99
72+
assert len(response["hits"]) == 2
73+
assert response["limit"] == 2
74+
assert response["offset"] == 0

0 commit comments

Comments
 (0)