meilisearch-java icon indicating copy to clipboard operation
meilisearch-java copied to clipboard

feat: support distinct in federated search

Open GabrielBBaldez opened this issue 5 months ago • 1 comments

Adds support for the distinct attribute in federated search, introduced in Meilisearch 1.40.0. Closes #949.

  • MultiSearchFederation now carries an optional distinct string, serialized into the federation object of the multi-search payload (alongside the existing limit / offset / mergeFacets / facetsByIndex options).
  • Unit tests verifying distinct is serialized when set and omitted when not.

Changes Made

MultiSearchFederation.java

Added support for the distinct attribute in federated search operations:

  • Added private String distinct field
  • Added public setDistinct(String distinct) method that enables fluent method chaining

MultiSearchFederationTest.java

Created new test class with two test cases:

  • serializesDistinctInFederationOptions: Verifies that when distinct("movie_id") is set, the Gson-encoded JSON includes "distinct":"movie_id"
  • omitsDistinctWhenNotSet: Verifies that when distinct is not configured, the encoded JSON does not contain the distinct field

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:

  1. Extending the MultiSearchFederation class to accept an optional distinct attribute
  2. Enabling the distinct parameter in federated search requests for Meilisearch 1.40.0 compatibility
  3. Including comprehensive unit tests validating proper serialization behavior

GabrielBBaldez avatar Jun 18 '26 23:06 GabrielBBaldez

Review Change Stack

📝 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
distinct travels 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Jun 18 '26 23:06 coderabbitai[bot]