Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Scout Database Engine Laravel Package

lunarphp/scout-database-engine

Database-backed Laravel Scout engine for Lunar PHP. Adds lightweight full‑text style searching without external services, indexing your models into SQL tables for fast local search in development and smaller deployments.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install: composer require lunarphp/scout-database-engine
  2. Configure Scout: In config/scout.php, set driver to database:
    'driver' => env('SCOUT_DRIVER', 'database'),
    
  3. Publish config (optional): php artisan vendor:publish --tag=scout-config to inspect defaults (mostly unchanged, just ensures driver=database).
  4. First use: Make sure your searchable model uses Lunarphp\ScoutDatabaseEngine\Traits\SearchableTrait and defines toSearchableArray(). Then run:
    php artisan scout:import "App\Models\YourModel"
    
    Search via YourModel::search('query')->get().

Implementation Patterns

  • Indexing strategy:

    • Override toSearchableArray() in your model to control which columns/indexes are built (e.g., combine title + content into a single body string for better relevance).
    • Leverage Scout’s queue option (Config::set('scout.queue', true)) for background indexing during sync operations.
    • Use withoutSyncingToSearch() for bulk operations (e.g., seeding, migrations) to avoid overhead.
  • Searching patterns:

    • Use Scout’s high-level API: Model::search('term')->where('status', 'published')->get().
    • Filter on indexed columns only—non-indexed fields won’t be searched or filtered reliably.
    • Combine multiple search constraints with where() and orWhere() (e.g., for tag-based filtering).
  • Scaling locally: For dev environments, this engine avoids complex local Docker setups (Elasticsearch, etc.), enabling consistent search behavior across local, staging, and CI without external services.

Gotchas and Tips

  • Full-text limitations: Only uses MySQL LIKE %term% and MATCH ... AGAINST (for MyISAM/InnoDB) depending on config—not for production-scale relevance ranking. Avoid complex regex or accent-insensitive queries without DB-specific tweaks.
  • Index column limits: ScoutDatabaseEngine indexes only what’s returned from toSearchableArray(). If you forget to include a column there, filtering/sorting on it won’t work as expected.
  • Case sensitivity: On MySQL, case-insensitivity depends on collation (e.g., utf8mb4_general_ci). Use lower() in toSearchableArray() if you want strict case normalization.
  • Performance caveats:
    • Large tables: Add DB-level indexes on indexed columns used in where()/orderBy() after syncing.
    • sync indexing (default) blocks requests until indexed—consider queue + scout:import for large datasets.
  • Debugging: Enable Scout logging (LOG_LEVEL=debug + SCOUT_LOG=true) to see raw SQL queries generated (check storage/logs).
  • Extension point: Override toDatabaseSearchString() in your model for custom query logic (e.g., MySQL-specific REGEXP, or JSON path extraction).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport