searchkick 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/CONTRIBUTING.md +9 -7
- data/README.md +86 -24
- data/lib/searchkick/bulk_indexer.rb +1 -1
- data/lib/searchkick/index_options.rb +12 -0
- data/lib/searchkick/model.rb +2 -2
- data/lib/searchkick/query.rb +36 -21
- data/lib/searchkick/record_data.rb +2 -2
- data/lib/searchkick/results.rb +2 -2
- data/lib/searchkick/version.rb +1 -1
- metadata +8 -106
- data/.github/ISSUE_TEMPLATE.md +0 -7
- data/.gitignore +0 -22
- data/.travis.yml +0 -33
- data/Gemfile +0 -16
- data/Rakefile +0 -16
- data/benchmark/Gemfile +0 -24
- data/benchmark/index.rb +0 -99
- data/benchmark/search.rb +0 -48
- data/docs/Searchkick-3-Upgrade.md +0 -57
- data/searchkick.gemspec +0 -30
- data/test/aggs_test.rb +0 -217
- data/test/autocomplete_test.rb +0 -81
- data/test/boost_test.rb +0 -225
- data/test/callbacks_test.rb +0 -59
- data/test/ci/before_install.sh +0 -17
- data/test/errors_test.rb +0 -19
- data/test/gemfiles/activerecord42.gemfile +0 -7
- data/test/gemfiles/activerecord50.gemfile +0 -7
- data/test/gemfiles/activerecord51.gemfile +0 -7
- data/test/gemfiles/apartment.gemfile +0 -8
- data/test/gemfiles/cequel.gemfile +0 -8
- data/test/gemfiles/mongoid5.gemfile +0 -7
- data/test/gemfiles/mongoid6.gemfile +0 -12
- data/test/gemfiles/nobrainer.gemfile +0 -8
- data/test/gemfiles/parallel_tests.gemfile +0 -8
- data/test/geo_shape_test.rb +0 -171
- data/test/highlight_test.rb +0 -109
- data/test/index_test.rb +0 -168
- data/test/inheritance_test.rb +0 -82
- data/test/language_test.rb +0 -79
- data/test/marshal_test.rb +0 -13
- data/test/match_test.rb +0 -293
- data/test/misspellings_test.rb +0 -56
- data/test/model_test.rb +0 -40
- data/test/multi_search_test.rb +0 -37
- data/test/multi_tenancy_test.rb +0 -22
- data/test/order_test.rb +0 -40
- data/test/pagination_test.rb +0 -96
- data/test/partial_reindex_test.rb +0 -65
- data/test/query_test.rb +0 -43
- data/test/reindex_test.rb +0 -87
- data/test/reindex_v2_job_test.rb +0 -27
- data/test/routing_test.rb +0 -23
- data/test/should_index_test.rb +0 -32
- data/test/similar_test.rb +0 -28
- data/test/sql_test.rb +0 -190
- data/test/suggest_test.rb +0 -100
- data/test/support/kaminari.yml +0 -21
- data/test/synonyms_test.rb +0 -69
- data/test/test_helper.rb +0 -593
- data/test/where_test.rb +0 -249
data/test/index_test.rb
DELETED
@@ -1,168 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class IndexTest < Minitest::Test
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
Region.destroy_all
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_clean_indices
|
10
|
-
suffix = Searchkick.index_suffix ? "_#{Searchkick.index_suffix}" : ""
|
11
|
-
old_index = Searchkick::Index.new("products_test#{suffix}_20130801000000000")
|
12
|
-
different_index = Searchkick::Index.new("items_test#{suffix}_20130801000000000")
|
13
|
-
|
14
|
-
old_index.delete if old_index.exists?
|
15
|
-
different_index.delete if different_index.exists?
|
16
|
-
|
17
|
-
# create indexes
|
18
|
-
old_index.create
|
19
|
-
different_index.create
|
20
|
-
|
21
|
-
Product.searchkick_index.clean_indices
|
22
|
-
|
23
|
-
assert Product.searchkick_index.exists?
|
24
|
-
assert different_index.exists?
|
25
|
-
assert !old_index.exists?
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_clean_indices_old_format
|
29
|
-
suffix = Searchkick.index_suffix ? "_#{Searchkick.index_suffix}" : ""
|
30
|
-
old_index = Searchkick::Index.new("products_test#{suffix}_20130801000000")
|
31
|
-
old_index.create
|
32
|
-
|
33
|
-
Product.searchkick_index.clean_indices
|
34
|
-
|
35
|
-
assert !old_index.exists?
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_retain
|
39
|
-
Product.reindex
|
40
|
-
assert_equal 1, Product.searchkick_index.all_indices.size
|
41
|
-
Product.reindex(retain: true)
|
42
|
-
assert_equal 2, Product.searchkick_index.all_indices.size
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_total_docs
|
46
|
-
store_names ["Product A"]
|
47
|
-
assert_equal 1, Product.searchkick_index.total_docs
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_mapping
|
51
|
-
store_names ["Dollar Tree"], Store
|
52
|
-
assert_equal [], Store.search(body: {query: {match: {name: "dollar"}}}).map(&:name)
|
53
|
-
assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}).map(&:name)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_body
|
57
|
-
store_names ["Dollar Tree"], Store
|
58
|
-
assert_equal [], Store.search(body: {query: {match: {name: "dollar"}}}).map(&:name)
|
59
|
-
assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}, load: false).map(&:name)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_body_incompatible_options
|
63
|
-
assert_raises(ArgumentError) do
|
64
|
-
Store.search(body: {query: {match: {name: "dollar"}}}, where: {id: 1})
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_block
|
69
|
-
store_names ["Dollar Tree"]
|
70
|
-
products =
|
71
|
-
Product.search "boom" do |body|
|
72
|
-
body[:query] = {match_all: {}}
|
73
|
-
end
|
74
|
-
assert_equal ["Dollar Tree"], products.map(&:name)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_tokens
|
78
|
-
assert_equal ["dollar", "dollartre", "tree"], Product.searchkick_index.tokens("Dollar Tree", analyzer: "searchkick_index")
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_tokens_analyzer
|
82
|
-
assert_equal ["dollar", "tree"], Product.searchkick_index.tokens("Dollar Tree", analyzer: "searchkick_search2")
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_record_not_found
|
86
|
-
store_names ["Product A", "Product B"]
|
87
|
-
Product.where(name: "Product A").delete_all
|
88
|
-
assert_output nil, /\[searchkick\] WARNING: Records in search index do not exist in database/ do
|
89
|
-
assert_search "product", ["Product B"]
|
90
|
-
end
|
91
|
-
ensure
|
92
|
-
Product.reindex
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_bad_mapping
|
96
|
-
Product.searchkick_index.delete
|
97
|
-
store_names ["Product A"]
|
98
|
-
error = assert_raises(Searchkick::InvalidQueryError) { Product.search "test" }
|
99
|
-
assert_equal "Bad mapping - run Product.reindex", error.message
|
100
|
-
ensure
|
101
|
-
Product.reindex
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_remove_blank_id
|
105
|
-
store_names ["Product A"]
|
106
|
-
Product.searchkick_index.remove(Product.new)
|
107
|
-
assert_search "product", ["Product A"]
|
108
|
-
ensure
|
109
|
-
Product.reindex
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_missing_index
|
113
|
-
assert_raises(Searchkick::MissingIndexError) { Product.search("test", index_name: "not_found") }
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_unsupported_version
|
117
|
-
raises_exception = ->(_) { raise Elasticsearch::Transport::Transport::Error, "[500] No query registered for [multi_match]" }
|
118
|
-
Searchkick.client.stub :search, raises_exception do
|
119
|
-
assert_raises(Searchkick::UnsupportedVersionError) { Product.search("test") }
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_invalid_body
|
124
|
-
assert_raises(Searchkick::InvalidQueryError) { Product.search(body: {boom: true}) }
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_transaction
|
128
|
-
skip unless defined?(ActiveRecord)
|
129
|
-
Product.transaction do
|
130
|
-
store_names ["Product A"]
|
131
|
-
raise ActiveRecord::Rollback
|
132
|
-
end
|
133
|
-
assert_search "*", []
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_filterable
|
137
|
-
# skip for 5.0 since it throws
|
138
|
-
# Cannot search on field [alt_description] since it is not indexed.
|
139
|
-
store [{name: "Product A", alt_description: "Hello"}]
|
140
|
-
assert_raises(Searchkick::InvalidQueryError) do
|
141
|
-
assert_search "*", [], where: {alt_description: "Hello"}
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_filterable_non_string
|
146
|
-
store [{name: "Product A", store_id: 1}]
|
147
|
-
assert_search "*", ["Product A"], where: {store_id: 1}
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_large_value
|
151
|
-
skip if nobrainer?
|
152
|
-
large_value = 1000.times.map { "hello" }.join(" ")
|
153
|
-
store [{name: "Product A", text: large_value}], Region
|
154
|
-
assert_search "product", ["Product A"], {}, Region
|
155
|
-
assert_search "hello", ["Product A"], {fields: [:name, :text]}, Region
|
156
|
-
assert_search "hello", ["Product A"], {}, Region
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_very_large_value
|
160
|
-
skip if nobrainer?
|
161
|
-
large_value = 10000.times.map { "hello" }.join(" ")
|
162
|
-
store [{name: "Product A", text: large_value}], Region
|
163
|
-
assert_search "product", ["Product A"], {}, Region
|
164
|
-
assert_search "hello", ["Product A"], {fields: [:name, :text]}, Region
|
165
|
-
# values that exceed ignore_above are not included in _all field :(
|
166
|
-
# assert_search "hello", ["Product A"], {}, Region
|
167
|
-
end
|
168
|
-
end
|
data/test/inheritance_test.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class InheritanceTest < Minitest::Test
|
4
|
-
def setup
|
5
|
-
skip if defined?(Cequel)
|
6
|
-
super
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_child_reindex
|
10
|
-
store_names ["Max"], Cat
|
11
|
-
assert Dog.reindex
|
12
|
-
assert_equal 1, Animal.search("*").size
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_child_index_name
|
16
|
-
assert_equal "animals-#{Date.today.year}", Dog.searchkick_index.name
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_child_search
|
20
|
-
store_names ["Bear"], Dog
|
21
|
-
store_names ["Bear"], Cat
|
22
|
-
assert_equal 1, Dog.search("bear").size
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_parent_search
|
26
|
-
store_names ["Bear"], Dog
|
27
|
-
store_names ["Bear"], Cat
|
28
|
-
assert_equal 2, Animal.search("bear").size
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_force_one_type
|
32
|
-
store_names ["Green Bear"], Dog
|
33
|
-
store_names ["Blue Bear"], Cat
|
34
|
-
assert_equal ["Blue Bear"], Animal.search("bear", type: [Cat]).map(&:name)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_force_multiple_types
|
38
|
-
store_names ["Green Bear"], Dog
|
39
|
-
store_names ["Blue Bear"], Cat
|
40
|
-
store_names ["Red Bear"], Animal
|
41
|
-
assert_equal ["Green Bear", "Blue Bear"], Animal.search("bear", type: [Dog, Cat]).map(&:name)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_child_autocomplete
|
45
|
-
store_names ["Max"], Cat
|
46
|
-
store_names ["Mark"], Dog
|
47
|
-
assert_equal ["Max"], Cat.search("ma", fields: [:name], match: :text_start).map(&:name)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_parent_autocomplete
|
51
|
-
store_names ["Max"], Cat
|
52
|
-
store_names ["Bear"], Dog
|
53
|
-
assert_equal ["Bear"], Animal.search("bea", fields: [:name], match: :text_start).map(&:name).sort
|
54
|
-
end
|
55
|
-
|
56
|
-
# def test_child_suggest
|
57
|
-
# store_names ["Shark"], Cat
|
58
|
-
# store_names ["Sharp"], Dog
|
59
|
-
# assert_equal ["shark"], Cat.search("shar", fields: [:name], suggest: true).suggestions
|
60
|
-
# end
|
61
|
-
|
62
|
-
def test_parent_suggest
|
63
|
-
store_names ["Shark"], Cat
|
64
|
-
store_names ["Tiger"], Dog
|
65
|
-
assert_equal ["tiger"], Animal.search("tige", fields: [:name], suggest: true).suggestions.sort
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_reindex
|
69
|
-
store_names ["Bear A"], Cat
|
70
|
-
store_names ["Bear B"], Dog
|
71
|
-
Animal.reindex
|
72
|
-
assert_equal 2, Animal.search("bear").size
|
73
|
-
end
|
74
|
-
|
75
|
-
# TODO move somewhere better
|
76
|
-
|
77
|
-
def test_multiple_indices
|
78
|
-
store_names ["Product A"]
|
79
|
-
store_names ["Product B"], Animal
|
80
|
-
assert_search "product", ["Product A", "Product B"], index_name: [Product.searchkick_index.name, Animal.searchkick_index.name], conversions: false
|
81
|
-
end
|
82
|
-
end
|
data/test/language_test.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class LanguageTest < Minitest::Test
|
4
|
-
def setup
|
5
|
-
skip unless ENV["LANGUAGE"]
|
6
|
-
|
7
|
-
Song.destroy_all
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_chinese
|
11
|
-
# requires https://github.com/medcl/elasticsearch-analysis-ik
|
12
|
-
with_options(Song, language: "chinese") do
|
13
|
-
store_names ["中华人民共和国国歌"], Song
|
14
|
-
assert_language_search "中华人民共和国", ["中华人民共和国国歌"]
|
15
|
-
assert_language_search "国歌", ["中华人民共和国国歌"]
|
16
|
-
assert_language_search "人", []
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# experimental
|
21
|
-
def test_smartcn
|
22
|
-
# requires https://www.elastic.co/guide/en/elasticsearch/plugins/6.2/analysis-smartcn.html
|
23
|
-
with_options(Song, language: "smartcn") do
|
24
|
-
store_names ["中华人民共和国国歌"], Song
|
25
|
-
assert_language_search "中华人民共和国", ["中华人民共和国国歌"]
|
26
|
-
# assert_language_search "国歌", ["中华人民共和国国歌"]
|
27
|
-
assert_language_search "人", []
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_japanese
|
32
|
-
# requires https://www.elastic.co/guide/en/elasticsearch/plugins/6.2/analysis-kuromoji.html
|
33
|
-
with_options(Song, language: "japanese") do
|
34
|
-
store_names ["JR新宿駅の近くにビールを飲みに行こうか"], Song
|
35
|
-
assert_language_search "飲む", ["JR新宿駅の近くにビールを飲みに行こうか"]
|
36
|
-
assert_language_search "jr", ["JR新宿駅の近くにビールを飲みに行こうか"]
|
37
|
-
assert_language_search "新", []
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_korean
|
42
|
-
# requires https://github.com/open-korean-text/elasticsearch-analysis-openkoreantext
|
43
|
-
with_options(Song, language: "korean") do
|
44
|
-
store_names ["한국어를 처리하는 예시입니닼ㅋㅋ"], Song
|
45
|
-
assert_language_search "처리", ["한국어를 처리하는 예시입니닼ㅋㅋ"]
|
46
|
-
assert_language_search "한국어", ["한국어를 처리하는 예시입니닼ㅋㅋ"]
|
47
|
-
assert_language_search "를", []
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_polish
|
52
|
-
# requires https://www.elastic.co/guide/en/elasticsearch/plugins/6.2/analysis-stempel.html
|
53
|
-
with_options(Song, language: "polish") do
|
54
|
-
store_names ["polski"], Song
|
55
|
-
assert_language_search "polskimi", ["polski"]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_ukrainian
|
60
|
-
# requires https://www.elastic.co/guide/en/elasticsearch/plugins/6.2/analysis-ukrainian.html
|
61
|
-
with_options(Song, language: "ukrainian") do
|
62
|
-
store_names ["ресторани"], Song
|
63
|
-
assert_language_search "ресторан", ["ресторани"]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_vietnamese
|
68
|
-
# requires https://github.com/duydo/elasticsearch-analysis-vietnamese
|
69
|
-
with_options(Song, language: "vietnamese") do
|
70
|
-
store_names ["công nghệ thông tin Việt Nam"], Song
|
71
|
-
assert_language_search "công nghệ thông tin", ["công nghệ thông tin Việt Nam"]
|
72
|
-
assert_language_search "công", []
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def assert_language_search(term, expected)
|
77
|
-
assert_search term, expected, {misspellings: false}, Song
|
78
|
-
end
|
79
|
-
end
|
data/test/marshal_test.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class MarshalTest < Minitest::Test
|
4
|
-
def test_marshal
|
5
|
-
store_names ["Product A"]
|
6
|
-
assert Marshal.dump(Product.search("*").results)
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_marshal_highlights
|
10
|
-
store_names ["Product A"]
|
11
|
-
assert Marshal.dump(Product.search("product", highlight: true, load: {dumpable: true}).results)
|
12
|
-
end
|
13
|
-
end
|
data/test/match_test.rb
DELETED
@@ -1,293 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class MatchTest < Minitest::Test
|
4
|
-
# exact
|
5
|
-
|
6
|
-
def test_match
|
7
|
-
store_names ["Whole Milk", "Fat Free Milk", "Milk"]
|
8
|
-
assert_search "milk", ["Milk", "Whole Milk", "Fat Free Milk"]
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_case
|
12
|
-
store_names ["Whole Milk", "Fat Free Milk", "Milk"]
|
13
|
-
assert_search "MILK", ["Milk", "Whole Milk", "Fat Free Milk"]
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_cheese_space_in_index
|
17
|
-
store_names ["Pepper Jack Cheese Skewers"]
|
18
|
-
assert_search "pepperjack cheese skewers", ["Pepper Jack Cheese Skewers"]
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_operator
|
22
|
-
store_names ["fresh", "honey"]
|
23
|
-
assert_search "fresh honey", ["fresh", "honey"], {operator: "or"}
|
24
|
-
assert_search "fresh honey", [], {operator: "and"}
|
25
|
-
assert_search "fresh honey", ["fresh", "honey"], {operator: :or}
|
26
|
-
end
|
27
|
-
|
28
|
-
# def test_cheese_space_in_query
|
29
|
-
# store_names ["Pepperjack Cheese Skewers"]
|
30
|
-
# assert_search "pepper jack cheese skewers", ["Pepperjack Cheese Skewers"]
|
31
|
-
# end
|
32
|
-
|
33
|
-
def test_middle_token
|
34
|
-
store_names ["Dish Washer Amazing Organic Soap"]
|
35
|
-
assert_search "dish soap", ["Dish Washer Amazing Organic Soap"]
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_middle_token_wine
|
39
|
-
store_names ["Beringer Wine Founders Estate Chardonnay"]
|
40
|
-
assert_search "beringer chardonnay", ["Beringer Wine Founders Estate Chardonnay"]
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_percent
|
44
|
-
# Note: "2% Milk" doesn't get matched in ES below 5.1.1
|
45
|
-
# This could be a bug since it has an edit distance of 1
|
46
|
-
store_names ["1% Milk", "Whole Milk"]
|
47
|
-
assert_search "1%", ["1% Milk"]
|
48
|
-
end
|
49
|
-
|
50
|
-
# ascii
|
51
|
-
|
52
|
-
def test_jalapenos
|
53
|
-
store_names ["Jalapeño"]
|
54
|
-
assert_search "jalapeno", ["Jalapeño"]
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_swedish
|
58
|
-
store_names ["ÅÄÖ"]
|
59
|
-
assert_search "aao", ["ÅÄÖ"]
|
60
|
-
end
|
61
|
-
|
62
|
-
# stemming
|
63
|
-
|
64
|
-
def test_stemming
|
65
|
-
store_names ["Whole Milk", "Fat Free Milk", "Milk"]
|
66
|
-
assert_search "milks", ["Milk", "Whole Milk", "Fat Free Milk"]
|
67
|
-
end
|
68
|
-
|
69
|
-
# fuzzy
|
70
|
-
|
71
|
-
def test_misspelling_sriracha
|
72
|
-
store_names ["Sriracha"]
|
73
|
-
assert_search "siracha", ["Sriracha"]
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_misspelling_multiple
|
77
|
-
store_names ["Greek Yogurt", "Green Onions"]
|
78
|
-
assert_search "greed", ["Greek Yogurt", "Green Onions"]
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_short_word
|
82
|
-
store_names ["Finn"]
|
83
|
-
assert_search "fin", ["Finn"]
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_edit_distance_two
|
87
|
-
store_names ["Bingo"]
|
88
|
-
assert_search "bin", []
|
89
|
-
assert_search "bingooo", []
|
90
|
-
assert_search "mango", []
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_edit_distance_one
|
94
|
-
store_names ["Bingo"]
|
95
|
-
assert_search "bing", ["Bingo"]
|
96
|
-
assert_search "bingoo", ["Bingo"]
|
97
|
-
assert_search "ringo", ["Bingo"]
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_edit_distance_long_word
|
101
|
-
store_names ["thisisareallylongword"]
|
102
|
-
assert_search "thisisareallylongwor", ["thisisareallylongword"] # missing letter
|
103
|
-
assert_search "thisisareelylongword", [] # edit distance = 2
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_misspelling_tabasco
|
107
|
-
store_names ["Tabasco"]
|
108
|
-
assert_search "tobasco", ["Tabasco"]
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_misspelling_zucchini
|
112
|
-
store_names ["Zucchini"]
|
113
|
-
assert_search "zuchini", ["Zucchini"]
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_misspelling_ziploc
|
117
|
-
store_names ["Ziploc"]
|
118
|
-
assert_search "zip lock", ["Ziploc"]
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_misspelling_zucchini_transposition
|
122
|
-
store_names ["zucchini"]
|
123
|
-
assert_search "zuccihni", ["zucchini"]
|
124
|
-
|
125
|
-
# need to specify field
|
126
|
-
# as transposition option isn't supported for multi_match queries
|
127
|
-
# until Elasticsearch 6.1
|
128
|
-
assert_search "zuccihni", [], misspellings: {transpositions: false}, fields: [:name]
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_misspelling_lasagna
|
132
|
-
store_names ["lasagna"]
|
133
|
-
assert_search "lasanga", ["lasagna"], misspellings: {transpositions: true}
|
134
|
-
assert_search "lasgana", ["lasagna"], misspellings: {transpositions: true}
|
135
|
-
assert_search "lasaang", [], misspellings: {transpositions: true} # triple transposition, shouldn't work
|
136
|
-
assert_search "lsagana", [], misspellings: {transpositions: true} # triple transposition, shouldn't work
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_misspelling_lasagna_pasta
|
140
|
-
store_names ["lasagna pasta"]
|
141
|
-
assert_search "lasanga", ["lasagna pasta"], misspellings: {transpositions: true}
|
142
|
-
assert_search "lasanga pasta", ["lasagna pasta"], misspellings: {transpositions: true}
|
143
|
-
assert_search "lasanga pasat", ["lasagna pasta"], misspellings: {transpositions: true} # both words misspelled with a transposition should still work
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_misspellings_word_start
|
147
|
-
store_names ["Sriracha"]
|
148
|
-
assert_search "siracha", ["Sriracha"], fields: [{name: :word_start}]
|
149
|
-
end
|
150
|
-
|
151
|
-
# spaces
|
152
|
-
|
153
|
-
def test_spaces_in_field
|
154
|
-
store_names ["Red Bull"]
|
155
|
-
assert_search "redbull", ["Red Bull"]
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_spaces_in_query
|
159
|
-
store_names ["Dishwasher"]
|
160
|
-
assert_search "dish washer", ["Dishwasher"]
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_spaces_three_words
|
164
|
-
store_names ["Dish Washer Soap", "Dish Washer"]
|
165
|
-
assert_search "dish washer soap", ["Dish Washer Soap"]
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_spaces_stemming
|
169
|
-
store_names ["Almond Milk"]
|
170
|
-
assert_search "almondmilks", ["Almond Milk"]
|
171
|
-
end
|
172
|
-
|
173
|
-
# butter
|
174
|
-
|
175
|
-
def test_exclude_butter
|
176
|
-
store_names ["Butter Tub", "Peanut Butter Tub"]
|
177
|
-
assert_search "butter", ["Butter Tub"], exclude: ["peanut butter"]
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_exclude_butter_word_start
|
181
|
-
store_names ["Butter Tub", "Peanut Butter Tub"]
|
182
|
-
assert_search "butter", ["Butter Tub"], exclude: ["peanut butter"], match: :word_start
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_exclude_butter_exact
|
186
|
-
store_names ["Butter Tub", "Peanut Butter Tub"]
|
187
|
-
assert_search "butter", [], exclude: ["peanut butter"], fields: [{name: :exact}]
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_exclude_same_exact
|
191
|
-
store_names ["Butter Tub", "Peanut Butter Tub"]
|
192
|
-
assert_search "Butter Tub", ["Butter Tub"], exclude: ["Peanut Butter Tub"], fields: [{name: :exact}]
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_exclude_egg_word_start
|
196
|
-
store_names ["eggs", "eggplant"]
|
197
|
-
assert_search "egg", ["eggs"], exclude: ["eggplant"], match: :word_start
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_exclude_string
|
201
|
-
store_names ["Butter Tub", "Peanut Butter Tub"]
|
202
|
-
assert_search "butter", ["Butter Tub"], exclude: "peanut butter"
|
203
|
-
end
|
204
|
-
|
205
|
-
# other
|
206
|
-
|
207
|
-
def test_all
|
208
|
-
store_names ["Product A", "Product B"]
|
209
|
-
assert_search "*", ["Product A", "Product B"]
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_no_arguments
|
213
|
-
store_names []
|
214
|
-
assert_equal [], Product.search.to_a
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_no_term
|
218
|
-
store_names ["Product A"]
|
219
|
-
assert_equal ["Product A"], Product.search(where: {name: "Product A"}).map(&:name)
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_to_be_or_not_to_be
|
223
|
-
store_names ["to be or not to be"]
|
224
|
-
assert_search "to be", ["to be or not to be"]
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_apostrophe
|
228
|
-
store_names ["Ben and Jerry's"]
|
229
|
-
assert_search "ben and jerrys", ["Ben and Jerry's"]
|
230
|
-
end
|
231
|
-
|
232
|
-
def test_apostrophe_search
|
233
|
-
store_names ["Ben and Jerrys"]
|
234
|
-
assert_search "ben and jerry's", ["Ben and Jerrys"]
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_ampersand_index
|
238
|
-
store_names ["Ben & Jerry's"]
|
239
|
-
assert_search "ben and jerrys", ["Ben & Jerry's"]
|
240
|
-
end
|
241
|
-
|
242
|
-
def test_ampersand_search
|
243
|
-
store_names ["Ben and Jerry's"]
|
244
|
-
assert_search "ben & jerrys", ["Ben and Jerry's"]
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_phrase
|
248
|
-
store_names ["Fresh Honey", "Honey Fresh"]
|
249
|
-
assert_search "fresh honey", ["Fresh Honey"], match: :phrase
|
250
|
-
end
|
251
|
-
|
252
|
-
def test_phrase_again
|
253
|
-
store_names ["Social entrepreneurs don't have it easy raising capital"]
|
254
|
-
assert_search "social entrepreneurs don't have it easy raising capital", ["Social entrepreneurs don't have it easy raising capital"], match: :phrase
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_phrase_order
|
258
|
-
store_names ["Wheat Bread", "Whole Wheat Bread"]
|
259
|
-
assert_order "wheat bread", ["Wheat Bread", "Whole Wheat Bread"], match: :phrase, fields: [:name]
|
260
|
-
end
|
261
|
-
|
262
|
-
def test_dynamic_fields
|
263
|
-
store_names ["Red Bull"], Speaker
|
264
|
-
assert_search "redbull", ["Red Bull"], {fields: [:name]}, Speaker
|
265
|
-
end
|
266
|
-
|
267
|
-
def test_unsearchable
|
268
|
-
skip
|
269
|
-
store [
|
270
|
-
{name: "Unsearchable", description: "Almond"}
|
271
|
-
]
|
272
|
-
assert_search "almond", []
|
273
|
-
end
|
274
|
-
|
275
|
-
def test_unsearchable_where
|
276
|
-
store [
|
277
|
-
{name: "Unsearchable", description: "Almond"}
|
278
|
-
]
|
279
|
-
assert_search "*", ["Unsearchable"], where: {description: "Almond"}
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_emoji
|
283
|
-
skip unless defined?(EmojiParser)
|
284
|
-
store_names ["Banana"]
|
285
|
-
assert_search "🍌", ["Banana"], emoji: true
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_emoji_multiple
|
289
|
-
skip unless defined?(EmojiParser)
|
290
|
-
store_names ["Ice Cream Cake"]
|
291
|
-
assert_search "🍨🍰", ["Ice Cream Cake"], emoji: true
|
292
|
-
end
|
293
|
-
end
|