Add support for Dynamic Search Rules#1238
Conversation
📝 WalkthroughWalkthroughAdds 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. ChangesDynamic Search Rules API Support
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
.code-samples.meilisearch.yamlmeilisearch/client.pymeilisearch/config.pymeilisearch/models/dynamic_search_rule.pytests/client/test_client_dynamic_search_rules_meilisearch.py
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
meilisearch/client.pymeilisearch/models/dynamic_search_rule.pytests/client/test_client_dynamic_search_rules_meilisearch.pytests/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
|
@Strift I've fixed the CI failures:
|
|
@Strift Hi, when you have time, could you please take another look at this PR? Thanks! |
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
Clientclass 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 forDynamicSearchRuleandDynamicSearchRuleResultstests/client/test_client_dynamic_search_rules_meilisearch.py— 7 test cases covering CRUD operationsModified files
meilisearch/config.py— Addeddynamic_search_rules = "dynamic-search-rules"path constantmeilisearch/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_1New methods
get_dynamic_search_rules()/dynamic-search-rulesget_dynamic_search_rule(uid)/dynamic-search-rules/{uid}create_or_update_dynamic_search_rule(uid, options)/dynamic-search-rules/{uid}delete_dynamic_search_rule(uid)/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
Clientget_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.pyDynamicSearchRule— Represents a single rule with fields: uid, optional description, optional priority, optional active flag, and optional conditions/actions listsDynamicSearchRuleResults— 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:Configuration
dynamic_search_rules = "dynamic-search-rules"path constant toConfig.Pathsinmeilisearch/config.pyDocumentation
Updated
.code-samples.meilisearch.yamlwith four code sample entries:list_dynamic_search_rules_1,get_dynamic_search_rule_1,patch_dynamic_search_rule_1, anddelete_dynamic_search_rule_1Related
Closes
#1227