-
Notifications
You must be signed in to change notification settings - Fork 110
Add support for Dynamic Search Rules #1238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
w1ndcn
wants to merge
2
commits into
meilisearch:main
Choose a base branch
from
w1ndcn:feat/dynamic-search-rules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from typing import Any, Dict, List, Optional | ||
|
|
||
| from camel_converter.pydantic_base import CamelBase | ||
| from pydantic import ConfigDict | ||
|
|
||
|
|
||
| class DynamicSearchRule(CamelBase): | ||
| """Model for a Meilisearch dynamic search rule.""" | ||
|
|
||
| model_config = ConfigDict(arbitrary_types_allowed=True) | ||
|
|
||
| uid: str | ||
| description: Optional[str] = None | ||
| priority: Optional[int] = None | ||
| active: Optional[bool] = None | ||
| conditions: Optional[List[Dict[str, Any]]] = None | ||
| actions: Optional[List[Dict[str, Any]]] = None | ||
|
|
||
|
|
||
| class DynamicSearchRuleResults(CamelBase): | ||
| """Model for dynamic search rules list results.""" | ||
|
|
||
| model_config = ConfigDict(arbitrary_types_allowed=True) | ||
| results: List[DynamicSearchRule] | ||
| offset: int | ||
| limit: int | ||
| total: int |
118 changes: 118 additions & 0 deletions
118
tests/client/test_client_dynamic_search_rules_meilisearch.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| """Tests for dynamic search rule management endpoints.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from meilisearch.errors import MeilisearchApiError | ||
|
|
||
| pytestmark = pytest.mark.usefixtures("enable_dynamic_search_rules") | ||
|
|
||
|
|
||
| def test_get_dynamic_search_rules_empty(client): | ||
| """Test getting dynamic search rules when none exist.""" | ||
| rules = client.get_dynamic_search_rules() | ||
| assert rules.results is not None | ||
| assert isinstance(rules.results, list) | ||
| assert len(rules.results) == 0 | ||
|
|
||
|
|
||
| def test_create_or_update_dynamic_search_rule(client): | ||
| """Test creating a dynamic search rule.""" | ||
| rule_data = { | ||
| "description": "Test rule for promotion", | ||
| "priority": 10, | ||
| "active": True, | ||
| "conditions": [{"scope": "query", "isEmpty": True}], | ||
| "actions": [ | ||
| { | ||
| "selector": {"indexUid": "movies", "id": "123"}, | ||
| "action": {"type": "pin", "position": 1}, | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| rule = client.create_or_update_dynamic_search_rule("test-rule", rule_data) | ||
|
|
||
| assert rule.uid == "test-rule" | ||
| assert rule.description == rule_data["description"] | ||
| assert rule.priority == 10 | ||
| assert rule.active is True | ||
|
|
||
|
|
||
| def test_get_dynamic_search_rule(client): | ||
| """Test getting a single dynamic search rule.""" | ||
| # Create a rule first | ||
| rule_data = { | ||
| "description": "Test rule", | ||
| "active": True, | ||
| } | ||
|
|
||
| created_rule = client.create_or_update_dynamic_search_rule("test-rule", rule_data) | ||
|
|
||
| # Get the rule | ||
| rule = client.get_dynamic_search_rule(created_rule.uid) | ||
|
|
||
| assert rule.uid == created_rule.uid | ||
| assert rule.description == rule_data["description"] | ||
|
|
||
|
|
||
| def test_get_dynamic_search_rule_not_found(client): | ||
| """Test getting a dynamic search rule that doesn't exist.""" | ||
| with pytest.raises(MeilisearchApiError): | ||
| client.get_dynamic_search_rule("non-existent-uid") | ||
|
|
||
|
|
||
| def test_update_dynamic_search_rule(client): | ||
| """Test updating a dynamic search rule.""" | ||
| # Create a rule first | ||
| rule_data = { | ||
| "description": "Original description", | ||
| "priority": 10, | ||
| "active": True, | ||
| "conditions": [{"scope": "query", "isEmpty": True}], | ||
| "actions": [ | ||
| { | ||
| "selector": {"indexUid": "movies", "id": "123"}, | ||
| "action": {"type": "pin", "position": 1}, | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| created_rule = client.create_or_update_dynamic_search_rule("test-rule", rule_data) | ||
|
|
||
| # Update the rule | ||
| update_data = { | ||
| "description": "Updated description", | ||
| "priority": 5, | ||
| } | ||
|
|
||
| updated_rule = client.create_or_update_dynamic_search_rule(created_rule.uid, update_data) | ||
|
|
||
| assert updated_rule.uid == created_rule.uid | ||
| assert updated_rule.description == update_data["description"] | ||
| assert updated_rule.priority == 5 | ||
|
|
||
|
|
||
| def test_delete_dynamic_search_rule(client): | ||
| """Test deleting a dynamic search rule.""" | ||
| # Create a rule first | ||
| rule_data = { | ||
| "description": "Rule to delete", | ||
| "active": True, | ||
| } | ||
|
|
||
| created_rule = client.create_or_update_dynamic_search_rule("test-rule", rule_data) | ||
|
|
||
| # Delete the rule | ||
| status_code = client.delete_dynamic_search_rule(created_rule.uid) | ||
|
|
||
| assert status_code == 204 | ||
|
|
||
| # Verify it's deleted | ||
| with pytest.raises(MeilisearchApiError): | ||
| client.get_dynamic_search_rule(created_rule.uid) | ||
|
|
||
|
|
||
| def test_delete_dynamic_search_rule_not_found(client): | ||
| """Test deleting a dynamic search rule that doesn't exist.""" | ||
| with pytest.raises(MeilisearchApiError): | ||
| client.delete_dynamic_search_rule("non-existent-uid") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.