Skip to content

Conversation

@tw2066
Copy link

@tw2066 tw2066 commented Dec 5, 2025

Pull Request

Update search and rawSearch methods to use SearchQuery

Summary by CodeRabbit

  • New Features
    • Search and raw search methods now accept SearchQuery objects in addition to arrays, providing increased flexibility when specifying search parameters.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 5, 2025

Walkthrough

Modified search-related methods in Indexes.php to accept SearchQuery objects in addition to arrays as search parameters. The rawSearch method includes conversion logic to transform SearchQuery objects to arrays before processing. Added missing SearchQuery import.

Changes

Cohort / File(s) Summary
Type signature widening for search methods
src/Endpoints/Indexes.php
Updated search() and rawSearch() method signatures to accept SearchQuery|array instead of array for search parameters. Added SearchQuery import. Implemented conversion logic in rawSearch() to transform SearchQuery objects to arrays via instanceof check and toArray() call.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

  • Verify SearchQuery::toArray() method exists and returns expected array structure
  • Confirm type union syntax is correctly recognized by the PHP version in use
  • Ensure backward compatibility with existing array-based callers

Poem

A rabbit hops through query gates,
Where SearchQuery joins array's mates,
Two paths now lead to the same delight,
Conversion whispers, "Everything's right!" 🐰✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: widening the search and rawSearch method parameters to accept SearchQuery objects alongside arrays.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/Endpoints/Indexes.php (2)

191-203: Widened search() parameter type is BC‑safe and consistent

Accepting SearchQuery|array for $searchParams while delegating normalization to rawSearch() cleanly extends the API without breaking existing array callers. Consider adding a brief phpdoc @param SearchQuery|array $searchParams for tools that still lean on annotations, but that’s optional.


205-212: Confirm intended precedence between $query and SearchQuery::q

Normalizing $searchParams with instanceof SearchQuery is correct and keeps rawSearch() working for both arrays and objects. Note that with:

$parameters = array_merge(['q' => $query], $searchParams);

a q key coming from SearchQuery::toArray() will override the $query argument when both are set. If you instead want the explicit $query parameter to always win, you could swap the merge order:

-        $parameters = array_merge(
-
-            ['q' => $query],
-            $searchParams
-        );
+        $parameters = array_merge(
+            $searchParams,
+            ['q' => $query],
+        );

Please confirm which behavior you intend.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 565bca2 and 884bf61.

📒 Files selected for processing (1)
  • src/Endpoints/Indexes.php (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Endpoints/Indexes.php (1)
src/Contracts/SearchQuery.php (2)
  • SearchQuery (7-495)
  • toArray (463-494)
🔇 Additional comments (1)
src/Endpoints/Indexes.php (1)

13-13: Importing SearchQuery matches the new method signatures

The added use Meilisearch\Contracts\SearchQuery; cleanly supports the new union-typed parameters without redundancy.

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.

1 participant