Magento 2.3 OpenSource - How to implement Stopwords in ElasticSearch 6.x
-
24-03-2021 - |
Question
Having custom module dependency injection as follows:
di.xml
inapp/code/Custom/Stopwords/etc
directory.<type name="Magento\Elasticsearch\SearchAdapter\Query\Preprocessor\Stopwords"> <arguments> <argument name="stopwordsDirectory" xsi:type="string">app/code/Custom/Stopwords/etc/stopwords</argument> </arguments>
stopwords_en_US.csv
inapp/code/Custom/Stopwords/etc/stopwords
directory copied from vendor.
Dev docs guide which i'm referring
Edit
I would like to add few stopwords in the .csv
file.
Have added the stop-words as follows:
more less some few other misc all
Issue - after adding the above stop-words it is not getting applied.
Solution
I ran into the same issue that you had following the documentation provided. You were following the Change Stopword Directory instead you want to follow the instructions under To change the directory from your module
In you custom module etc/di.xml file add in the following
<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>
Then make sure to copy vendor\magento\module-elasticsearch\etc\stopwords\stopwords.csv
to app/code/Your/Module/etc/stopwords/stopwords.csv
and add your words at the end of the file adding a new line for each word.
Once you are done I recommend rebuilding the indexes.