Commit 5d921bc3da69d6105cbc682ea3df6dce389b47dc
1 parent
4bed5e3e
Exists in
master
and in
18 other branches
Added stem option
Showing
6 changed files
with
45 additions
and
16 deletions
Show diff stats
CHANGELOG.md
README.md
... | ... | @@ -1676,6 +1676,22 @@ class Product < ApplicationRecord |
1676 | 1676 | end |
1677 | 1677 | ``` |
1678 | 1678 | |
1679 | +Turn off stemming [master] | |
1680 | + | |
1681 | +```ruby | |
1682 | +class Product < ApplicationRecord | |
1683 | + searchkick stem: false | |
1684 | +end | |
1685 | +``` | |
1686 | + | |
1687 | +Turn on stemming for conversions | |
1688 | + | |
1689 | +```ruby | |
1690 | +class Product < ApplicationRecord | |
1691 | + searchkick stem_conversions: true | |
1692 | +end | |
1693 | +``` | |
1694 | + | |
1679 | 1695 | Use a different [similarity algorithm](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-similarity.html) for scoring |
1680 | 1696 | |
1681 | 1697 | ```ruby | ... | ... |
lib/searchkick/index_options.rb
... | ... | @@ -226,12 +226,17 @@ module Searchkick |
226 | 226 | end |
227 | 227 | |
228 | 228 | if options[:case_sensitive] |
229 | - # delete lowercase analyzer from each | |
230 | 229 | settings[:analysis][:analyzer].each do |_, analyzer| |
231 | 230 | analyzer[:filter].delete("lowercase") |
232 | 231 | end |
233 | 232 | end |
234 | 233 | |
234 | + if options[:stem] == false | |
235 | + settings[:analysis][:analyzer].each do |_, analyzer| | |
236 | + analyzer[:filter].delete("searchkick_stemmer") | |
237 | + end | |
238 | + end | |
239 | + | |
235 | 240 | settings = settings.symbolize_keys.deep_merge((options[:settings] || {}).symbolize_keys) |
236 | 241 | |
237 | 242 | # synonyms | ... | ... |
lib/searchkick/model.rb
... | ... | @@ -6,7 +6,7 @@ module Searchkick |
6 | 6 | unknown_keywords = options.keys - [:_all, :_type, :batch_size, :callbacks, :case_sensitive, :conversions, :default_fields, |
7 | 7 | :filterable, :geo_shape, :highlight, :ignore_above, :index_name, :index_prefix, :inheritance, :language, |
8 | 8 | :locations, :mappings, :match, :merge_mappings, :routing, :searchable, :settings, :similarity, |
9 | - :special_characters, :stem_conversions, :suggest, :synonyms, :text_end, | |
9 | + :special_characters, :stem, :stem_conversions, :suggest, :synonyms, :text_end, | |
10 | 10 | :text_middle, :text_start, :word, :wordnet, :word_end, :word_middle, :word_start] |
11 | 11 | raise ArgumentError, "unknown keywords: #{unknown_keywords.join(", ")}" if unknown_keywords.any? |
12 | 12 | ... | ... |
test/case_sensitive_test.rb
... | ... | @@ -1,14 +0,0 @@ |
1 | -require_relative "test_helper" | |
2 | - | |
3 | -class CaseSensitiveTest < Minitest::Test | |
4 | - def setup | |
5 | - Song.destroy_all | |
6 | - end | |
7 | - | |
8 | - def test_case_sensitive | |
9 | - with_options(Song, case_sensitive: true) do | |
10 | - store_names ["Test", "test"], Song | |
11 | - assert_search "test", ["test"], {misspellings: false}, Song | |
12 | - end | |
13 | - end | |
14 | -end |
... | ... | @@ -0,0 +1,21 @@ |
1 | +require_relative "test_helper" | |
2 | + | |
3 | +class IndexOptionsTest < Minitest::Test | |
4 | + def setup | |
5 | + Song.destroy_all | |
6 | + end | |
7 | + | |
8 | + def test_case_sensitive | |
9 | + with_options(Song, case_sensitive: true) do | |
10 | + store_names ["Test", "test"], Song | |
11 | + assert_search "test", ["test"], {misspellings: false}, Song | |
12 | + end | |
13 | + end | |
14 | + | |
15 | + def test_no_stemming | |
16 | + with_options(Song, stem: false) do | |
17 | + store_names ["milk", "milks"], Song | |
18 | + assert_search "milks", ["milks"], {misspellings: false}, Song | |
19 | + end | |
20 | + end | |
21 | +end | ... | ... |