The SearchBundle now uses the Algolia PHP API Client v4. This is a significant upgrade of the underlying SDK that introduces a few breaking changes.
Upgrade your algolia/search-bundle dependency to ^8.1 in your composer.json file and run composer update algolia/search-bundle algolia/algoliasearch-client-php in your terminal.
The SearchClient class has moved to a new namespace. If you inject or type-hint SearchClient in your own services, update the fully qualified class name.
Before:
use Algolia\AlgoliaSearch\SearchClient;
After:
use Algolia\AlgoliaSearch\Api\SearchClient;
The bundle's DI alias has been updated accordingly:
Before:
services: App\Service\MyService: arguments: $client: '@Algolia\AlgoliaSearch\SearchClient'
After:
services: App\Service\MyService: arguments: $client: '@Algolia\AlgoliaSearch\Api\SearchClient'
If you autowire by type-hint, update your constructor or method signatures:
Before:
public function __construct(\Algolia\AlgoliaSearch\SearchClient $client) {}
After:
public function __construct(\Algolia\AlgoliaSearch\Api\SearchClient $client) {}
In v3, custom HTTP headers could be passed as flat top-level keys in $requestOptions. In v4, flat keys are silently ignored. HTTP headers must be nested under the headers key.
Before:
$searchService->index($em, $entity, ['X-Forwarded-For' => '0.0.0.0']);
After:
$searchService->index($em, $entity, [ 'headers' => ['X-Forwarded-For' => '0.0.0.0'], ]);
This applies to all SearchService methods that accept $requestOptions: index(), remove(), clear(), delete(), search(), rawSearch(), and count().
The recognized top-level keys for $requestOptions in v4 are:
headers— Custom HTTP headers (associative array)queryParameters— Extra URL query parameters (associative array)body— Extra body parameters (associative array)readTimeout— Read timeout in milliseconds (int)writeTimeout— Write timeout in milliseconds (int)connectTimeout— Connection timeout in milliseconds (int)
In v3, SearchServiceResponse::wait() accepted $requestOptions to customize the wait behavior (e.g. timeout). In v4, waiting is handled internally by the SDK's SearchClient::waitForTask() method and no longer accepts parameters.
Before:
$response = $searchService->index($em, $entities); $response->wait(['readTimeout' => 30]);
After:
$response = $searchService->index($em, $entities); $response->wait();
SearchServiceResponse was a subclass of the SDK's Algolia\AlgoliaSearch\Response\AbstractResponse in v3. That class no longer exists in v4. SearchServiceResponse is now a standalone class in the bundle's own namespace.
If you type-hint or instanceof check against AbstractResponse, update your code:
Before:
use Algolia\AlgoliaSearch\Response\AbstractResponse; if ($response instanceof AbstractResponse) { ... }
After:
use Algolia\SearchBundle\Responses\SearchServiceResponse; if ($response instanceof SearchServiceResponse) { ... }
| 8.0.0 | Breaking Change | 8.1.0 |
|---|---|---|
Algolia\AlgoliaSearch\SearchClient |
Moved | Algolia\AlgoliaSearch\Api\SearchClient |
Algolia\AlgoliaSearch\Response\AbstractResponse |
Removed | Algolia\SearchBundle\Responses\SearchServiceResponse (no longer a base class) |
Algolia\AlgoliaSearch\Response\IndexingResponse |
Removed | Algolia\SearchBundle\Responses\EngineResponse |
Algolia\AlgoliaSearch\Response\BatchIndexingResponse |
Removed | Handled internally by SearchServiceResponse |
Algolia\AlgoliaSearch\Response\NullResponse |
Removed | Algolia\SearchBundle\Responses\NullResponse |
Algolia\AlgoliaSearch\Support\UserAgent |
Removed | Algolia\AlgoliaSearch\Support\AlgoliaAgent |
| 8.0.0 | Breaking Change | 8.1.0 |
|---|---|---|
Algolia\AlgoliaSearch\SearchClient (autowiring alias) |
Renamed | Algolia\AlgoliaSearch\Api\SearchClient |