Meilisearch Symfony Bundle

repository·main·Indexed 41 days ago

https://github.com/meilisearch/meilisearch-symfony

A Symfony bundle for seamless integration of the Meilisearch search engine into Symfony applications, featuring support for Doctrine ORM entities and Meilisearch v1.x. Includes CLI commands for index management, data import with atomic index swapping, and settings updates.

Tokens
2.8K
Snippets
14
Records
16
Agent score
99%

What's inside Meilisearch Symfony Bundle

  1. Install the Meilisearch Symfony Bundle

    main

    To integrate Meilisearch into your Symfony project, install the meilisearch/search-bundle package via Composer.

    Requirements

    • PHP: 8.1 or later
    • Symfony: 6.4 or later

    For support of older versions, you must use the specific older versions of this bundle.

    composer require meilisearch/search-bundle
  2. Run the development environment with Docker Compose

    main

    The repository provides a docker-compose.yml file to orchestrate a local development environment consisting of the meilisearch-symfony package and a Meilisearch instance.

    Services

    • package: Builds the current directory into a container. It is configured to work in /home/package and depends on the meilisearch service. It uses a bind mount to sync the local source code with the container for real-time development.
    • meilisearch: Runs the getmeili/meilisearch-enterprise:latest image.

    Environment Variables

    For the package service:

    • MEILISEARCH_URL: The URL used by the Symfony package to communicate with the Meilisearch instance. Defaults to http://meilisearch:7700 in this configuration.

    For the meilisearch service:

    • MEILI_MASTER_KEY: The master key required for authenticated requests to Meilisearch. Set to masterKey in this configuration.
    • MEILI_NO_ANALYTICS: Set to true to disable analytics.
    docker-compose up
  3. Reference: meilisearch:import command options

    main

    The following options are available for the meilisearch:import command:

    OptionShortcutDescription
    --indices-iComma-separated list of index names to import.
    --update-settingsIf present, updates settings related to the indices in the search engine. This is a negatable option (use --no-update-settings to disable).
    --batch-sizeThe number of records to process in a single batch. If not provided, the value from the SearchManager configuration is used.
    --skip-batchesSkip the first N batches and start importing from the N+1 batch.
    --response-timeout-tTimeout in milliseconds to wait for a response from the search engine.
    --swap-indicesImport to temporary indices and use index swap to prevent downtime.
    php bin/console meilisearch:import --indices="index1,index2" --batch-size=100 --swap-indices
  4. Use the `--indices` option in Meilisearch Symfony commands

    main

    When using Meilisearch bundle commands (which extend IndexCommand), you can filter operations to specific indices using the --indices option.

    • Format: A comma-separated list of index names (e.g., index1,index2).
    • Prefixing: If the index name provided does not already contain the configured prefix (from your Meilisearch bundle configuration), the command will automatically prepend the prefix to the name.
    • Behavior: If no indices are provided via the CLI option and no indices are defined in your YAML configuration, the command will warn that no indices were specified.
    # Example usage (actual command name depends on the specific implementation)
    symphony-cli meilisearch:index:some-action --indices=my_index,another_index
  5. Reference: meilisearch:clear command options

    main

    The meilisearch:clear (alias meili:clear) command accepts the following options:

    OptionShortcutRequiredDescription
    --indices-iOptionalComma-separated list of index names
    --response-timeout-tRequiredTimeout (in ms) to get response from the search engine (defaults to self::DEFAULT_RESPONSE_TIMEOUT)
    Options:
      -i, --indices=""          Comma-separated list of index names
      -t, --response-timeout="" Timeout (in ms) to get response from the search engine
  6. Reference: Docker Compose service configuration

    main

    The following environment variables and service settings are defined in the docker-compose.yml file for local development.

    services:
      package:
        environment:
          - MEILISEARCH_URL=http://meilisearch:7700
        volumes:
          - ./:/home/package:rw,cached
        depends_on:
          - meilisearch
    
      meilisearch:
        image: getmeili/meilisearch-enterprise:latest
        environment:
          - MEILI_MASTER_KEY=masterKey
          - MEILI_NO_ANALYTICS=true
  7. Reference: meilisearch:update-settings options

    main

    The meilisearch:update-settings command supports the following options:

    OptionShortcutRequirementDescription
    --indices-iOptionalA comma-separated list of index names to update.
    --response-timeout-tRequiredTimeout (in ms) to get response from the search engine.

    Note: The --response-timeout has a default value defined within the command if not explicitly provided.

    --indices, -i : Comma-separated list of index names
    --response-timeout, -t : Timeout (in ms) to get response from the search engine
  8. Reference: meilisearch:create command options

    main

    The meilisearch:create command supports the following options:

    OptionShortDescription
    --indices-iComma-separated list of index names
    --update-settingsUpdate settings related to indices to the search engine (negatable)
    --response-timeout-tTimeout (in ms) to get response from the search engine (default: self::DEFAULT_RESPONSE_TIMEOUT)
    --indices, -i
    --update-settings
    --response-timeout, -t
  9. Create Meilisearch indexes via CLI

    main

    Use the meilisearch:create command (or its alias meili:create) to create new indexes in Meilisearch based on your configured entities. The command identifies searchable entities and triggers the index creation process on the Meilisearch server. If an entity is an Aggregator, the command will also expand the index creation to include its constituent entities.

    # Basic usage to create indexes
    php bin/console meilisearch:create
    
    # Create specific indexes using a comma-separated list
    php bin/console meilisearch:create --indices="index1,index2"
    
    # Create indexes and update their settings in the search engine
    php bin/console meilisearch:create --update-settings
    
    # Set a custom response timeout in milliseconds
    php bin/console meilisearch:create --response-timeout=5000