- How do I integrate this Algolia PHP client with Laravel Scout for basic search?
- Use the `algolia/scout-extended` package alongside this client. Install both via Composer, then configure Scout’s `algolia.php` with your Algolia credentials. The official client handles low-level API calls while Scout manages Eloquent model synchronization. For advanced features like recommendations, extend Scout with custom Composition API calls via the client’s `composition()` method.
- What Laravel versions are supported by this Algolia client?
- The client requires PHP 8.0+, which aligns with Laravel 8.x and later. No Laravel-specific dependencies exist, so it works with any Laravel version meeting the PHP requirement. For older Laravel apps, ensure your PHP version is updated to 8.0+ before installation.
- Can I use this client for real-time indexing without Laravel Scout?
- Yes. Use the `SearchClient` to manually index models via events (e.g., `ModelSaved`) or queues. For example, trigger `client->saveObject()` in a listener or queue job. The client’s thin design makes it lightweight for custom workflows, though Scout simplifies Eloquent integration.
- How does the Composition API’s `feedsOrder` work in Laravel, and when should I use it?
- `feedsOrder` prioritizes data sources (e.g., user personalization, popularity) in Composition API runs. Use it for hybrid search (e.g., blending recommendations with search results). In Laravel, pass it via `client->composition()->run()` with a user token tied to `Auth::user()`. Ideal for apps needing dynamic ranking, like e-commerce or social feeds.
- Will this client work with Laravel’s queue system for bulk indexing?
- Absolutely. Offload indexing tasks to Laravel queues (e.g., `algolia:index`) using the client’s `saveObject()` or `partialUpdateObject()` methods. The `push` helper (PR #6247) mitigates rate-limiting during bulk operations, ensuring reliability. Test with `queue:work` to benchmark throughput.
- Are there alternatives to this client for Laravel Algolia integration?
- For basic search, `algolia/scout-extended` is a Laravel-specific wrapper. For advanced features like Composition API, this official client is the only PHP option. Third-party libraries (e.g., `spatie/laravel-search`) may offer simpler abstractions but lack Composition API support. Choose this client for full Algolia feature access.
- How do I handle errors when the Composition API fails in production?
- Implement graceful fallbacks. Wrap Composition API calls in try-catch blocks and log failures. For critical apps, cache results or fallback to basic search (e.g., `client->search()`). Algolia’s API returns HTTP status codes; use these to trigger retries or degrade functionality (e.g., hide recommendations).
- Does this client support polymorphic Eloquent models for indexing?
- Yes, but ensure proper serialization. The client’s `OperationIndexParams` fixes edge cases (PR #6287) for complex models. For polymorphic relationships, flatten JSON attributes or use `attributesToIndex` in Scout’s configuration. Test with `dd($model->toSearchableArray())` to debug serialization issues.
- How can I test Composition API features locally before deploying to Laravel?
- Use Algolia’s local testing environment (e.g., `algolia/algoliasearch-client-php` with mock credentials). Test `feedsOrder` and recommendations by simulating user tokens. For Laravel, mock `Auth::user()` in PHPUnit and verify responses with `assertEquals()`. Validate edge cases like empty feeds or concurrent writes.
- What are the cost implications of using Composition API in Laravel?
- Composition API features (e.g., recommendations) may increase Algolia’s usage-based pricing. Audit the [Algolia pricing calculator](https://www.algolia.com/pricing) for hybrid search workloads. Monitor API calls via the Algolia dashboard and set budget alerts. For cost-sensitive apps, limit Composition API usage to high-value features (e.g., product recommendations).