Skip to content

feat: add personalized search (experimental)#971

Open
GabrielBBaldez wants to merge 1 commit into
meilisearch:mainfrom
GabrielBBaldez:fix/personalized-search
Open

feat: add personalized search (experimental)#971
GabrielBBaldez wants to merge 1 commit into
meilisearch:mainfrom
GabrielBBaldez:fix/personalized-search

Conversation

@GabrielBBaldez

@GabrielBBaldez GabrielBBaldez commented Jun 16, 2026

Copy link
Copy Markdown

Adds support for the personalize search parameter introduced in Meilisearch 1.47.0. Closes #970.

  • New Personalize model (model/Personalize.java) with a userContext field, mirroring the existing Hybrid model (lombok builder + toJSONObject()).
  • SearchRequest and IndexSearchRequest now accept an optional personalize object and serialize it into the request body. IndexSearchRequest covers federated / multi-search, which 1.47.0 also supports per the issue note.
  • Unit tests in SearchRequestTest and IndexSearchRequestTest covering 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 Personalize class with a userContext field, configured with Lombok annotations for builders, getters, and setters
  • Includes toJSONObject() method for serialization and toString() override for JSON string representation

Updated Search Classes

  • SearchRequest: Added optional personalize field with JSON serialization support
  • IndexSearchRequest: Added optional personalize field with JSON serialization support

Testing

  • Added test in SearchRequestTest (toStringWithPersonalizeUsingBuilder) verifying personalize serialization and getter functionality
  • Added test in IndexSearchRequestTest verifying personalize serialization with userContext field

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.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4f526cbf-1178-46ac-a7ca-ba504fa2b1bc

📥 Commits

Reviewing files that changed from the base of the PR and between acfe026 and 9139d4f.

📒 Files selected for processing (5)
  • src/main/java/com/meilisearch/sdk/IndexSearchRequest.java
  • src/main/java/com/meilisearch/sdk/SearchRequest.java
  • src/main/java/com/meilisearch/sdk/model/Personalize.java
  • src/test/java/com/meilisearch/sdk/IndexSearchRequestTest.java
  • src/test/java/com/meilisearch/sdk/SearchRequestTest.java

📝 Walkthrough

Walkthrough

Introduces a new Personalize model class with a userContext field and JSON serialization. Adds a personalize field to both SearchRequest and IndexSearchRequest, with null-guarded inclusion in their toString() JSON output. Tests are added for both request classes.

Changes

Personalized Search Support

Layer / File(s) Summary
Personalize model and request field 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
New Personalize class with Lombok configuration, a userContext field, toJSONObject(), and toString(). Both SearchRequest and IndexSearchRequest gain a protected Personalize personalize field and null-guarded "personalize" entry in their toString() JSON builders.
Serialization tests
src/test/java/com/meilisearch/sdk/SearchRequestTest.java, src/test/java/com/meilisearch/sdk/IndexSearchRequestTest.java
New @Test methods in both test classes build requests with a personalize payload using the builder, parse the resulting JSON string, and assert both the nested personalize.userContext value and the getter return value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A context for users, a field newly made,
With userContext tucked in JSON's cascade,
toJSONObject() hops through the code with a flair,
Both Search and IndexSearch now carry it there,
Tests assert every hop lands just right,
Personalized searches leap into the light! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements personalized search support for SearchRequest and IndexSearchRequest with the Personalize model and tests, but only handles POST search, not GET search as requested in issue #970. Add support for GET search endpoints with personalize parameter, as issue #970 requires updating both POST and GET search methods.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and concisely summarizes the main change: adding personalized search support (experimental).
Out of Scope Changes check ✅ Passed All changes are directly related to implementing personalized search support in the SDK as defined in the linked issue objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

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.

[Meilisearch v1.47.0] Add personalized search (experimental)

1 participant