Commit a876251e3c39c900900d7f53032693e7c6f258ee

Authored by Andrew
1 parent 30d58f4a

Added support for Ukrainian

README.md
... ... @@ -307,6 +307,8 @@ class Product < ApplicationRecord
307 307 end
308 308 ```
309 309  
  310 +For Ukranian, install the [analysis-ukrainian plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/6.2/analysis-ukrainian.html) and use `language: "ukrainian"`. [master]
  311 +
310 312 ### Synonyms
311 313  
312 314 ```ruby
... ...
lib/searchkick/index_options.rb
... ... @@ -142,7 +142,8 @@ module Searchkick
142 142 }
143 143 }
144 144  
145   - if language == "chinese"
  145 + case language
  146 + when "chinese"
146 147 settings[:analysis][:analyzer].merge!(
147 148 default_analyzer => {
148 149 type: "ik_smart"
... ... @@ -156,6 +157,18 @@ module Searchkick
156 157 )
157 158  
158 159 settings[:analysis][:filter].delete(:searchkick_stemmer)
  160 + when "ukrainian"
  161 + settings[:analysis][:analyzer].merge!(
  162 + default_analyzer => {
  163 + type: "ukrainian"
  164 + },
  165 + searchkick_search: {
  166 + type: "ukrainian"
  167 + },
  168 + searchkick_search2: {
  169 + type: "ukrainian"
  170 + }
  171 + )
159 172 end
160 173  
161 174 if Searchkick.env == "test"
... ...
lib/searchkick/query.rb
... ... @@ -314,10 +314,12 @@ module Searchkick
314 314  
315 315 if field == "_all" || field.end_with?(".analyzed")
316 316 shared_options[:cutoff_frequency] = 0.001 unless operator.to_s == "and" || misspellings == false
317   - qs.concat [
318   - shared_options.merge(analyzer: "searchkick_search"),
319   - shared_options.merge(analyzer: "searchkick_search2")
320   - ]
  317 + qs << shared_options.merge(analyzer: "searchkick_search")
  318 +
  319 + # searchkick_search and searchkick_search2 are the same for ukrainian
  320 + unless searchkick_options[:language] == "ukranian"
  321 + qs << shared_options.merge(analyzer: "searchkick_search2")
  322 + end
321 323 exclude_analyzer = "searchkick_search2"
322 324 elsif field.end_with?(".exact")
323 325 f = field.split(".")[0..-2].join(".")
... ...
test/language_test.rb
... ... @@ -2,13 +2,13 @@ require_relative &quot;test_helper&quot;
2 2  
3 3 class LanguageTest < Minitest::Test
4 4 def setup
  5 + skip unless ENV["LANGUAGE"]
  6 +
5 7 Song.destroy_all
6 8 end
7 9  
8 10 def test_chinese
9 11 # requires https://github.com/medcl/elasticsearch-analysis-ik
10   - skip unless ENV["CHINESE"]
11   -
12 12 with_options(Song, language: "chinese") do
13 13 store_names ["中华人民共和国国歌"], Song
14 14 assert_search "中华人民共和国", ["中华人民共和国国歌"], {}, Song
... ... @@ -16,4 +16,12 @@ class LanguageTest &lt; Minitest::Test
16 16 assert_search "人", [], {}, Song
17 17 end
18 18 end
  19 +
  20 + def test_ukrainian
  21 + # requires https://www.elastic.co/guide/en/elasticsearch/plugins/6.2/analysis-ukrainian.html
  22 + with_options(Song, language: "ukrainian") do
  23 + store_names ["ресторани"], Song
  24 + assert_search "ресторан", ["ресторани"], {misspellings: false}, Song
  25 + end
  26 + end
19 27 end
... ...