Basic search
You can search for documents in your Algolia index with a single line of code. Thesearch
method queries Algolia to get matching results and creates a doctrine collection.
The data is pulled from the database, which is why you need to pass the Doctrine Manager.
The
SearchService
must be injected into your class,
so that you can use $this->searchService
.PHP
search
method only retrieves a list of IDs from the engine and uses them
to create a collection of Doctrine entities.
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
All methods in theSearchService
take a $requestOptions
array as the last argument.
This lets you pass any search parameters and optional arguments to Algolia.
With this parameters you can influence any of your operations.
For example, you can change the number of results to retrieve,
fetch a precise page, filter the results, or choose what attributes to retrieve.
You can find all possibilities in the list of search API parameters
PHP
Raw search
If you want to get the raw results from Algolia, use therawSearch
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
search
method is that you won’t retrieve Doctrine Entities,
but a JSON object.
Count
Use this method if you need to know quickly how many results are returned by your query. This still triggers a search.PHP
Clear
Theclear
method is used to delete the records of an index without affecting its settings.
It takes an index name or the class name related to an index,
and optionally $requestOptions
as the last parameter.
This method is waitable.
PHP
Delete
Delete an index and all its settings, including links to its replicas. It takes an index name or the class name related to an index, and optionally$requestOptions
as the last parameter.
This method is waitable as well.
PHP