Skip to content

Synonyms

The Synonyms are defined in the %PLUGIN_DIR%/Resources/config/Synonyms.php. The path to this file is saved in the swag_ses_synonym_dir parameter of the container and can be overridden with the default Dependency Injection. See How to override for more information.

INFO

The syntax in the association may look a bit strange, it's the Solr syntax.

The path parameter is afterwards passed to the Swag\EnterpriseSearch\Relevance\SynonymProvider class.

Example

php
// Synonyms.php
<?php declare(strict_types=1);

use Swag\EnterpriseSearch\Relevance\SynonymProvider;

return [
    SynonymProvider::DEFAULT_KEY => [
        'i-pod, i pod => ipod',
        'universe, cosmos',
    ],
];

The SynonymProvider supports multi languages and a default fallback! For a specific language the language code can be added as an array key, like the following.

php
// Synonyms.php with multi language support
<?php declare(strict_types=1);

use Swag\EnterpriseSearch\Relevance\SynonymProvider;

return [
    SynonymProvider::DEFAULT_KEY => [
        'i-pod, i pod => ipod',
        'universe, cosmos',
    ],
    'en-GB' => [
        'foozball, foosball',
        'sea biscuit, sea biscit => seabiscuit',
    ],
];

How to override

  1. Shopware Configuration
    1. Shopware is based on symfony, so it's possible to override the Service parameters in symfony style.
    2. Parametername swag_ses_synonym_dir
  2. Own Plugin 1. Create a plugin
    1. Add a dependency injection file
    2. Create a file with your synonyms, see Example
    3. Add a parameter to the Dependency Injection File.
html
// services.xml
<parameters>
    <parameter key="swag_ses_synonym_dir">%kernel.project_dir%/MySynonyms.php</parameter>
</parameter>

WARNING

Make sure that the paths matches!