spatie/searchindex
Opinionated Laravel package to index and search objects via a unified API. Supports Elasticsearch and Algolia, with simple upsert and query methods for any model implementing the Searchable interface.
Searchable interface enforces a clean contract for indexable models, reducing boilerplate. However, this may limit flexibility for non-standard use cases.observers or model events must be manually configured to sync index updates with DB changes).Searchable interface and SearchIndex facade may make migration to alternative solutions (e.g., Meilisearch, Typesense) costly.Searchable interface conflict with existing model traits/interfaces?spatie/laravel-search, scout-apm/scout) with better support?SearchIndex::upsertToIndex() in a job).created, updated, deleted model events triggering index updates).Product) and test basic search.LIKE queries) with SearchIndex::getResults().Facade::class usage).search vs. instantsearch).Searchable interface or extend SearchableModel trait.toSearchableArray() for indexing fields.// app/Observers/ProductObserver.php
public function saved(Product $product) {
SearchIndex::upsertToIndex($product);
}
SearchIndex::getResults().spatie/laravel-search).GET /index_name/_mapping).SearchIndex::getResults(..., ['per_page' => 20])) and caching (e.g., Redis for frequent queries).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Search backend downtime | Broken search functionality | Fallback to DB queries or cached results. |
| Queue worker failures | Stale index data | Retry logic + dead-letter queue for failed jobs. |
| Elasticsearch cluster failure | Unavailable search | Multi-AZ deployment or Algolia as backup. |
| Algolia API throttling | Slow/failed queries | Implement exponential backoff; use local cache. |
| Large index size | Slow queries, high costs | Archive old data; optimize mappings (e.g., keyword vs. text fields). |
| Schema changes | Broken index mappings | Versioned indices; reindexing scripts. |
How can I help you explore Laravel packages today?