Skip to content

Add personalized search support to the search query - #752

Open
arcusbuilds wants to merge 1 commit into
meilisearch:mainfrom
arcusbuilds:feat/personalized-search
Open

Add personalized search support to the search query#752
arcusbuilds wants to merge 1 commit into
meilisearch:mainfrom
arcusbuilds:feat/personalized-search

Conversation

@arcusbuilds

@arcusbuilds arcusbuilds commented Jul 30, 2026

Copy link
Copy Markdown

Pull Request

Related issue

Fixes #737

What does this PR do?

Adds the experimental personalize search parameter from Meilisearch 1.47.0. It is a new Personalize class with a single UserContext string, exposed as SearchQuery.Personalize:

await index.SearchAsync<Movie>("man", new SearchQuery
{
    Personalize = new Personalize { UserContext = "The user only watches science fiction movies" }
});

This covers Search (POST). Search (GET) has no surface in this SDK: the only search call is the POST in Index.Documents.cs, and there is no GET-based search method to update. Worth flagging for whoever adds one, the GET endpoint takes a flat personalizeUserContext string rather than a personalize object, so this class will not map onto it directly.

Non-federated /multi-search picks the parameter up without extra work, since MultiSearchQuery.Queries is a List<SearchQuery>.

Not included

Federated /multi-search needs federation.personalize instead. The server rejects per-query personalize when a federation object is present, and FederatedMultiSearchQuery always emits one, so federated personalization is currently unreachable from the SDK. I kept this PR scoped to the issue and left it out. Happy to open a separate PR for it if you want.

Tests

Reranking needs a personalization API key on the instance, which neither docker-compose.yml nor CI sets, so the feature itself cannot run under test. Two things are covered instead:

  • SearchQuerySerializationTests asserts the request JSON directly, with no server involved.
  • CustomSearchWithPersonalize sends a real request and passes whether or not a key is configured, so it will not start failing if CI ever gets one.

All of the tests added here pass locally against Meilisearch 1.51.0.

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.
  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

AI tool disclosure

I used Claude Code to write the implementation and the tests, and to review the result. I verified the API shape by hand against a local Meilisearch 1.51.0 instance, including which error code comes back for each request shape, and I read through the whole diff before committing.

Summary by CodeRabbit

  • New Features

    • Added support for personalizing search queries using a user context.
    • Personalization can now be included in standard and multi-search requests.
    • Requests use the personalize.userContext format for compatibility with the search API.
  • Tests

    • Added coverage for personalization serialization, omission when unused, multi-search requests, and search behavior when personalization is enabled.

Adds the experimental `personalize` search parameter introduced in Meilisearch
v1.47.0, as requested in meilisearch#737.

`SearchQuery.Personalize` covers POST /indexes/{uid}/search. It also covers
non-federated POST /multi-search, since `MultiSearchQuery.Queries` is a list of
`SearchQuery`. This SDK exposes no GET search method, so the issue's Search (GET)
half has no surface to update here.

The wire format is pinned by server-independent serialization tests. The
integration test passes whether or not the Meilisearch instance has a
personalization API key configured, since reranking cannot be exercised without
one.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a Personalize query model with UserContext, wires it into SearchQuery, and tests serialization for regular and multi-search requests plus a personalized search call.

Changes

Personalized search

Layer / File(s) Summary
Personalization query contract
src/Meilisearch/Personalize.cs, src/Meilisearch/SearchQuery.cs
Adds the Personalize model and maps SearchQuery.Personalize to the personalize JSON field, with UserContext serialized as userContext.
Serialization and search validation
tests/Meilisearch.Tests/SearchQuerySerializationTests.cs, tests/Meilisearch.Tests/SearchTests.cs
Verifies populated, omitted, and nested personalization serialization, and exercises personalized search with the expected feature-disabled error handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • meilisearch/meilisearch-swift#523 — Adds the same personalize.userContext SDK support and related tests.
  • meilisearch/meilisearch-ruby#702 — Covers personalized search query serialization and tests.
  • meilisearch/meilisearch-dart#489 — Adds the corresponding personalized search parameter.
  • meilisearch/meilisearch-php#917 — Adds personalize.userContext support and search tests.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant SearchQuery
  participant JsonSerializer
  participant SearchEndpoint
  Caller->>SearchQuery: set Personalize.UserContext
  SearchQuery->>JsonSerializer: serialize query
  JsonSerializer->>SearchEndpoint: send personalize.userContext
  SearchEndpoint-->>Caller: return search results or feature_not_enabled
Loading

Poem

I’m a bunny with context tucked neat,
In a query that makes searches sweet.
userContext hops into the JSON,
Multi-search joins the procession.
Tests nibble each field into place—
Personalized results win the race!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR adds personalize support to SearchQuery and covers it with serialization and integration tests, satisfying the issue's core search-personalization objective.
Out of Scope Changes check ✅ Passed The changes stay focused on personalization support and related tests, with no obvious unrelated code additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding personalized search support to search queries.
✨ 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.

@arcusbuilds

Copy link
Copy Markdown
Author

@curquiza @Strift this has been open a month with CI green. It adds the personalize parameter from #737, covering search and non-federated multi-search. Could one of you take a look?

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