Skip to content

Add support for Dynamic Search Rules#1238

Open
w1ndcn wants to merge 2 commits into
meilisearch:mainfrom
w1ndcn:feat/dynamic-search-rules
Open

Add support for Dynamic Search Rules#1238
w1ndcn wants to merge 2 commits into
meilisearch:mainfrom
w1ndcn:feat/dynamic-search-rules

Conversation

@w1ndcn

@w1ndcn w1ndcn commented Jun 5, 2026

Copy link
Copy Markdown

Add support for Dynamic Search Rules

Summary

Add support for Meilisearch v1.41's Dynamic Search Rules feature. This introduces four new methods on the Client class for managing dynamic search rules, along with the corresponding models, tests, and code samples.

Changes

New files

  • meilisearch/models/dynamic_search_rule.py — Pydantic models for DynamicSearchRule and DynamicSearchRuleResults
  • tests/client/test_client_dynamic_search_rules_meilisearch.py — 7 test cases covering CRUD operations

Modified files

  • meilisearch/config.py — Added dynamic_search_rules = "dynamic-search-rules" path constant
  • meilisearch/client.py — Added 4 methods: get_dynamic_search_rules, get_dynamic_search_rule, create_or_update_dynamic_search_rule, delete_dynamic_search_rule
  • .code-samples.meilisearch.yaml — Added 4 code samples: list_dynamic_search_rules_1, get_dynamic_search_rule_1, patch_dynamic_search_rule_1, delete_dynamic_search_rule_1

New methods

Method HTTP Endpoint
get_dynamic_search_rules() POST /dynamic-search-rules
get_dynamic_search_rule(uid) GET /dynamic-search-rules/{uid}
create_or_update_dynamic_search_rule(uid, options) PATCH /dynamic-search-rules/{uid}
delete_dynamic_search_rule(uid) DELETE /dynamic-search-rules/{uid}

Related issue

Closes #1227

Summary

This PR adds support for Meilisearch v1.41 Dynamic Search Rules, enabling SDK users to manage document pinning rules through four new client methods. The implementation includes new Pydantic models, comprehensive test coverage, and documentation code samples.

Changes

New Methods in Client

  • get_dynamic_search_rules() → Returns all dynamic search rules (POST /dynamic-search-rules)
  • get_dynamic_search_rule(uid) → Retrieves a specific rule by UID (GET /dynamic-search-rules/{uid})
  • create_or_update_dynamic_search_rule(uid, options) → Creates or updates a rule (PATCH /dynamic-search-rules/{uid})
  • delete_dynamic_search_rule(uid) → Deletes a rule and returns status code (DELETE /dynamic-search-rules/{uid})

New Models in meilisearch/models/dynamic_search_rule.py

  • DynamicSearchRule — Represents a single rule with fields: uid, optional description, optional priority, optional active flag, and optional conditions/actions lists
  • DynamicSearchRuleResults — Models list responses with results array and pagination fields (offset, limit, total)

Test Coverage

Added 7 test cases in tests/client/test_client_dynamic_search_rules_meilisearch.py:

  • Get empty rules list
  • Create/update a rule and verify returned fields
  • Retrieve a specific rule
  • Handle not-found errors for missing rules
  • Update existing rule and verify changes
  • Delete a rule and verify status
  • Delete non-existent rule error handling

Configuration

  • Added dynamic_search_rules = "dynamic-search-rules" path constant to Config.Paths in meilisearch/config.py

Documentation

Updated .code-samples.meilisearch.yaml with four code sample entries: list_dynamic_search_rules_1, get_dynamic_search_rule_1, patch_dynamic_search_rule_1, and delete_dynamic_search_rule_1

Related

Closes #1227

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Meilisearch Dynamic Search Rules support: new models and config path, four Client CRUD methods (list, get, create-or-update, delete), tests exercising all flows with a fixture toggling the feature, and documentation code samples.

Changes

Dynamic Search Rules API Support

