Skip to content

Commit

Permalink
Updating test cases and docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
MuddyHope committed Aug 29, 2024
1 parent b45f482 commit 007f40f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion meilisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def multi_search(self, queries: Sequence[Mapping[str, Any]], federation: Optiona
List of dictionaries containing the specified indexes and their search queries
https://www.meilisearch.com/docs/reference/api/search#search-in-an-index
federation: (optional):
List of dictionaries containing offset and limit
Dictionary containing offset and limit
https://www.meilisearch.com/docs/reference/api/multi_search
Returns
Expand Down
43 changes: 29 additions & 14 deletions tests/client/test_client_multi_search_meilisearch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from meilisearch.errors import MeilisearchApiError
from tests.common import INDEX_UID


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


def test_multi_search_with_no_value_in_federation(client, empty_index):
def test_multi_search_with_no_value_in_federation(client, empty_index, index_with_documents):
"""Tests multi-search with federation, but no value"""
empty_index("indexA")
response = client.multi_search([{"indexUid": "indexA", "q": ""}], {})

assert response["hits"][0]["_federation"]['indexUid'] == "indexA" if len(response["hits"]) >= 1 else isinstance(response, dict)

index_with_documents()
empty_index("indexB")
response = client.multi_search(
[{"indexUid": INDEX_UID, "q": ""}, {"indexUid": "indexB", "q": ""}], {}
)
assert "results" not in response
assert len(response["hits"]) > 0
assert "_federation" in response["hits"][0]
assert response["limit"] == 20
assert response["offset"] == 0

def test_multi_search_with_offset_and_limit_in_federation(client, empty_index):
def test_multi_search_with_offset_and_limit_in_federation(client, index_with_documents):
"""Tests multi-search with federation, with offset and limit value"""
empty_index("indexA")
response = client.multi_search([{"indexUid": "indexA", "q": ""}], {"offset": 2, "limit": 2})
index_with_documents()
response = client.multi_search([{"indexUid": INDEX_UID, "q": ""}], {"offset": 2, "limit": 2})

assert len(response["hits"]) == 2 if response['hits'] else True
assert "results" not in response
assert len(response["hits"]) == 2
assert "_federation" in response["hits"][0]
assert response["limit"] == 2
assert response["offset"] == 2


def test_multi_search_with_federation_options(client, empty_index):
def test_multi_search_with_federation_options(client, index_with_documents):
"""Tests multi-search with federation, with federation options"""
empty_index("indexA")
response = client.multi_search([{"indexUid": "indexA", "q": "", "federationOptions": {"weight": 0.99}}], {"offset": 2, "limit": 2})
index_with_documents()
response = client.multi_search([{"indexUid": INDEX_UID, "q": "", "federationOptions": {"weight": 0.99}}], {"limit": 2})

assert "results" not in response
assert response["hits"][0]["_federation"]["indexUid"] == INDEX_UID
assert isinstance(response["hits"], list)
assert response["hits"][0]["_federation"]["weightedRankingScore"] < 0.99 if len(response["hits"]) >= 1 else True
assert response["hits"][0]["_federation"]["weightedRankingScore"] >= 0.99
assert len(response["hits"]) == 2
assert response["limit"] == 2
assert response["offset"] == 0

0 comments on commit 007f40f

Please sign in to comment.