Skip to content

Implement federated multi search #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 11, 2025
Merged

Implement federated multi search #681

merged 18 commits into from
Jul 11, 2025

Conversation

Mubelotix
Copy link
Collaborator

@Mubelotix Mubelotix commented Jul 11, 2025

Pull Request

Rework on top of #625

Related issue

Fixes #609

What does this PR do?

This PR adds types and methods to use the federated multi search API. There are multiple ways to add this to this library, depending on how strictly one wants to type everything. I decided to:

  • Add a new FederatedMultiSearchResponse, which also required a new Client::execute_federated_multi_search_query. The response of federated searches is just very different from normal multi searches, and I didn't think having an enum returned by execute_multi_search_query was a particularly nice design (and it would have been a breaking change).
  • Add a federation: Option<FederationHitInfo> to each SearchResult (which is None for non-federated searches). I don't think it's worth to have a dedicated FederatedSearchResult.
  • Add MultiSearchQuery::with_federation which returns a new FederatedMultiSearchQuery. One could also change MultiSearchQuery to be able to represent federated queries, but I had a slight preference for my solution.

Summary by CodeRabbit

  • New Features

    • Introduced federated multi-search functionality, allowing queries across multiple indexes with support for query weighting and merged results.
    • Added new methods and options to customize federated search behavior, including per-query weighting and federation parameters.
    • Enhanced response structure to include merged hits, pagination, facet data, and remote error details.
  • Bug Fixes

    • Improved handling of multiple index parameters in test macros, ensuring each index is managed independently during tests.
  • Documentation

    • Updated documentation to clarify usage of federated multi-search and support for multiple index parameters in test macros.

@Mubelotix Mubelotix changed the base branch from main to dev July 11, 2025 15:29
@meilisearch meilisearch deleted a comment from coderabbitai bot Jul 11, 2025
@meilisearch meilisearch deleted a comment from coderabbitai bot Jul 11, 2025
@meilisearch meilisearch deleted a comment from coderabbitai bot Jul 11, 2025
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Federated multi-search support is introduced, allowing queries across multiple indexes with merged results. New types and methods for federated queries and responses are added, including per-query weighting and federation options. The test macro is enhanced to handle multiple Index parameters, and documentation is updated to clarify usage and federated search concepts.

Changes

File(s) Change Summary
meilisearch-test-macro/src/lib.rs, meilisearch-test-macro/README.md Macro and documentation updated to support and clarify multiple Index parameters per test.
src/client.rs Added execute_federated_multi_search_query method and extended docs for federated multi-search usage.
src/search.rs Added federated multi-search types, options, response structs, and related methods. Updated tests and serialization.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Client
    participant MeilisearchServer

    User->>Client: Construct FederatedMultiSearchQuery
    User->>Client: Call execute_federated_multi_search_query()
    Client->>MeilisearchServer: POST /multi-search with federation options
    MeilisearchServer-->>Client: FederatedMultiSearchResponse
    Client-->>User: Return merged results, facets, and errors
Loading

Assessment against linked issues

