- How do I replace Laravel Scout with Meilisearch PHP in my existing app?
- Start by installing the package via Composer (`meilisearch/meilisearch-php`). Replace Scout’s search logic with Meilisearch’s `Index` class, then sync model events (e.g., `saved()`) to trigger index updates via Laravel queues. Use a facade or service container to centralize Meilisearch client access. Test with a non-critical index first before full migration.
- What Laravel versions and PHP requirements does Meilisearch PHP support?
- Meilisearch PHP v2.x requires Laravel 8+ and PHP 8.0+. For older Laravel versions, use v1.x of the package. Always check the [Meilisearch PHP documentation](https://php-sdk.meilisearch.com) for version-specific notes, as newer features may require updates to your Meilisearch server (v1.37+ recommended).
- Can I use Meilisearch PHP with Meilisearch Cloud instead of self-hosted?
- Yes, the package works identically with Meilisearch Cloud. Just replace your self-hosted server URL with your Cloud instance’s endpoint (e.g., `https://your-instance.meilisearch.io`). Cloud handles scaling and maintenance, while self-hosted gives you full control over data and costs. Both support the same API features.
- How do I handle large datasets during initial indexing in Laravel?
- Use Laravel queues to batch index updates. Dispatch queued jobs (e.g., `UpdateMeilisearchIndex`) from model observers or console commands. For massive datasets, consider a two-phase approach: index a subset first, then migrate the rest incrementally. Monitor queue workers to avoid timeouts, and use Meilisearch’s bulk API for efficiency.
- What HTTP clients does Meilisearch PHP support, and how do I customize them?
- The package supports Guzzle, Symfony HTTP Client, and custom PSR-18 clients. Configure your preferred client via the `HttpClient` class or dependency injection. For example, pass a Guzzle client instance to the Meilisearch client constructor. This flexibility helps optimize performance or integrate with existing Laravel HTTP stacks.
- How can I cache search results in Laravel to reduce Meilisearch load?
- Leverage Laravel’s cache (Redis, Memcached) to store frequent search queries. Use `Cache::remember()` with a key like `'search:query'` and a short TTL (e.g., 5 minutes). For dynamic queries, cache partial results or use Meilisearch’s built-in caching. This reduces API calls but requires invalidating cache when indexes update.
- What happens if Meilisearch goes down? Can I implement a fallback?
- Design a fallback by caching search results or implementing a degraded mode (e.g., database search or static responses). Use Laravel’s `try-catch` blocks around Meilisearch calls and log failures. For critical apps, consider a multi-search backend with feature flags to toggle between Meilisearch and a secondary search system.
- Are there performance benchmarks for Meilisearch PHP vs. Scout/Algolia?
- Meilisearch excels in typo tolerance and real-time updates, often outperforming Scout’s database-based search. Benchmarks show Meilisearch handles complex queries faster than Algolia for smaller datasets but may require tuning for large-scale apps. Test with your specific data volume and query patterns—use Laravel’s `benchmark()` helper to compare execution times.
- How do I sync Eloquent model changes to Meilisearch in real time?
- Use Eloquent observers or model events (e.g., `saved()`, `deleted()`) to trigger queued jobs that update Meilisearch. For example, dispatch `UpdateMeilisearchIndex` with the model ID. Alternatively, use Laravel’s `Model::updating` event to batch updates. Ensure your indexing logic handles soft deletes and model relationships correctly.
- What alternatives exist if Meilisearch PHP doesn’t fit my needs?
- For Laravel, consider Scout (database search), Algolia (cloud-based), or Elasticsearch (self-hosted). If you need a lightweight alternative, try Laravel’s built-in database full-text search or packages like `spatie/laravel-searchable`. Meilisearch stands out for its open-source nature, typo tolerance, and ease of self-hosting, but evaluate your app’s specific needs for scalability and cost.