Add dynamic search rules#910
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds first-class support for Meilisearch Dynamic Search Rules: new contract types, a DynamicSearchRules endpoint with CRUD methods, a delegate trait wired into the Client, tests and code samples, docs, and a Meilisearch image bump in docker-compose.yml. Changes
Sequence Diagram(s)sequenceDiagram
participant User as "User"
participant Client as "Client"
participant Delegate as "HandlesDynamicSearchRules"
participant Endpoint as "DynamicSearchRules"
participant API as "Meilisearch API"
User->>Client: getDynamicSearchRules(options)
Client->>Delegate: delegate call
Delegate->>Endpoint: all(options)
Endpoint->>Endpoint: options?.toArray()
Endpoint->>API: POST /dynamic-search-rules
API-->>Endpoint: { results, offset, limit, total }
Endpoint->>Endpoint: map results -> DynamicSearchRule::fromArray()
Endpoint-->>Delegate: DynamicSearchRulesResults
Delegate-->>Client: DynamicSearchRulesResults
Client-->>User: DynamicSearchRulesResults
User->>Client: updateDynamicSearchRule(request)
Client->>Delegate: delegate call
Delegate->>Endpoint: update(request)
Endpoint->>Endpoint: request.toArray()
Endpoint->>API: PATCH /dynamic-search-rules/{uid}
API-->>Endpoint: raw rule
Endpoint->>Endpoint: DynamicSearchRule::fromArray()
Endpoint-->>Delegate: DynamicSearchRule
Delegate-->>Client: DynamicSearchRule
Client-->>User: DynamicSearchRule
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~28 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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
🧹 Nitpick comments (3)
tests/Contracts/DynamicSearchRulesQueryTest.php (1)
32-47: Consider adding one regression test foractive=false.This would harden behavior around boolean serialization and protect against accidental false-value filtering.
Suggested test case
final class DynamicSearchRulesQueryTest extends TestCase { + public function testSetFilterWithInactiveRule(): void + { + $data = (new DynamicSearchRulesQuery()) + ->setFilter( + (new DynamicSearchRulesFilter()) + ->setAttributePatterns(['movie-rule']) + ->setActive(false) + ); + + self::assertSame([ + 'filter' => [ + 'attributePatterns' => ['movie-rule'], + 'active' => false, + ], + ], $data->toArray()); + } + public function testSetFilter(): void {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/Contracts/DynamicSearchRulesQueryTest.php` around lines 32 - 47, Add a regression test that verifies boolean false is serialized correctly: create a new test method (e.g., testSetFilterInactive) in DynamicSearchRulesQueryTest which builds a DynamicSearchRulesQuery with DynamicSearchRulesFilter()->setAttributePatterns([...])->setActive(false) and assert that ->toArray() returns ['filter'=>['attributePatterns'=>[...],'active'=>false]] to ensure false values are not omitted or converted.src/Contracts/DynamicSearchRulesResults.php (1)
25-30: Reduce duplicated payload shape docs with a PHPStan alias.The constructor and
toArray()repeat the same shape. Defining a single alias improves maintainability and avoids drift.As per coding guidelines, "Import shared aliases with `@phpstan-import-type` instead of duplicating shapes."Proposed refactor
final class DynamicSearchRulesResults extends Data { + /** + * `@phpstan-type` DynamicSearchRulesResultsPayload array{ + * results: array<int, DynamicSearchRule>, + * offset: non-negative-int, + * limit: non-negative-int, + * total: non-negative-int + * } + */ + /** - * `@param` array{ - * results: array<int, DynamicSearchRule>, - * offset: non-negative-int, - * limit: non-negative-int, - * total: non-negative-int - * } $params + * `@param` DynamicSearchRulesResultsPayload $params */ public function __construct(array $params) { parent::__construct($params['results']); @@ /** - * `@return` array{ - * results: array<int, DynamicSearchRule>, - * offset: non-negative-int, - * limit: non-negative-int, - * total: non-negative-int - * } + * `@return` DynamicSearchRulesResultsPayload */ public function toArray(): arrayAlso applies to: 74-79
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Contracts/DynamicSearchRulesResults.php` around lines 25 - 30, Define a single PHPStan array-shape alias for the payload and import it instead of duplicating the shape in this file; add an alias (e.g., `@phpstan-type` DynamicSearchRulesResultsShape array{results: array<int, DynamicSearchRule>, offset: non-negative-int, limit: non-negative-int, total: non-negative-int}) in a central contract (or at top of this file) and then replace the duplicated shape docs used on DynamicSearchRulesResults::__construct and DynamicSearchRulesResults::toArray with an import line like `@phpstan-import-type` DynamicSearchRulesResultsShape from <wherever you placed it> and reference that alias in the `@param/`@return tags so both the constructor and toArray use the single shared alias.src/Endpoints/DynamicSearchRules.php (1)
40-60: Optional DRY cleanup for repeated rule-path construction.
self::PATH.'/'.$uidis repeated in three methods. A small helper would reduce duplication and future drift.♻️ Proposed refactor
class DynamicSearchRules extends Endpoint { protected const PATH = '/dynamic-search-rules'; + + /** + * `@param` non-empty-string $uid + */ + private function rulePath(string $uid): string + { + return self::PATH.'/'.$uid; + } /** * `@param` non-empty-string $uid */ public function get(string $uid): DynamicSearchRule { - $response = $this->http->get(self::PATH.'/'.$uid); + $response = $this->http->get($this->rulePath($uid)); return DynamicSearchRule::fromArray($response); } public function update(UpdateDynamicSearchRuleQuery $request): DynamicSearchRule { - $response = $this->http->patch(self::PATH.'/'.$request->uid, $request->toArray()); + $response = $this->http->patch($this->rulePath($request->uid), $request->toArray()); return DynamicSearchRule::fromArray($response); } /** * `@param` non-empty-string $uid */ public function delete(string $uid): ?array { - return $this->http->delete(self::PATH.'/'.$uid); + return $this->http->delete($this->rulePath($uid)); } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Endpoints/DynamicSearchRules.php` around lines 40 - 60, The three methods get, update, and delete repeat building the endpoint string using self::PATH.'/'. $uid; add a small private helper method (e.g., pathFor(string $uid) or buildPath(string $uid)) that returns self::PATH.'/'.$uid, and update DynamicSearchRules::get, DynamicSearchRules::update (which uses $request->uid), and DynamicSearchRules::delete to call that helper to remove duplication and centralize path construction.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Contracts/DynamicSearchRulesQuery.php`:
- Around line 55-63: The phpdoc for DynamicSearchRulesQuery currently
re-declares the nested filter array shape; instead import the shared alias with
`@phpstan-import-type` DynamicSearchRulesFilter from the DynamicSearchRulesFilter
contract and then reference that alias in the return phpdoc for toArray() (use
the imported type for the filter key instead of inlining
attributePatterns/active). Add the `@phpstan-import-type` statement near the top
of the file and update the return array shape to use the imported alias so the
filter shape is a single source of truth.
---
Nitpick comments:
In `@src/Contracts/DynamicSearchRulesResults.php`:
- Around line 25-30: Define a single PHPStan array-shape alias for the payload
and import it instead of duplicating the shape in this file; add an alias (e.g.,
`@phpstan-type` DynamicSearchRulesResultsShape array{results: array<int,
DynamicSearchRule>, offset: non-negative-int, limit: non-negative-int, total:
non-negative-int}) in a central contract (or at top of this file) and then
replace the duplicated shape docs used on DynamicSearchRulesResults::__construct
and DynamicSearchRulesResults::toArray with an import line like
`@phpstan-import-type` DynamicSearchRulesResultsShape from <wherever you placed
it> and reference that alias in the `@param/`@return tags so both the constructor
and toArray use the single shared alias.
In `@src/Endpoints/DynamicSearchRules.php`:
- Around line 40-60: The three methods get, update, and delete repeat building
the endpoint string using self::PATH.'/'. $uid; add a small private helper
method (e.g., pathFor(string $uid) or buildPath(string $uid)) that returns
self::PATH.'/'.$uid, and update DynamicSearchRules::get,
DynamicSearchRules::update (which uses $request->uid), and
DynamicSearchRules::delete to call that helper to remove duplication and
centralize path construction.
In `@tests/Contracts/DynamicSearchRulesQueryTest.php`:
- Around line 32-47: Add a regression test that verifies boolean false is
serialized correctly: create a new test method (e.g., testSetFilterInactive) in
DynamicSearchRulesQueryTest which builds a DynamicSearchRulesQuery with
DynamicSearchRulesFilter()->setAttributePatterns([...])->setActive(false) and
assert that ->toArray() returns
['filter'=>['attributePatterns'=>[...],'active'=>false]] to ensure false values
are not omitted or converted.
🪄 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: 3527ad2c-6de1-466c-8eba-d3352b2773ba
📒 Files selected for processing (17)
AGENTS.mddocker-compose.ymlsrc/Client.phpsrc/Contracts/AGENTS.mdsrc/Contracts/DynamicSearchRule.phpsrc/Contracts/DynamicSearchRulesFilter.phpsrc/Contracts/DynamicSearchRulesQuery.phpsrc/Contracts/DynamicSearchRulesResults.phpsrc/Contracts/UpdateDynamicSearchRuleQuery.phpsrc/Endpoints/AGENTS.mdsrc/Endpoints/Delegates/HandlesDynamicSearchRules.phpsrc/Endpoints/DynamicSearchRules.phptests/Contracts/DynamicSearchRuleTest.phptests/Contracts/DynamicSearchRulesQueryTest.phptests/Contracts/DynamicSearchRulesResultsTest.phptests/Contracts/UpdateDynamicSearchRuleQueryTest.phptests/Endpoints/DynamicSearchRulesTest.php
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Contracts/DynamicSearchRulesFilter.php`:
- Around line 39-44: Add a reusable PHPStan type alias for the filter payload
inside the DynamicSearchRulesFilter contract (e.g., declare /** `@phpstan-type`
DynamicSearchRulesFilterPayload array{attributePatterns?:
list<non-empty-string>, active?: bool} */ above the class) and then replace the
duplicated anonymous shape in DynamicSearchRulesQuery by importing that alias
with /** `@phpstan-import-type` DynamicSearchRulesFilterPayload from
DynamicSearchRulesFilter */; update the toArray() docblock in
DynamicSearchRulesFilter to reference the named alias and remove the duplicated
shape from DynamicSearchRulesQuery so both files use
DynamicSearchRulesFilterPayload.
🪄 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: 50a3e36e-79eb-4096-95f1-1c4449e9c869
📒 Files selected for processing (3)
src/Contracts/DynamicSearchRulesFilter.phpsrc/Contracts/DynamicSearchRulesQuery.phpsrc/Endpoints/DynamicSearchRules.php
✅ Files skipped from review due to trivial changes (1)
- src/Contracts/DynamicSearchRulesQuery.php
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Endpoints/DynamicSearchRules.php
Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>
Pull Request
Related issue
Fixes #904
What does this PR do?
AGENTS.mdAI disclosure
Cursor with
gpt-5.5-medium, andgpt-5.3-codex-medium.PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!
Summary by CodeRabbit
New Features
Documentation
Tests
Chores