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
Searchindex

Searchindex Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Store and retrieve objects from Algolia or Elasticsearch

Frequently asked questions about Searchindex
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.
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