Documentation Index
Fetch the complete documentation index at: https://algolia.com/llms.txt
Use this file to discover all available pages before exploring further.
Indexing data
You have to define the entities that should be indexed to Algolia. You can do this by adding the entities to your configuration file, under thealgolia_search.indices key.
Each entry under the indices key must contain the following attributes:
nameis the canonical name of the index in Algoliaclassis the full class reference of the entity to index
YAML
enable_serializer_groups
Before sending your data to Algolia, each entity is converted to an array using the Symfony built-in serializer.
This option lets you define which attributes to index using the #[Groups(['searchable'])] attribute.
For more information, see Normalizers.
Example:
YAML
Batching
By default, calls to Algolia for indexing or removing data are batched per 500 items. You can modify the batch size in your configuration.YAML
batchSize value.
JMS serializer
The bundle also provides basic support for the JMS serializer. Note that not all features are supported (like the#[Groups] attribute).
In your configuration, pass the name of the JMS serializer service (jms_serializer by default).
YAML
Normalizers
By default all entities are converted to an array with the built-in Symfony normalizers (for exampleGetSetMethodNormalizer, DateTimeNormalizer, or ObjectNormalizer)
which should be enough for simple use cases.
For more control over what you send to Algolia,
or to avoid circular references,
write your own normalizer.
Symfony uses the first normalizer in the array to support your entity or format.
You can change the order in your service declaration.
The normalizer is called with searchableArray format.
The following features are only supported with the default Symfony serializer, not with JMS serializer.
Attributes
The simplest way to choose which fields to index is to mark them with the#[Groups] attribute.
This feature relies on the built-in ObjectNormalizer and its serializer-group support.
Attributes require
enable_serializer_groups to be set to true in the configuration.PHP
Normalize
Another option is to implement a dedicated method that returns the entity as an array. This feature relies on theCustomNormalizer that ships with the serializer component.
Implement the Symfony\Component\Serializer\Normalizer\NormalizableInterface interface and write your normalize method.
Example based on a simplified version of this Post entity:
PHP
Handle multiple formats
In case you are already using this method for something else, like encoding entities into JSON for instance, you may want to use a different format for both use cases. You can rely on the format to return different arrays.PHP
Custom normalizers
You can create a custom normalizer for any entity by implementing theSymfony\Component\Serializer\Normalizer\NormalizerInterface interface.
The following snippet shows a simple UserNormalizer.
PHP
UserNormalizer whenever it encounters a User — either as the top-level indexed entity or as a nested property on another entity being indexed.
Order of normalizers
Because Symfony uses the first normalizer that supports your entity or format, the order is important. TheObjectNormalizer is registered with a priority of -1000 and should always be the last fallback.
Most of Symfony’s built-in normalizers sit in the negative range below the CustomNormalizer (registered at -800), though a few (such as the UnwrappingDenormalizer) run at higher priorities.
To keep your normalizers ahead of the bundle’s CustomNormalizer, register them above -800.
This also puts them ahead of the lower-priority Symfony fallback normalizers, such as ObjectNormalizer.
The default priority is 0.
You can change the priority in your service definition.