Edit stopwords for an existing locale
To edit stopwords:
-
Log in to your Commerce server, or switch to, the file system owner.
-
Use a text editor to open a stopword file in the
<magento_root>/vendor/magento/module-elasticsearch/etc/stopwords
directory.CSV files use the naming convention
stopwords_<locale_code>.csv
. For example, the German stopword file is namedstopwords_de_DE.csv
. -
Add words, remove words, or change words in the file.
(Each stopword in a file starts on a new line.)
-
Save your changes and exit the text editor.
-
Clean the configuration cache.
-
Admin: System > Tools > Cache Management. Select the Configuration checkbox and, from the list above it, click Refresh. Click Submit to complete the action.
-
Command line: As the file system owner, enter the following command:
php <magento_root>/bin/magento cache:clean config
-
-
Check the results by searching for terms on your storefront.
Create stopwords for a new locale
To add stopwords for a locale:
-
Log in to your Commerce server, or switch to, the file system owner.
-
Use a text editor to create a stopword file named
stopwords_<locale_code>.csv
in the<magento_root>/vendor/magento/module-elasticsearch/etc/stopwords
directory.For example, to create stopwords for the Italian locale, name the file
stopwords_it_IT.csv
. -
In your stopword file, make sure that each stopword is on a separate line.
-
Save your changes and exit the text editor.
-
In the same directory, open
esconfig.xml
in a text editor. -
Add a line to
esconfig.xml
as follows:<LOCALE_CODE>stopwords_LOCALE_CODE.csv</LOCALE_CODE>
For example, to add an Italian stopword file, add the following line:
<it_IT>stopwords_it_IT.csv</it_IT>
-
Save the changes to
esconfig.xml
and exit the text editor. -
Clean the configuration cache.
-
Admin: System > Tools > Cache Management. Select the Configuration checkbox and, from the list above it, click Refresh. Click Submit to complete the action.
-
Command line: As the file system owner, enter the following command:
php <magento_root>/bin/magento magento cache:clean config
-
-
Check the results by searching for terms on your storefront.
Change the stopword directory
This section discusses how to optionally change the default stopword directory from one of the following:
<magento_root>/vendor/magento/module-elasticsearch/etc/stopwords
<magento_root>/app/code/Magento/Elasticsearch/etc/stopwords/
The location depends on how you installed the Commerce software. If you cloned the Magento 2 GitHub repository, the path is under app/code
. If you installed a compressed archive or a metapackage, the path is under vendor
.
To change the directory:
-
As the file system owner, open the Elasticsearch
di.xml
in a text editor.If you cloned the repository, it is located at
app/code/Magento/Elasticsearch/etc/di.xml
If you got an archive or the metapackage, it is located at
vendor/magento/module-elasticsearch/etc/di.xml
-
Change the value of
stopwordsDirectory
to the desired directory:<type name="Magento\Elasticsearch\SearchAdapter\Query\Preprocessor\Stopwords"> <arguments> <argument name="stopwordsDirectory" xsi:type="string">app/code/Magento/Elasticsearch/etc/stopwords</argument> </arguments> </type>
-
Save your changes to
di.xml
and exit the text editor.
To change the directory from your module
-
In your module
etc/di.xml
add instructions:<type name="Magento\Elasticsearch\SearchAdapter\Query\Preprocessor\Stopwords"> <arguments> <argument name="stopwordsModule" xsi:type="string">Your_Module</argument> <argument name="stopwordsDirectory" xsi:type="string">stopwords</argument> </arguments> </type>
-
In your module, create the directory
etc/stopwords
, with the corresponding CSV file. -
Save your changes to
di.xml
and exit the text editor.