Layer / File(s) Summary
Data Models and Configuration
meilisearch/models/dynamic_search_rule.py, meilisearch/config.py
DynamicSearchRule and DynamicSearchRuleResults models define rule metadata and paginated responses; Config.Paths.dynamic_search_rules maps the endpoint path.
Client API Methods
meilisearch/client.py
Four new Client methods implement listing (POST), retrieving (GET), creating/updating (PATCH), and deleting (DELETE) Dynamic Search Rules and return typed models or status codes.
Tests and Fixture
tests/client/test_client_dynamic_search_rules_meilisearch.py, tests/conftest.py
Seven tests cover empty list, create/update, fetch, not-found errors, update, delete (204), and delete-not-found; enable_dynamic_search_rules fixture toggles the experimental feature around tests.
Documentation Code Samples
.code-samples.meilisearch.yaml
Adds four YAML snippets: list_dynamic_search_rules_1, get_dynamic_search_rule_1, patch_dynamic_search_rule_1, and delete_dynamic_search_rule_1.

🎯 3 (Moderate) | ⏱️ ~25 minutes

"I hopped through code with a curious sniff,
Models and methods all lined up swift,
Tests cheered loud while fixtures danced true,
Docs show the steps — now rules can hop through! 🐇"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add support for Dynamic Search Rules' clearly and concisely describes the primary change—introducing new SDK methods and models for managing Meilisearch's Dynamic Search Rules feature.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #1227: four new Client methods for CRUD operations, Pydantic models for request/response types, configuration path constant, comprehensive test coverage (7 tests), and code samples.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the stated objectives—implementing Dynamic Search Rules support via new methods, models, tests, and documentation samples. No extraneous modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

✏️ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@tests/client/test_client_dynamic_search_rules_meilisearch.py`:
- Around line 8-14: test_get_dynamic_search_rules_empty can be flaky because
dynamic rules created by other tests are not cleaned up; before asserting empty,
call client.get_dynamic_search_rules() and delete any existing rules to make the
test deterministic (e.g., iterate over the results from
client.get_dynamic_search_rules() and call the client delete method for each
rule such as client.delete_dynamic_search_rule(rule["name"]) or the appropriate
delete API on your client) then re-query with client.get_dynamic_search_rules()
and assert results is an empty list.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e80c737b-b318-4793-bd03-f9e75d18b8d0

📥 Commits

Reviewing files that changed from the base of the PR and between ada25db and 68831d5.

📒 Files selected for processing (5)
  • .code-samples.meilisearch.yaml
  • meilisearch/client.py
  • meilisearch/config.py
  • meilisearch/models/dynamic_search_rule.py
  • tests/client/test_client_dynamic_search_rules_meilisearch.py

Comment thread tests/client/test_client_dynamic_search_rules_meilisearch.py
@Strift Strift added the enhancement New feature or request label Jun 8, 2026

@Strift Strift left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @w1ndcn and thank you for your contribution!

CI is not passing. Please make sure tests, linters, and formatters pass locally before asking another review :)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@tests/conftest.py`:
- Around line 359-370: The PATCH calls in the enable_dynamic_search_rules
fixture currently ignore responses; update both requests.patch invocations (the
one before yield and the one after yield) to capture their return values (e.g.,
resp = requests.patch(...)) and call resp.raise_for_status() immediately after
each call so any HTTP errors surface and prevent leaving the server in the wrong
state.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f57de259-5131-46d4-8f7f-8094dfd3606d

📥 Commits

Reviewing files that changed from the base of the PR and between 68831d5 and 7e2fd46.

📒 Files selected for processing (4)
  • meilisearch/client.py
  • meilisearch/models/dynamic_search_rule.py
  • tests/client/test_client_dynamic_search_rules_meilisearch.py
  • tests/conftest.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • meilisearch/models/dynamic_search_rule.py
  • meilisearch/client.py
  • tests/client/test_client_dynamic_search_rules_meilisearch.py

Comment thread tests/conftest.py
@w1ndcn

w1ndcn commented Jun 8, 2026

Copy link
Copy Markdown
Author

@Strift I've fixed the CI failures:

  1. Ran isort + black to fix formatting issues
  2. Added the enable_dynamic_search_rules fixture in conftest.py to enable the experimental feature before tests
    CI should pass now. Could you re-run it? Thanks!

@w1ndcn w1ndcn requested a review from Strift June 8, 2026 12:03
@w1ndcn

w1ndcn commented Jun 14, 2026

Copy link
Copy Markdown
Author

@Strift Hi, when you have time, could you please take another look at this PR? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Meilisearch v1.41] Add support for Dynamic Search Rules

2 participants