|
9 | 9 | from meilisearch_python_sdk import AsyncClient |
10 | 10 | from meilisearch_python_sdk._task import async_wait_for_task |
11 | 11 | from meilisearch_python_sdk.errors import MeilisearchApiError, MeilisearchError |
12 | | -from meilisearch_python_sdk.models.search import Federation, Hybrid, SearchParams |
| 12 | +from meilisearch_python_sdk.models.search import ( |
| 13 | + Federation, |
| 14 | + FederationMerged, |
| 15 | + Hybrid, |
| 16 | + MergeFacets, |
| 17 | + SearchParams, |
| 18 | +) |
13 | 19 |
|
14 | 20 |
|
15 | 21 | async def test_basic_search(async_index_with_documents): |
@@ -395,6 +401,55 @@ async def test_multi_search_federated(async_client, async_index_with_documents, |
395 | 401 | assert "_federation" in response.hits[0] |
396 | 402 |
|
397 | 403 |
|
| 404 | +async def test_multi_search_federated_facets_by_index( |
| 405 | + async_client, async_index_with_documents, async_empty_index |
| 406 | +): |
| 407 | + index1 = await async_index_with_documents() |
| 408 | + task = await index1.update_filterable_attributes(["title"]) |
| 409 | + await async_client.wait_for_task(task.task_uid) |
| 410 | + index2 = await async_empty_index() |
| 411 | + federation = Federation() |
| 412 | + federation.facets_by_index = {index1.uid: ["title"]} |
| 413 | + response = await async_client.multi_search( |
| 414 | + [ |
| 415 | + SearchParams(index_uid=index1.uid, query="How to Train Your Dragon"), |
| 416 | + SearchParams(index_uid=index2.uid, query=""), |
| 417 | + ], |
| 418 | + federation=federation, |
| 419 | + ) |
| 420 | + |
| 421 | + assert response.hits[0]["id"] == "166428" |
| 422 | + assert "_formatted" not in response.hits[0] |
| 423 | + assert "_federation" in response.hits[0] |
| 424 | + assert response.facets_by_index is not None |
| 425 | + |
| 426 | + |
| 427 | +async def test_multi_search_federated_merge_facets( |
| 428 | + async_client, |
| 429 | + async_index_with_documents, |
| 430 | + async_empty_index, |
| 431 | +): |
| 432 | + index1 = await async_index_with_documents() |
| 433 | + task = await index1.update_filterable_attributes(["title"]) |
| 434 | + await async_client.wait_for_task(task.task_uid) |
| 435 | + index2 = await async_empty_index() |
| 436 | + federation = FederationMerged(merge_facets=MergeFacets(max_values_per_facet=10)) |
| 437 | + federation.facets_by_index = {index1.uid: ["title"]} |
| 438 | + response = await async_client.multi_search( |
| 439 | + [ |
| 440 | + SearchParams(index_uid=index1.uid, query="How to Train Your Dragon"), |
| 441 | + SearchParams(index_uid=index2.uid, query=""), |
| 442 | + ], |
| 443 | + federation=federation, |
| 444 | + ) |
| 445 | + |
| 446 | + assert response.hits[0]["id"] == "166428" |
| 447 | + assert "_formatted" not in response.hits[0] |
| 448 | + assert "_federation" in response.hits[0] |
| 449 | + assert response.facets_by_index is None |
| 450 | + assert response.facet_distribution is not None |
| 451 | + |
| 452 | + |
398 | 453 | async def test_multi_search_locales(async_client, async_index_with_documents, async_empty_index): |
399 | 454 | index1 = await async_index_with_documents() |
400 | 455 | index2 = await async_empty_index() |
|
0 commit comments