- How do I install spatie/searchindex in a Laravel 5.1 project?
- Run `composer require spatie/searchindex` in your Laravel 5.1 project. The package includes a service provider and facade, so no additional configuration is needed beyond requiring the package. Ensure your models implement the `Searchable` interface for indexing.
- Does spatie/searchindex work with Laravel 8/9/10, or is it limited to 5.1?
- The package was built for Laravel 5.1 and lacks official support for newer versions. While it *might* work with minimal tweaks, compatibility isn’t guaranteed—especially for features like dependency injection or service providers. Test thoroughly before adoption.
- Can I use this package with Eloquent models without extra setup?
- Yes, but your Eloquent models must implement the `Searchable` interface. The package provides a trait (`SearchableTrait`) to simplify this. For non-Eloquent objects, ensure they adhere to the interface contract (e.g., `toSearchableArray()` method).
- How do I keep my search index in sync with database changes?
- You’ll need to manually trigger index updates via `SearchIndex::upsertToIndex($model)` during model events (e.g., `created`, `updated`, `deleted`). For large-scale apps, use Laravel queues to avoid blocking requests. There’s no built-in observer integration.
- What’s the difference between Elasticsearch and Algolia support in this package?
- Both backends are supported via the same API, but Elasticsearch requires self-hosting (or a cloud provider like AWS OpenSearch) and offers advanced features like custom analyzers. Algolia is fully managed but operates on a pay-per-query model, which may inflate costs at scale.
- Can I add custom fields or filters to my search queries?
- Basic search is supported via `getResults()`, but advanced Elasticsearch features (e.g., faceting, aggregations, or custom analyzers) require manual configuration outside the package. Algolia’s API is more limited but simpler for basic use cases.
- Is this package actively maintained? Should I use it for production?
- The last release was in 2017, and there’s no indication of ongoing maintenance. While functional, it carries risks for production—especially with Laravel’s evolving ecosystem. Consider alternatives like `spatie/laravel-search` or `scout-apm/scout` for newer Laravel versions.
- How do I handle pagination or large result sets with this package?
- The `getResults()` method supports pagination via `paginate()` or `cursor()`, but performance depends on your backend. For Elasticsearch, ensure proper sharding and indexing. Algolia handles pagination natively but may throttle high-volume requests.
- Are there alternatives to spatie/searchindex for Laravel 8+ with better support?
- Yes. For Laravel 8+, consider `spatie/laravel-search` (Elasticsearch-focused), `scout-apm/scout` (multi-backend), or `meilisearch/meilisearch-php` (Meilisearch integration). These packages align with modern Laravel practices and offer active maintenance.
- How do I test search functionality in my Laravel app with this package?
- Mock the `SearchIndex` facade in tests and verify `upsertToIndex()` and `getResults()` calls. Use in-memory backends (e.g., Elasticsearch’s local node or Algolia’s sandbox) for integration tests. Avoid testing against production search services in CI.