Objective Addressed Explanation
Add a new search parameter named federation to the multiSearch method (#609)
Add the capability to have a new search parameter to the search query named federationOptions (#609)
Add tests (#609)

Possibly related PRs

Suggested labels

enhancement

Poem

In burrows deep, a search anew,
Across all fields, results accrue!
With federated hops from here to there,
Weighted queries fill the air.
Now rabbits find, with bounding glee,
All answers merged—federally!
🐇✨


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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Mubelotix
Copy link
Collaborator Author

@CodeRabbit review

Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

codecov bot commented Jul 11, 2025

Codecov Report

Attention: Patch coverage is 94.35897% with 11 lines in your changes missing coverage. Please review.

Project coverage is 93.78%. Comparing base (2a3c015) to head (1101fa0).
Report is 25 commits behind head on dev.

Files with missing lines Patch % Lines
src/search.rs 92.81% 0 Missing and 11 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #681      +/-   ##
==========================================
- Coverage   93.81%   93.78%   -0.03%     
==========================================
  Files          19       19              
  Lines        7792     7905     +113     
  Branches     7792     7905     +113     
==========================================
+ Hits         7310     7414     +104     
  Misses        258      258              
- Partials      224      233       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
meilisearch-test-macro/src/lib.rs (1)

167-167: Minor: Unnecessary clone() on args.

The clone() call on args might be unnecessary since Expr values are typically cheap to clone or could be passed by reference.

Consider removing the clone if not needed:

-            let result = #inner_ident(#(#args.clone()),*).await;
+            let result = #inner_ident(#(#args),*).await;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d0d3ee and 94e9140.

📒 Files selected for processing (4)
  • meilisearch-test-macro/README.md (1 hunks)
  • meilisearch-test-macro/src/lib.rs (1 hunks)
  • src/client.rs (2 hunks)
  • src/search.rs (9 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: LukasKalbertodt
PR: meilisearch/meilisearch-rust#625
File: src/search.rs:368-370
Timestamp: 2025-06-12T13:28:23.700Z
Learning: In the Meilisearch Rust client, `SearchQuery` serializes its per-query federation settings under the key `federationOptions`; only the top-level multi-search parameter is named `federation`.
Learnt from: LukasKalbertodt
PR: meilisearch/meilisearch-rust#625
File: src/search.rs:758-759
Timestamp: 2025-06-12T12:31:13.079Z
Learning: In Meilisearch federated multi-search responses, `_federation.weightedRankingScore` is always returned, independent of the `showRankingScore` query parameter, so the `weighted_ranking_score` field in `FederationHitInfo` should remain a non-optional `f32`.
src/client.rs (2)
Learnt from: LukasKalbertodt
PR: meilisearch/meilisearch-rust#625
File: src/search.rs:368-370
Timestamp: 2025-06-12T13:28:23.700Z
Learning: In the Meilisearch Rust client, `SearchQuery` serializes its per-query federation settings under the key `federationOptions`; only the top-level multi-search parameter is named `federation`.
Learnt from: LukasKalbertodt
PR: meilisearch/meilisearch-rust#625
File: src/search.rs:758-759
Timestamp: 2025-06-12T12:31:13.079Z
Learning: In Meilisearch federated multi-search responses, `_federation.weightedRankingScore` is always returned, independent of the `showRankingScore` query parameter, so the `weighted_ranking_score` field in `FederationHitInfo` should remain a non-optional `f32`.
src/search.rs (2)
Learnt from: LukasKalbertodt
PR: meilisearch/meilisearch-rust#625
File: src/search.rs:368-370
Timestamp: 2025-06-12T13:28:23.700Z
Learning: In the Meilisearch Rust client, `SearchQuery` serializes its per-query federation settings under the key `federationOptions`; only the top-level multi-search parameter is named `federation`.
Learnt from: LukasKalbertodt
PR: meilisearch/meilisearch-rust#625
File: src/search.rs:758-759
Timestamp: 2025-06-12T12:31:13.079Z
Learning: In Meilisearch federated multi-search responses, `_federation.weightedRankingScore` is always returned, independent of the `showRankingScore` query parameter, so the `weighted_ranking_score` field in `FederationHitInfo` should remain a non-optional `f32`.
🧬 Code Graph Analysis (2)
src/client.rs (1)
src/request.rs (1)
  • body (49-56)
src/search.rs (7)
src/indexes.rs (28)
  • client (185-187)
  • client (231-233)
  • client (319-321)
  • client (375-377)
  • client (427-429)
  • client (472-474)
  • client (521-524)
  • client (555-557)
  • client (633-635)
  • client (699-701)
  • client (969-971)
  • client (1037-1039)
  • client (1088-1090)
  • client (1132-1134)
  • client (1185-1187)
  • client (1244-1246)
  • execute (1819-1831)
  • execute (2036-2038)
  • index (2106-2106)
  • index (2123-2124)
  • index (2161-2161)
  • index (2187-2187)
  • index (2215-2215)
  • index (2241-2241)
  • index (2268-2268)
  • new (80-88)
  • new (1730-1736)
  • new (1929-1935)
src/request.rs (2)
  • request (71-91)
  • request (147-159)
src/client.rs (2)
  • index (420-422)
  • new (50-62)
meilisearch-test-macro/src/lib.rs (1)
  • meilisearch_test (14-201)
src/settings.rs (1)
  • new (246-248)
src/features.rs (1)
  • new (52-61)
src/reqwest.rs (1)
  • new (23-50)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Code Coverage
🔇 Additional comments (9)
meilisearch-test-macro/README.md (1)

71-71: Documentation accurately reflects the new functionality.

The addition clearly explains that multiple Index parameters are now supported by the macro.

src/client.rs (2)

131-144: Well-structured implementation of federated multi-search execution.

The method follows the established pattern from execute_multi_search_query and correctly handles the federated query type with appropriate return type mapping.


188-203: Excellent documentation for federated search usage.

The documentation clearly explains:

  • How to create federated queries using with_federation
  • The challenges with generic type T when merging different document types
  • Practical solutions using either enums with #[serde(untagged)] or serde_json::Map

This will help users understand the nuances of federated search implementation.

meilisearch-test-macro/src/lib.rs (1)

108-184: Excellent implementation of multi-index support in the test macro.

The changes properly handle multiple Index parameters by:

  • Generating unique variable names for each index
  • Creating indexes with unique UIDs using the pattern {test_name}_{index_number}
  • Ensuring proper cleanup of all created indexes after test completion

This implementation maintains backward compatibility while enabling more complex test scenarios.

src/search.rs (5)

62-85: Good design choice for backward compatibility.

The addition of skip_serializing_if attributes reduces payload size, and the optional federation field maintains backward compatibility while supporting federated search metadata.


405-414: Correctly implements per-query federation options.

The QueryFederationOptions struct with camelCase serialization aligns with the Meilisearch API specification where per-query federation settings serialize under federationOptions.


722-789: Well-designed API for federated multi-search.

The separation between MultiSearchQuery and FederatedMultiSearchQuery provides a clean API. The builder methods for adding weighted queries and the conversion method maintain type safety while avoiding breaking changes.


885-901: Correctly implements federation hit metadata.

The weighted_ranking_score field is appropriately non-optional, aligning with the Meilisearch API specification that always returns this value for federated searches.


1261-1355: Excellent test coverage for federated multi-search.

The test comprehensively covers:

  • Weighted query result ordering
  • Heterogeneous document type handling via enum
  • Federation options application
  • Multiple index support through the enhanced test macro

@Mubelotix Mubelotix merged commit c3a1135 into dev Jul 11, 2025
16 of 17 checks passed
@Mubelotix Mubelotix deleted the federation branch July 11, 2025 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v1.10.0] Federated search
2 participants