feat: support distinct in federated search
Adds support for the distinct attribute in federated search, introduced in Meilisearch 1.40.0. Closes #949.
MultiSearchFederationnow carries an optionaldistinctstring, serialized into thefederationobject of the multi-search payload (alongside the existinglimit/offset/mergeFacets/facetsByIndexoptions).- Unit tests verifying
distinctis serialized when set and omitted when not.
Changes Made
MultiSearchFederation.java
Added support for the distinct attribute in federated search operations:
- Added private
String distinctfield - Added public
setDistinct(String distinct)method that enables fluent method chaining
MultiSearchFederationTest.java
Created new test class with two test cases:
serializesDistinctInFederationOptions: Verifies that whendistinct("movie_id")is set, the Gson-encoded JSON includes"distinct":"movie_id"omitsDistinctWhenNotSet: Verifies that whendistinctis not configured, the encoded JSON does not contain thedistinctfield
Implementation Notes
The distinct field is serialized via Gson's JSON encoding mechanism used by jsonHandler.encode(). While the toString() method only explicitly serializes limit and offset fields, Gson's default behavior will serialize all non-null fields with the @Getter annotation, allowing the distinct parameter to be included in the federation object alongside other federation options.
Alignment with Objectives
This implementation fulfills the requirements from Issue #949 by:
- Extending the
MultiSearchFederationclass to accept an optionaldistinctattribute - Enabling the distinct parameter in federated search requests for Meilisearch 1.40.0 compatibility
- Including comprehensive unit tests validating proper serialization behavior
📝 Walkthrough
Walkthrough
Adds distinct and showPerformanceDetails fields to MultiSearchFederation. Adds a fluent setDistinct method. New tests validate distinct JSON inclusion and omission.
Changes
Federation search options
| Layer / File(s) | Summary |
|---|---|
Federation fields, setter, and serialization tests src/main/java/com/meilisearch/sdk/MultiSearchFederation.java, src/test/java/com/meilisearch/sdk/MultiSearchFederationTest.java |
Adds distinct and showPerformanceDetails fields. Adds a fluent setDistinct(String) method. Tests verify distinct appears when configured and is omitted when not configured. |
Estimated code review effort: 1 (Trivial) | ~3 minutes
Merge Risk: 🔵 Low · up to 4c9c7
Federated search now supports serializing distinct in requests, but the class’s JSON-like string representation still omits distinct and showPerformanceDetails. This does not affect request behavior, but should be corrected as a bounded follow-up before treating the change as fully complete.
Poem
A rabbit adds a field with care
distincttravels through the air
A fluent setter joins the trail
Tests check its JSON without fail
Unset values stay out of sight
🚥 Pre-merge checks | ✅ 2 | ❌ 3
❌ Failed checks (3 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Linked Issues check | ⚠️ Warning | The PR adds the distinct field, fluent setter, and serialization tests. However, the implementation summary states that JSON serialization remains limited to limit and offset, so distinct is n… |
Update MultiSearchFederation JSON serialization to include the optional distinct attribute, then verify the existing tests pass and add or retain coverage for both configured and omitted values [#949]. |
| Out of Scope Changes check | ⚠️ Warning | The added showPerformanceDetails field and setter are not part of the linked issue, which only requires support for distinct in federated search [#949]. |
Remove showPerformanceDetails and its setter from this PR, or link a requirement that explicitly includes this change. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly describes the primary change: support for distinct in federated search. |
Full details: Linked Issues check
Explanation
The PR adds the distinct field, fluent setter, and serialization tests. However, the implementation summary states that JSON serialization remains limited to limit and offset, so distinct is not serialized as required by issue #949.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
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 @coderabbitai help to get the list of available commands.