Commit fd66e07c9de067695dd9e79aaa518cef9ad174fa
1 parent
4e11926e
Exists in
master
and in
5 other branches
Added support for Hunspell - closes #1460
Showing
4 changed files
with
28 additions
and
1 deletions
Show diff stats
CHANGELOG.md
README.md
@@ -322,6 +322,14 @@ See the [list of stemmers](https://www.elastic.co/guide/en/elasticsearch/referen | @@ -322,6 +322,14 @@ See the [list of stemmers](https://www.elastic.co/guide/en/elasticsearch/referen | ||
322 | - `ukrainian` - [analysis-ukrainian plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/7.4/analysis-ukrainian.html) | 322 | - `ukrainian` - [analysis-ukrainian plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/7.4/analysis-ukrainian.html) |
323 | - `vietnamese` - [analysis-vietnamese plugin](https://github.com/duydo/elasticsearch-analysis-vietnamese) | 323 | - `vietnamese` - [analysis-vietnamese plugin](https://github.com/duydo/elasticsearch-analysis-vietnamese) |
324 | 324 | ||
325 | +You can also use a Hunspell dictionary for stemming. [master] | ||
326 | + | ||
327 | +```ruby | ||
328 | +class Product < ApplicationRecord | ||
329 | + searchkick language: {type: "hunspell", locale: "en_US"} | ||
330 | +end | ||
331 | +``` | ||
332 | + | ||
325 | Disable stemming with: | 333 | Disable stemming with: |
326 | 334 | ||
327 | ```ruby | 335 | ```ruby |
lib/searchkick/index_options.rb
@@ -153,7 +153,11 @@ module Searchkick | @@ -153,7 +153,11 @@ module Searchkick | ||
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | - update_language(settings, language) | 156 | + if language.is_a?(Hash) && language[:type] == "hunspell" |
157 | + update_hunspell(settings, language) | ||
158 | + else | ||
159 | + update_language(settings, language) | ||
160 | + end | ||
157 | update_stemming(settings) | 161 | update_stemming(settings) |
158 | 162 | ||
159 | if Searchkick.env == "test" | 163 | if Searchkick.env == "test" |
@@ -196,6 +200,11 @@ module Searchkick | @@ -196,6 +200,11 @@ module Searchkick | ||
196 | settings | 200 | settings |
197 | end | 201 | end |
198 | 202 | ||
203 | + # supports all hunspell token filter options | ||
204 | + def update_hunspell(settings, language) | ||
205 | + settings[:analysis][:filter][:searchkick_stemmer] = language | ||
206 | + end | ||
207 | + | ||
199 | def update_language(settings, language) | 208 | def update_language(settings, language) |
200 | case language | 209 | case language |
201 | when "chinese" | 210 | when "chinese" |
test/language_test.rb
@@ -90,6 +90,15 @@ class LanguageTest < Minitest::Test | @@ -90,6 +90,15 @@ class LanguageTest < Minitest::Test | ||
90 | end | 90 | end |
91 | end | 91 | end |
92 | 92 | ||
93 | + def test_hunspell | ||
94 | + skip if ci? | ||
95 | + | ||
96 | + with_options({language: {type: "hunspell", locale: "en_US"}}) do | ||
97 | + store_names ["the foxes jumping quickly"] | ||
98 | + assert_language_search "fox", ["the foxes jumping quickly"] | ||
99 | + end | ||
100 | + end | ||
101 | + | ||
93 | def assert_language_search(term, expected) | 102 | def assert_language_search(term, expected) |
94 | assert_search term, expected, {misspellings: false} | 103 | assert_search term, expected, {misspellings: false} |
95 | end | 104 | end |