Skip to main content
You can search for documents in your Algolia with a single line of code. The search method queries Algolia for matching results and returns an array of Doctrine-managed objects (ORM entities or ODM documents). The objects are loaded from your database through the Doctrine Manager you pass in.
Both SearchService and Doctrine\Persistence\ManagerRegistry must be injected into your class, so that you can use $this->searchService and $this->managerRegistry.
PHP
$em = $this->managerRegistry->getManagerForClass(Post::class);

$posts = $this->searchService->search($em, Post::class, 'query');
The search method only retrieves a list of IDs from the engine and uses them to hydrate the corresponding Doctrine objects from your database. You can only pass parameters to modify what to search, not modify the type of response. If you want to modify the attributes to retrieve or retrieve data like facets, facets_stats, or _rankingInfo, use the rawSearch method.

Request options

The search and write methods in SearchService take a $requestOptions array as their last argument. For search(), rawSearch(), and count(), any top-level keys that aren’t HTTP options become search parameters sent to Algolia, for example, to change the page, filter the results, or choose what attributes to retrieve. You can find all possibilities in the list of search API parameters. For write methods (index(), remove(), clear(), delete()), $requestOptions is passed directly to the PHP client, so only supported request-option keys (such as headers, queryParameters, and timeouts) apply.
PHP
$em = $this->managerRegistry->getManagerForClass(Post::class);

$posts = $this->searchService->search($em, Post::class, 'query', [
    'page' => 0,
    'hitsPerPage' => 10,
    'filters' => 'comment_count>10',
]);
If you want to get the raw results from Algolia, use the rawSearch method. This is the method you’ll need to use if you want to retrieve the highlighted snippets or ranking information for instance. It takes a $requestOptions array as an optional last parameter.
PHP
$posts = $this->searchService->rawSearch(Post::class, 'query');

$posts = $this->searchService->rawSearch(Post::class, 'query', [
    'page' => 0,
    'hitsPerPage' => 10,
    'filters' => 'comment_count>10'
    // ...
]);
The difference with the search method is that you won’t retrieve Doctrine-managed objects, but a PHP associative array containing the raw engine response.

Count

Use this method when you only need the number of results for a query. count still triggers a search request.
PHP
$posts = $this->searchService->count(Post::class, 'query');

Clear

The clear method deletes the in an index without affecting its settings. It takes the class name associated with an index and, optionally, $requestOptions as the last parameter. This method is waitable.
PHP
$posts = $this->searchService->clear(Post::class);

$posts = $this->searchService->clear(Post::class, [
    // ..any request options
]);

$posts = $this->searchService->clear(Post::class)->wait();

Delete

Delete an index and all its settings, including links to its replicas. It takes the class name associated with an index and, optionally, $requestOptions as the last parameter. This method is waitable as well.
PHP
$posts = $this->searchService->delete(Post::class);

$posts = $this->searchService->delete(Post::class, [
    // ..any request options
]);

$posts = $this->searchService->delete(Post::class)->wait();
Last modified on April 27, 2026