Skip to content

Add custom_headers client option for inline rule preview metadata - #719

Open
ammadakram wants to merge 1 commit into
meilisearch:mainfrom
ammadakram:pr/issue-714
Open

ammadakram wants to merge 1 commit into
meilisearch:mainfrom
ammadakram:pr/issue-714

Conversation

@ammadakram

@ammadakram ammadakram commented Oct 25, 2026 •

Copy link
Copy Markdown

Related issue

Fixes #714

What does this PR do?

  • inline_rule: already passes through index.search and client.multi_search options as inlineRule, because Utils.transform_attributes camelizes only top-level keys. Field names inside the rule, such as stock_intent, are sent unchanged.
  • metadata.inlineRuleConditionOutcomes is only returned when the request sends Meili-Include-Metadata: true, and the client had no way to send it. This PR adds a custom_headers client option. The headers are added to every request made by the client and its indexes. Keys and values are sent as strings, so 'Meili-Include-Metadata' => true works:
client = Meilisearch::Client.new(url, key, custom_headers: { 'Meili-Include-Metadata' => true })
client.index('books').search('prince', inline_rule: { uid: 'r1', conditions: { query: { words: 'prince' } } })
# => response['metadata']['inlineRuleConditionOutcomes']

This matches how meilisearch-python handled the same issue (custom_headers={"Meili-Include-Metadata": "true"}, #1284/#1286).

Tests

  • spec/meilisearch/index/search/inline_rule_spec.rb covers search with inline_rule, the condition outcomes in metadata, and multi-search where only the query that sends inline_rule gets outcomes. It needs Enterprise with dynamicSearchRules, which the CI image provides.
  • spec/meilisearch_spec.rb has a unit test for custom_headers (a symbol key, a boolean value and nil) that needs no running server.
  • I ran the full suite locally against Meilisearch Enterprise v1.55.0 on Ruby 3.3: 463 examples, 0 failures. Rubocop reports no offenses.

Note: spec/meilisearch/client/experimental_features_spec.rb leaves every experimental feature switched on, so the order of a local run sometimes breaks settings_spec.rb default-value examples. This also happens on main and is unrelated to this PR.

AI assistance

Per the "Coding with AI" section: I used Claude (Anthropic) to explore the codebase and to draft the implementation and specs. I then ran two automated review passes, which caught the boolean-header crash fixed here. I reviewed the full diff and ran the tests locally against Enterprise v1.55.

Summary by CodeRabbit

  • Improvements
    • Custom request headers are converted to strings before being sent, so header names and values can be provided in non-string formats.
    • Custom headers can override default headers when their names match, giving you control over the headers used in requests.
    • Custom headers continue to be included alongside authorization information in requests to search indexes.

Meilisearch v1.55 returns metadata.inlineRuleConditionOutcomes only when
the request sends Meili-Include-Metadata: true. inline_rule already passes
through search and multi_search options, but the client had no way to send
that header. Client options now accept custom_headers, which are added to
every request made by the client and its indexes. Keys and values are sent
as strings, so `'Meili-Include-Metadata' => true` works.

Closes meilisearch#714

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8d6ec983-47d4-46fd-8e4d-b52d01a0158a
Commits

Reviewing files that changed from the base of the PR and between 8cf7fe3 and e64487d.

Files selected for processing: 4
  • lib/meilisearch/http_request.rb
  • spec/meilisearch/index/search/inline_rule_spec.rb
  • spec/meilisearch_spec.rb
  • spec/support/experimental_feature_helpers.rb

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

The request builder now merges stringified custom headers into default headers. New specs cover custom-header propagation and inline-rule behavior in single-search and multi-search requests.

Changes: Custom Header Handling

Layer / File(s) Summary
Merge custom headers into requests
lib/meilisearch/http_request.rb, spec/meilisearch_spec.rb
The request builder stringifies custom header keys and values, then merges them into default headers. Specs check the authorization header, index-request propagation, and behavior with custom_headers: nil.

Dynamic Search Rule Specs

Layer / File(s) Summary
Exercise inline rules in search requests
spec/support/experimental_feature_helpers.rb, spec/meilisearch/index/search/inline_rule_spec.rb
A helper toggles the dynamicSearchRules feature. Specs cover single-search and multi-search requests, including pinned hits and inline-rule condition outcome metadata.

Priority: Normal

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

Change: Feature

Suggested reviewers: brunoocasali, curquiza

Merge Risk: Minimal · up to e6448

The change is mergeable after normal checks; no actionable risk remains established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
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 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 "Add custom_headers client option for inline rule preview metadata" matches the main change. The PR adds a custom_headers client option that applies headers to client and index requests. The…
Linked Issues check Passed Issue [#714] requires inline-rule support for search and multi-search, metadata condition outcomes when Meili-Include-Metadata is true, and automated tests. The reviewed changes add string conversio…
Out of Scope Changes check Passed The changes stay within issue [#714]. custom_headers enables the required metadata request header and applies it to client requests and index requests. The added unit and integration tests, plus the…
Full details: Title check

Explanation

The title "Add custom_headers client option for inline rule preview metadata" matches the main change. The PR adds a custom_headers client option that applies headers to client and index requests. The stated purpose is sending Meili-Include-Metadata: true to receive inlineRuleConditionOutcomes for inline-rule previews. The raw summary covers the header merge in http_request.rb, the new inline rule specs, the client spec, and the dynamicSearchRules helper. The title names the primary feature and its purpose, so it is specific and accurate.

Full details: Linked Issues check

Explanation

Issue [#714] requires inline-rule support for search and multi-search, metadata condition outcomes when Meili-Include-Metadata is true, and automated tests. The reviewed changes add string conversion and propagation for custom_headers in HTTPRequest, including Meili-Include-Metadata. The existing request transformation passes inline_rule as inlineRule, including nested field names unchanged. The added integration specs cover single search, multi-search, and condition outcomes with dynamicSearchRules enabled.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue [#714]. custom_headers enables the required metadata request header and applies it to client requests and index requests. The added unit and integration tests, plus the experimental-feature helper, support that implementation. No unrelated product behavior is shown in the supplied evidence.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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.55] Add support for dynamic search rule preview

1 participant