Add support for distinct in multi search federation#782
Conversation
📝 WalkthroughWalkthroughAdded an optional Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
8d9a307 to
b53fe61
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/search.rs (1)
2406-2424: Strengthen this test to validate global distinct across merged queries.At Line 2411-Line 2415, the test uses a single query, so it doesn’t really prove deduplication across federated merged results. Consider adding two queries and asserting uniqueness of
kindin the merged hits.Proposed test hardening
#[meilisearch_test] async fn test_federated_multi_search_with_distinct( client: Client, index: Index, ) -> Result<(), Error> { setup_test_index(&client, &index).await?; - let search_query = SearchQuery::new(&index).build(); + let search_query_text = SearchQuery::new(&index).with_query("Lorem").build(); + let search_query_title = SearchQuery::new(&index).with_query("Harry").build(); let mut multi_search = client.multi_search(); - multi_search.with_search_query(search_query); + multi_search.with_search_query(search_query_text); + multi_search.with_search_query(search_query_title); let federated_multi_search = multi_search.with_federation(FederationOptions { distinct: Some("kind".to_string()), ..Default::default() }); let response = federated_multi_search.execute::<Document>().await.unwrap(); assert_eq!(response.hits.len(), 2); + let distinct_kinds = response + .hits + .iter() + .map(|hit| hit.result.kind.as_str()) + .collect::<std::collections::HashSet<_>>(); + assert_eq!(distinct_kinds.len(), response.hits.len()); Ok(()) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/search.rs` around lines 2406 - 2424, The test function test_federated_multi_search_with_distinct currently only adds one SearchQuery, so it doesn't validate global deduplication across merged federated results; update the test to add two different SearchQuery instances to the multi_search (e.g., call multi_search.with_search_query(...) twice or use multi_search.with_search_queries([...]) so the federation actually merges multiple queries), execute federated_multi_search.execute::<Document>(), and then assert that the merged response.hits contain unique values for the "kind" field (e.g., assert the number of hits equals the number of distinct kinds and that no duplicate kind values appear) to prove global distinct behavior when using FederationOptions { distinct: Some("kind".to_string()), ... }.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/search.rs`:
- Around line 2406-2424: The test function
test_federated_multi_search_with_distinct currently only adds one SearchQuery,
so it doesn't validate global deduplication across merged federated results;
update the test to add two different SearchQuery instances to the multi_search
(e.g., call multi_search.with_search_query(...) twice or use
multi_search.with_search_queries([...]) so the federation actually merges
multiple queries), execute federated_multi_search.execute::<Document>(), and
then assert that the merged response.hits contain unique values for the "kind"
field (e.g., assert the number of hits equals the number of distinct kinds and
that no duplicate kind values appear) to prove global distinct behavior when
using FederationOptions { distinct: Some("kind".to_string()), ... }.
Pull Request
Related issue
Fixes #777
What does this PR do?
distinctas a federation parameterPR checklist
Please check if your PR fulfills the following requirements:
AI was not used
Summary by CodeRabbit
Release Notes
New Features
Tests