Skip to content

Index Configuration

Clémentine Urquizar edited this page Jul 9, 2020 · 9 revisions

Create meili_search.yaml

Configuration typically lives in the config/packages/meili_search.yaml file for a Symfony 4 application.

This is how you define what entity or document you want to index and some other technical details like a prefix or the number of results.

The documentation uses the Symfony/demo app as an example; we are working with posts and comments.

The Simplest Version

meili_search:
    indices:
        - name: posts
          class: App\Entity\Post

        - name: comments
          class: App\Entity\Comment

A more Complete Example

meili_search:
    nbResults: 8                  # Retrieve less results on search (default: 20)
    prefix: %env(SEARCH_PREFIX)%  # Use a prefix for index names based en env var
    doctrineSubscribedEvents: []  # disable doctrine events (turn off realtime sync)
    indices:
        -   name: posts
            class: App\Entity\Post
            enable_serializer_groups: true

        -   name: comments
            class: App\Entity\Comment

Multi-environment Setup

Usually, you need different configurations per environment, so that you don’t work with production data while developing.

Prefix

The first thing to do is to set a prefix per environment. You can do this by either creating an extra configuration file for your development environment, or rely on environment variables.

Configuration file

Create a config file inside the dev/ directory and override your default configuration.

# config/packages/meili_search.yaml
meili_search:
    prefix: app_prod_
# config/packages/dev/meili_search.yaml
meili_search:
    prefix: app_dev_

Environment Variables

In your config file, set the prefix as an environment variable.

meili_search:
    prefix: %env(MEILISEARCH_PREFIX)%

Then, define the MEILISEARCH_PREFIX variable in your .env file or your Apache/Nginx configuration. Symfony makes it easy to concatenate environment variables in the .env file.

The following example uses the APP_ENV environment variable to create a search prefix:

MEILISEARCH_PREFIX=app1_${APP_ENV}_
Clone this wiki locally