The application uses rails 4.2 and standard gem elasticsearch. An additional filter by synonyms was needed for the search. A dictionary and filter documentation was written. But for some reason, not all words from the dictionary are correctly searched.

'Π°ΠΏΠ°Ρ‡, Π°ΠΏΠ°Ρ‡ΠΈ, Π°ΠΏΠ°Ρ‡Π΅ => Apache' 'ΠΏΡ…ΠΏ => PHP' 'Π³ΠΈΡ‚, Π³ΠΈΡ‚Ρ…Π°Π± => Git' 'линукс => Linux' 'ΠΊΠ»ΠΈΠ΅Π½Ρ‚-сСрвСр => Client-Server' 'ΠΏΠΈΡ‚ΠΎΠ½, ΠΏΠ°ΠΉΡ‚ΠΎΠ½, python3, python2 => Python' 

This format dictionary written in a separate file.

 synonym: { type: 'synonym', synonyms: Rails.root.join('config', 'elastic', 'synonyms_dictionary.txt').readlines.map(&:strip).join(',') }, 

and so its introduction to the filter looks like

The essence of the problem is that for some reason the search for synonyms behaves incorrectly. For example, \ by examples from the dictionary \, Π³ΠΈΡ‚ - Π½Π΅ Π½Π°Ρ…ΠΎΠ΄ΠΈΡ‚ записСй , but Π³ΠΈΡ‚Ρ…Π°Π± - Π½Π°Ρ…ΠΎΠ΄ΠΈΡ‚ записи ΠΏΠΎ слову git , ΠΏΠΈΡ‚ΠΎΠ½|ΠΏΠ°ΠΉΡ‚ΠΎΠ½|python3 - Π½Π΅ ΠΈΡ‰Π΅Ρ‚ записи , but python2 - Π½Π°Ρ…ΠΎΠ΄ΠΈΡ‚ записи ΠΏΠΎ слову python . Линукс Π½Π°Ρ…ΠΎΠ΄ΠΈΡ‚ записи Π²ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‰ΠΈΠ΅ слово Linux . And this is very strange and not understandable.

    1 answer 1

    As it turned out he didn’t like the embedding method. That is, it accepts in such a way that one line of synonyms = one request. I deleted all line breaks, everything was written in 1 line and accordingly violated the logic of work, and the elastic swallowed and worked incorrectly. The decision to change the implementation line to: synonyms:[Rails.root.join('config','elastic','synonyms_dictionary.txt').readlines.join(',')]