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.
composer require lunarphp/scout-database-engineconfig/scout.php, set driver to database:
'driver' => env('SCOUT_DRIVER', 'database'),
php artisan vendor:publish --tag=scout-config to inspect defaults (mostly unchanged, just ensures driver=database).Lunarphp\ScoutDatabaseEngine\Traits\SearchableTrait and defines toSearchableArray(). Then run:
php artisan scout:import "App\Models\YourModel"
Search via YourModel::search('query')->get().Indexing strategy:
toSearchableArray() in your model to control which columns/indexes are built (e.g., combine title + content into a single body string for better relevance).queue option (Config::set('scout.queue', true)) for background indexing during sync operations.withoutSyncingToSearch() for bulk operations (e.g., seeding, migrations) to avoid overhead.Searching patterns:
Model::search('term')->where('status', 'published')->get().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.
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.toSearchableArray(). If you forget to include a column there, filtering/sorting on it won’t work as expected.utf8mb4_general_ci). Use lower() in toSearchableArray() if you want strict case normalization.where()/orderBy() after syncing.sync indexing (default) blocks requests until indexed—consider queue + scout:import for large datasets.LOG_LEVEL=debug + SCOUT_LOG=true) to see raw SQL queries generated (check storage/logs).toDatabaseSearchString() in your model for custom query logic (e.g., MySQL-specific REGEXP, or JSON path extraction).How can I help you explore Laravel packages today?