Create configuration file algolia_search.yaml
The configuration for Algolia is in the file config/packages/algolia_search.yaml
for Symfony 4 apps.
Here, you can define what to index,
and change other settings, such as,
the number of results to retrieve with every search.
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 changes a few settings,
such as reduce the number of retrieved results.
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:
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.
-
Extend the
SearchServiceInterface
and use that new class, for example in your tests. As a starting point, you can use theNullSearchService
class:PHP
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:
--indices
option takes a comma-separated list of index names (without prefix).
Without options, all indices are processed.
Settings directory
Depending on your version of Symfony, the settings are in different locations:- Symfony 4:
config/settings/algolia_search/
- Symfony 3:
app/Resources/SearchBundle/settings/
YAML