|
1 | 1 | import pytest
|
2 | 2 |
|
3 | 3 | from meilisearch.errors import MeilisearchApiError
|
| 4 | +from tests.common import INDEX_UID |
4 | 5 |
|
5 | 6 |
|
6 | 7 | def test_basic_multi_search(client, empty_index):
|
@@ -34,26 +35,40 @@ def test_multi_search_on_no_index(client):
|
34 | 35 | client.multi_search([{"indexUid": "indexDoesNotExist", "q": ""}])
|
35 | 36 |
|
36 | 37 |
|
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): |
38 | 39 | """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 |
44 | 50 |
|
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): |
46 | 52 | """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}) |
49 | 55 |
|
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 |
51 | 61 |
|
52 | 62 |
|
53 |
| -def test_multi_search_with_federation_options(client, empty_index): |
| 63 | +def test_multi_search_with_federation_options(client, index_with_documents): |
54 | 64 | """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}) |
57 | 67 |
|
| 68 | + assert "results" not in response |
| 69 | + assert response["hits"][0]["_federation"]["indexUid"] == INDEX_UID |
58 | 70 | 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