feat: add personalized search (experimental)
Adds support for the personalize search parameter introduced in Meilisearch 1.47.0. Closes #970.
- New
Personalizemodel (model/Personalize.java) with auserContextfield, mirroring the existingHybridmodel (lombok builder +toJSONObject()). SearchRequestandIndexSearchRequestnow accept an optionalpersonalizeobject and serialize it into the request body.IndexSearchRequestcovers federated / multi-search, which 1.47.0 also supports per the issue note.- Unit tests in
SearchRequestTestandIndexSearchRequestTestcovering the serialization and getters.
Usage:
SearchRequest.builder()
.q("...")
.personalize(Personalize.builder().userContext("The user prefers ...").build())
.build();
Note: the SDK performs search over POST (Search / Index.search), so there is no separate GET search path in the client to update — personalize is added to the POST request body.
Overview
This PR adds support for the personalize search parameter introduced in Meilisearch 1.47.0, enabling users to provide personalization context in search requests. The implementation includes a new Personalize model class and updates to search request classes with corresponding unit tests.
Changes
New Model
- Added
Personalizeclass with auserContextfield, configured with Lombok annotations for builders, getters, and setters - Includes
toJSONObject()method for serialization andtoString()override for JSON string representation
Updated Search Classes
SearchRequest: Added optionalpersonalizefield with JSON serialization supportIndexSearchRequest: Added optionalpersonalizefield with JSON serialization support
Testing
- Added test in
SearchRequestTest(toStringWithPersonalizeUsingBuilder) verifyingpersonalizeserialization and getter functionality - Added test in
IndexSearchRequestTestverifyingpersonalizeserialization withuserContextfield
Usage
Users can now use personalization in search requests via the builder pattern:
SearchRequest.builder()
.q("...")
.personalize(Personalize.builder().userContext("user preference data").build())
.build();
The implementation supports both standard search and federated/multi-search operations with personalization context.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 99cc664f-eea1-48a8-9182-4d50342d88d2
📥 Commits
Reviewing files that changed from the base of the PR and between 9139d4f3b38223e471182753edcf482df200aedc and 2c3e2de1734a1b8f8c6a1e050ada59bd545343db.
📒 Files selected for processing (1)
src/main/java/com/meilisearch/sdk/SearchRequest.java
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.
📝 Walkthrough
Walkthrough
Introduces a Personalize model with a userContext field and JSON serialization. Adds an optional personalize field to SearchRequest and IndexSearchRequest. Tests verify serialized JSON and getter values.
Changes
Personalized Search Support
| Layer / File(s) | Summary |
|---|---|
Personalize model and request integration src/main/java/com/meilisearch/sdk/model/Personalize.java, src/main/java/com/meilisearch/sdk/SearchRequest.java, src/main/java/com/meilisearch/sdk/IndexSearchRequest.java |
Adds Personalize with toJSONObject() and toString(). Both request classes serialize non-null personalize values. |
Personalize serialization tests src/test/java/com/meilisearch/sdk/SearchRequestTest.java, src/test/java/com/meilisearch/sdk/IndexSearchRequestTest.java |
Builds requests with Personalize, parses the JSON output, and checks userContext and getter values. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Merge Risk: ⚪ Minimal · up to 2c3e2
This is a localized search API addition with request serialization coverage; no actionable merge-blocking risk remains beyond normal checks and review.
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant SearchRequest
participant Personalize
Caller->>SearchRequest: Build request with personalize
SearchRequest->>Personalize: toJSONObject()
Personalize-->>SearchRequest: JSON object with userContext
SearchRequest-->>Caller: Serialized request JSON
Poem
A rabbit adds context to the search request,
Personalizekeeps the JSON shape correct,SearchRequestcarries the new field,IndexSearchRequestcarries it as well, Tests check the context in place, The request hops forward with grace.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly identifies the primary change: adding experimental personalized search support. |
| Linked Issues check | ✅ Passed | The changes satisfy issue #970 by adding the Personalize model, supporting userContext serialization in SearchRequest and IndexSearchRequest, covering federated search request serialization, and addin… |
| Out of Scope Changes check | ✅ Passed | All production and test changes directly support personalized search and the requirements in issue #970. No unrelated changes are identified. |
Full details: Linked Issues check
Explanation
The changes satisfy issue #970 by adding the Personalize model, supporting userContext serialization in SearchRequest and IndexSearchRequest, covering federated search request serialization, and adding unit tests. The provided context states that the SDK has no separate GET search path to update.
✨ 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.