jeroen-g/explorer
Laravel-friendly wrapper for Explorer, a lightweight full-text search engine. Index and search your Eloquent models with simple configuration, fast queries, and flexible ranking/filters. Ideal for adding on-site search without running Elasticsearch or Algolia.
Strengths:
Searchable) and Scout’s query builder.Explored interface, FakeResponse for testing) aligns with modern Laravel best practices and enables testability.Fit for Use Cases:
author.name) is needed.Term queries for categories).Gaps:
geo_aggregations). Requires custom SyntaxInterface implementations.toSearchableArray() optimizations.Laravel Compatibility:
meilisearch or algolia drivers, migration is straightforward.use Searchable and optionally Explored interface or publish config for mappings.where() with Explorer’s filter(), must(), etc., but retains Laravel’s cursor()/paginate() methods.Elasticsearch Version:
keyword vs. text field handling in mappings).mappableAs()) are recommended to avoid Elasticsearch’s dynamic inference pitfalls (e.g., date vs. string conflicts).Testing Support:
FakeResponse mocks Elasticsearch API calls, enabling unit tests without a live cluster. Example in docs shows integration with Laravel’s instance() mocking.post('api/search')) with mocked responses.'driver' => 'explorer').Engine or Builder classes, refactor to use Explorer’s SyntaxInterface or query properties.author.tags.subtags) may degrade performance. Monitor query execution time via Elasticsearch’s _explain API.from/size pagination is inefficient for deep pagination. Use search_after or scroll APIs for large datasets (Explorer doesn’t expose these natively; may need custom syntax).mappableAs() or config requires reindexing. Use aliases (prune_old_aliases: false) during development to preserve old indices.SyntaxInterface.FakeResponse for unit tests and integrate Elasticsearch’s _validate/query API in deployment pipelines.profile: true or APM.elasticsearch driver. Replace config/scout.php:
'driver' => 'explorer',
date vs. date_nanos).client configuration.FakeResponse replaces Elasticsearch HTTP calls. Store mock responses in tests/Support/Elastic/Responses/.ElasticClientFactory to simulate API responses (as shown in docs).ScoutEngine extensions) that may need refactoring.mappableAs() or config to match Explorer’s syntax.composer require jeroen-g/explorer laravel/scout:"^8.0"
php artisan vendor:publish --tag=explorer.config
config/explorer.php with your indexes and mappings.use Searchable to models. Implement Explored interface or use config-based mappings.class Post extends Model implements Explored {
use Searchable;
public function mappableAs(): array {
return ['title' => 'text', 'published_at' => 'date'];
}
}
where() with Explorer’s filter()/must():
// Before (Scout)
Post::search('query')->where('published', true)->get();
// After (Explorer)
Post::search('query')->filter(new Term('published', true))->get();
Post::search('query')->must(new Nested('author', new Matching('author.name', 'John')))->get();
FakeResponse-based unit tests for critical queries.ElasticClientFactory.scout:import or Explorer’s alias system:
php artisan scout:import "App\Models\Post"
'prune_old_aliases' => env('APP_ENV') !== 'production',
Searchable trait.keyword vs. text in mappings).Builder or Engine, refactor to use Explorer’s SyntaxInterface or query properties.ScoutEngine to a SyntaxInterface implementation.Post, Product) to validate Explorer’s performance and query behavior._explain API.keyword vs. text) based on query patterns.How can I help you explore Laravel packages today?