feat: support distinct in federated search#972
Conversation
📝 WalkthroughWalkthroughAdds a ChangesMultiSearchFederation distinct support
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/com/meilisearch/sdk/MultiSearchFederation.java (1)
47-50:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
toString()omitsdistinct(and other federation fields), so serialized output is incomplete.On Line 49, the JSON only includes
limit/offset. After addingdistinct, this method now returns incorrect federation JSON for any caller usingtoString().Suggested fix
`@Override` public String toString() { JSONObject jsonObject = - new JSONObject().put("limit", this.limit).put("offset", this.offset); + new JSONObject() + .put("limit", this.limit) + .put("offset", this.offset) + .put("mergeFacets", this.mergeFacets) + .put("facetsByIndex", this.facetsByIndex) + .put("distinct", this.distinct); return jsonObject.toString(); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/meilisearch/sdk/MultiSearchFederation.java` around lines 47 - 50, The toString() method in the MultiSearchFederation class only serializes the limit and offset fields to the JSONObject, but omits the distinct field and any other federation fields. Update the toString() method to include all federation instance fields when constructing the JSONObject, ensuring that the distinct field is added to the JSON alongside the existing limit and offset fields using the same put() pattern already in use.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/main/java/com/meilisearch/sdk/MultiSearchFederation.java`:
- Around line 47-50: The toString() method in the MultiSearchFederation class
only serializes the limit and offset fields to the JSONObject, but omits the
distinct field and any other federation fields. Update the toString() method to
include all federation instance fields when constructing the JSONObject,
ensuring that the distinct field is added to the JSON alongside the existing
limit and offset fields using the same put() pattern already in use.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 37c96f06-fbe3-4e70-8b86-6443785573d4
📒 Files selected for processing (2)
src/main/java/com/meilisearch/sdk/MultiSearchFederation.javasrc/test/java/com/meilisearch/sdk/MultiSearchFederationTest.java
Adds support for the
distinctattribute 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).distinctis serialized when set and omitted when not.Changes Made
MultiSearchFederation.java
Added support for the
distinctattribute in federated search operations:String distinctfieldsetDistinct(String distinct)method that enables fluent method chainingMultiSearchFederationTest.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 thedistinctfieldImplementation Notes
The
distinctfield is serialized via Gson's JSON encoding mechanism used byjsonHandler.encode(). While thetoString()method only explicitly serializeslimitandoffsetfields, Gson's default behavior will serialize all non-null fields with the@Getterannotation, allowing thedistinctparameter to be included in the federation object alongside other federation options.Alignment with Objectives
This implementation fulfills the requirements from Issue
#949by:MultiSearchFederationclass to accept an optionaldistinctattribute