|
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):
|
@@ -32,3 +33,45 @@ def test_multi_search_on_no_index(client):
|
32 | 33 | """Tests multi-search on a non existing index."""
|
33 | 34 | with pytest.raises(MeilisearchApiError):
|
34 | 35 | client.multi_search([{"indexUid": "indexDoesNotExist", "q": ""}])
|
| 36 | + |
| 37 | + |
| 38 | +def test_multi_search_with_no_value_in_federation(client, empty_index, index_with_documents): |
| 39 | + """Tests multi-search with federation, but no value""" |
| 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 |
| 50 | + |
| 51 | + |
| 52 | +def test_multi_search_with_offset_and_limit_in_federation(client, index_with_documents): |
| 53 | + """Tests multi-search with federation, with offset and limit value""" |
| 54 | + index_with_documents() |
| 55 | + response = client.multi_search([{"indexUid": INDEX_UID, "q": ""}], {"offset": 2, "limit": 2}) |
| 56 | + |
| 57 | + assert "results" not in response |
| 58 | + assert len(response["hits"]) == 2 |
| 59 | + assert "_federation" in response["hits"][0] |
| 60 | + assert response["limit"] == 2 |
| 61 | + assert response["offset"] == 2 |
| 62 | + |
| 63 | + |
| 64 | +def test_multi_search_with_federation_options(client, index_with_documents): |
| 65 | + """Tests multi-search with federation, with federation options""" |
| 66 | + index_with_documents() |
| 67 | + response = client.multi_search( |
| 68 | + [{"indexUid": INDEX_UID, "q": "", "federationOptions": {"weight": 0.99}}], {"limit": 2} |
| 69 | + ) |
| 70 | + |
| 71 | + assert "results" not in response |
| 72 | + assert isinstance(response["hits"], list) |
| 73 | + assert len(response["hits"]) == 2 |
| 74 | + assert response["hits"][0]["_federation"]["indexUid"] == INDEX_UID |
| 75 | + assert response["hits"][0]["_federation"]["weightedRankingScore"] >= 0.99 |
| 76 | + assert response["limit"] == 2 |
| 77 | + assert response["offset"] == 0 |
0 commit comments