Make Scout models trait-only - #468
Conversation
Treat the Searchable trait as the application-facing model contract while keeping SearchableInterface as an internal static-analysis shape. Widen public engine, command, job, event, and collection boundaries to ordinary Eloquent models, then narrow only where Scout capabilities are consumed. This removes the need for application models to implement an extra interface and keeps the API aligned with Laravel Scout. Preserve collection types through model hooks, remove redundant callback annotations, and make intentional loose Scout-key matching explicit where search services serialize numeric keys as strings.
Convert Scout's application-model fixtures to use the Searchable trait without implementing the internal interface. Update engine mocks and scope/coroutine coverage around the widened model boundaries. Keep the Typesense removable-collection regression discriminating by mocking the stored key separately from the model's live Scout key.
Update the Scout and search documentation to show the Laravel-style model setup: extend Eloquent Model and use the Searchable trait. Remove the internal interface from application examples and explain that the trait supplies the complete model capability used by Scout.
|
Warning Review limit reached
Next review available in: 48 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughScout now documents searchable models through the ChangesScout contract and typing updates
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Greptile SummaryThis PR makes Scout models searchable through the
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/scout/src/Searchable.php | Preserves the trait’s runtime behavior while refining collection/query annotations and strict membership checks. |
| src/scout/src/Contracts/SearchableInterface.php | Recasts the interface as an internal searchable-model shape and widens engine-facing collection annotations. |
| src/scout/src/Builder.php | Widens the public model generic while retaining a local intersection annotation where Scout methods are consumed. |
| src/scout/src/SearchableScope.php | Narrows models locally before invoking searchable behavior and retains import event dispatch for complete chunks. |
| src/scout/src/Jobs/RemoveableScoutCollection.php | Detects trait-only searchable models during queued-removal serialization and preserves their Scout keys. |
| src/scout/src/Jobs/RemoveFromSearch.php | Continues restoring lightweight model instances keyed for deletion from external search engines. |
| src/scout/src/Engines/Engine.php | Widens the abstract engine API to Eloquent models so trait-only models satisfy public boundaries. |
| src/scout/src/Engines/AlgoliaEngine.php | Adapts engine annotations for trait-only models and explicitly supports numeric key representation differences. |
| src/scout/src/Engines/MeilisearchEngine.php | Adapts update, deletion, mapping, and flush paths to widened model boundaries. |
| src/scout/src/Engines/TypesenseEngine.php | Preserves searchable capability at consumption sites while accepting model-typed collections. |
| src/scout/src/Engines/CollectionEngine.php | Preserves transformed searchable collections and handles key representation differences during mapping. |
| src/scout/src/Engines/DatabaseEngine.php | Applies strict comparisons and widens no-op indexing boundaries without changing database search behavior. |
Reviews (2): Last reviewed commit: "Use the imported model in Scout annotati..." | Re-trigger Greptile
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/scout/src/Contracts/SearchableInterface.php (1)
21-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse the imported
Modelalias in the PHPDoc directive.
Modelis already imported on Line 10. Replace the fully qualified class name on Line 21 withModel.Proposed fix
- * `@phpstan-require-extends` \Hypervel\Database\Eloquent\Model + * `@phpstan-require-extends` ModelAs per coding guidelines, import classes with
usestatements instead of referencing fully qualified class names.🤖 Prompt for 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. In `@src/scout/src/Contracts/SearchableInterface.php` at line 21, Update the `@phpstan-require-extends` directive in SearchableInterface to reference the existing imported Model alias instead of the fully qualified Hypervel\Database\Eloquent\Model name.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@src/scout/src/Contracts/SearchableInterface.php`:
- Line 21: Update the `@phpstan-require-extends` directive in SearchableInterface
to reference the existing imported Model alias instead of the fully qualified
Hypervel\Database\Eloquent\Model name.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4666e7bb-6f12-4606-abdd-9807f43f415e
📒 Files selected for processing (39)
src/boost/docs/scout.mdsrc/boost/docs/search.mdsrc/scout/src/Builder.phpsrc/scout/src/Console/IndexCommand.phpsrc/scout/src/Console/QueueImportCommand.phpsrc/scout/src/Console/SyncIndexSettingsCommand.phpsrc/scout/src/Contracts/SearchableInterface.phpsrc/scout/src/Engines/AlgoliaEngine.phpsrc/scout/src/Engines/CollectionEngine.phpsrc/scout/src/Engines/DatabaseEngine.phpsrc/scout/src/Engines/Engine.phpsrc/scout/src/Engines/MeilisearchEngine.phpsrc/scout/src/Engines/TypesenseEngine.phpsrc/scout/src/Events/ModelsFlushed.phpsrc/scout/src/Events/ModelsImported.phpsrc/scout/src/Jobs/MakeSearchable.phpsrc/scout/src/Jobs/RemoveFromSearch.phpsrc/scout/src/Jobs/RemoveableScoutCollection.phpsrc/scout/src/ModelObserver.phpsrc/scout/src/Scout.phpsrc/scout/src/Searchable.phpsrc/scout/src/SearchableScope.phpsrc/scout/src/Traits/UniqueByScoutKeys.phptests/Scout/Feature/CoroutineSafetyTest.phptests/Scout/Feature/SearchableScopeTest.phptests/Scout/Models/ConditionalSearchableModel.phptests/Scout/Models/ConfigBasedTypesenseModel.phptests/Scout/Models/CustomScoutKeyModel.phptests/Scout/Models/FilteringSearchableModel.phptests/Scout/Models/PrefixSearchableModel.phptests/Scout/Models/SearchableModel.phptests/Scout/Models/SoftDeletableSearchableModel.phptests/Scout/Models/SoftDeleteSearchableModel.phptests/Scout/Models/TypesenseSearchableModel.phptests/Scout/Models/TypesenseSoftDeleteSearchableModel.phptests/Scout/Models/UuidSearchableModel.phptests/Scout/Unit/Engines/AlgoliaEngineTest.phptests/Scout/Unit/Engines/MeilisearchEngineTest.phptests/Scout/Unit/Engines/TypesenseEngineTest.php
Reference the existing Model import in the SearchableInterface PHPStan requirement. This keeps the internal contract consistent with repository import conventions without changing its behavior or type meaning.
Summary
This changes Scout so Eloquent models opt into search by using the Searchable trait alone. Applications no longer need to implement SearchableInterface.
This matches Laravel Scout model ergonomics while preserving Hypervel static analysis and coroutine safety.
Problem
Searchable already provides the full application-facing model behavior. Requiring models to also implement SearchableInterface exposes an internal typing detail and makes ordinary Scout setup more verbose than Laravel.
The interface was also used as a public generic bound across builders, engines, jobs, events, and collections. That made collection invariance difficult to express and pushed internal capability annotations into application boundaries.
Implementation
Existing models that explicitly implement SearchableInterface continue to work. Search indexing and query behavior do not otherwise change.
Verification
The full formatting, static-analysis, parallel test, Testbench, and dogfood gates pass. Focused Scout engine, scope, and coroutine tests also pass.
Summary by CodeRabbit
New Features
Searchabletrait without explicitly declaring an additional interface.Bug Fixes
Documentation