Create configuration file algolia_search.yaml
The configuration for Algolia lives in config/packages/algolia_search.yaml.
Here, you can define what to index and change other settings,
such as the index name prefix and the batch size for automatic indexing.
This guide uses the Symfony demo app as an example,
using posts and comments.
Configuration examples
The following example lets Algolia store your posts in the indexposts
and your comments in the index comments.
The other settings use their default values.
YAML
posts or comments.
The prefix is read from the environment variable SEARCH_PREFIX.
This configuration example also turns off real-time sync and opts posts into serializer groups.
YAML
Multi-environment setup
To avoid working with production data while developing your app, use different configurations for each environment.Prefix
To use different indices for your production and development environments, set up different index name prefixes, either in configuration files, or environment variables.Set up different prefixes in configuration files
Create a configuration file inside thedev/ directory and override your default configuration.
The configuration for your production environment uses the app_prod_ prefix:
YAML
app_dev_ prefix:
YAML
Set up different prefixes in environment variables
In your configuration file, set the prefix as environment variable.YAML
SEARCH_PREFIX variable in your .env file or your server configuration.
The following example uses the APP_ENV environment variable to create a search prefix:
.env
Bypass calls to Algolia
To prevent requests to Algolia while developing your app, you can use one of the following approaches:- Unsubscribe from Doctrine events to avoid indexing calls when you update your data.
- Override
search.servicewith the built-inAlgolia\SearchBundle\Services\NullSearchServicein your test environment:
YAML
Index settings
To configure index settings, you can use the JSON files inconfig/settings/algolia_search/{$index_name}-settings.json.
The SettingsManager class backs up settings from the engine and pushes them back with the following commands:
Command line
--indices option takes a comma-separated list of index names (without prefix).
Without options, all indices are processed.
Settings directory
By default, the bundle looks for settings files underconfig/settings/algolia_search/.
You can change the settings directory in your configuration file. The value is appended directly to kernel.project_dir, so it must start with a leading slash:
YAML