searchkick_bharthur 0.0.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 +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +44 -0
- data/CHANGELOG.md +360 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +1443 -0
- data/Rakefile +8 -0
- data/lib/searchkick/index.rb +662 -0
- data/lib/searchkick/logging.rb +185 -0
- data/lib/searchkick/middleware.rb +12 -0
- data/lib/searchkick/model.rb +105 -0
- data/lib/searchkick/query.rb +845 -0
- data/lib/searchkick/reindex_job.rb +26 -0
- data/lib/searchkick/reindex_v2_job.rb +23 -0
- data/lib/searchkick/results.rb +211 -0
- data/lib/searchkick/tasks.rb +33 -0
- data/lib/searchkick/version.rb +3 -0
- data/lib/searchkick.rb +159 -0
- data/searchkick.gemspec +28 -0
- data/test/aggs_test.rb +115 -0
- data/test/autocomplete_test.rb +65 -0
- data/test/boost_test.rb +144 -0
- data/test/callbacks_test.rb +27 -0
- data/test/ci/before_install.sh +21 -0
- data/test/dangerous_reindex_test.rb +27 -0
- data/test/facets_test.rb +90 -0
- data/test/gemfiles/activerecord31.gemfile +7 -0
- data/test/gemfiles/activerecord32.gemfile +7 -0
- data/test/gemfiles/activerecord40.gemfile +8 -0
- data/test/gemfiles/activerecord41.gemfile +8 -0
- data/test/gemfiles/activerecord50.gemfile +7 -0
- data/test/gemfiles/apartment.gemfile +8 -0
- data/test/gemfiles/mongoid2.gemfile +7 -0
- data/test/gemfiles/mongoid3.gemfile +6 -0
- data/test/gemfiles/mongoid4.gemfile +7 -0
- data/test/gemfiles/mongoid5.gemfile +7 -0
- data/test/gemfiles/nobrainer.gemfile +6 -0
- data/test/highlight_test.rb +63 -0
- data/test/index_test.rb +120 -0
- data/test/inheritance_test.rb +78 -0
- data/test/match_test.rb +227 -0
- data/test/misspellings_test.rb +46 -0
- data/test/model_test.rb +42 -0
- data/test/multi_search_test.rb +22 -0
- data/test/multi_tenancy_test.rb +22 -0
- data/test/order_test.rb +44 -0
- data/test/pagination_test.rb +53 -0
- data/test/query_test.rb +13 -0
- data/test/records_test.rb +8 -0
- data/test/reindex_job_test.rb +31 -0
- data/test/reindex_v2_job_test.rb +32 -0
- data/test/routing_test.rb +13 -0
- data/test/should_index_test.rb +32 -0
- data/test/similar_test.rb +28 -0
- data/test/sql_test.rb +196 -0
- data/test/suggest_test.rb +80 -0
- data/test/synonyms_test.rb +54 -0
- data/test/test_helper.rb +361 -0
- data/test/where_test.rb +171 -0
- metadata +231 -0
data/test/match_test.rb
ADDED
@@ -0,0 +1,227 @@
|
|
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_cheese_space_in_query
|
22
|
+
# store_names ["Pepperjack Cheese Skewers"]
|
23
|
+
# assert_search "pepper jack cheese skewers", ["Pepperjack Cheese Skewers"]
|
24
|
+
# end
|
25
|
+
|
26
|
+
def test_middle_token
|
27
|
+
store_names ["Dish Washer Amazing Organic Soap"]
|
28
|
+
assert_search "dish soap", ["Dish Washer Amazing Organic Soap"]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_middle_token_wine
|
32
|
+
store_names ["Beringer Wine Founders Estate Chardonnay"]
|
33
|
+
assert_search "beringer chardonnay", ["Beringer Wine Founders Estate Chardonnay"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_percent
|
37
|
+
store_names ["1% Milk", "2% Milk", "Whole Milk"]
|
38
|
+
assert_search "1%", ["1% Milk"]
|
39
|
+
end
|
40
|
+
|
41
|
+
# ascii
|
42
|
+
|
43
|
+
def test_jalapenos
|
44
|
+
store_names ["Jalapeño"]
|
45
|
+
assert_search "jalapeno", ["Jalapeño"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_swedish
|
49
|
+
store_names ["ÅÄÖ"]
|
50
|
+
assert_search "aao", ["ÅÄÖ"]
|
51
|
+
end
|
52
|
+
|
53
|
+
# stemming
|
54
|
+
|
55
|
+
def test_stemming
|
56
|
+
store_names ["Whole Milk", "Fat Free Milk", "Milk"]
|
57
|
+
assert_search "milks", ["Milk", "Whole Milk", "Fat Free Milk"]
|
58
|
+
end
|
59
|
+
|
60
|
+
# fuzzy
|
61
|
+
|
62
|
+
def test_misspelling_sriracha
|
63
|
+
store_names ["Sriracha"]
|
64
|
+
assert_search "siracha", ["Sriracha"]
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_misspelling_multiple
|
68
|
+
store_names ["Greek Yogurt", "Green Onions"]
|
69
|
+
assert_search "greed", ["Greek Yogurt", "Green Onions"]
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_short_word
|
73
|
+
store_names ["Finn"]
|
74
|
+
assert_search "fin", ["Finn"]
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_edit_distance_two
|
78
|
+
store_names ["Bingo"]
|
79
|
+
assert_search "bin", []
|
80
|
+
assert_search "bingooo", []
|
81
|
+
assert_search "mango", []
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_edit_distance_one
|
85
|
+
store_names ["Bingo"]
|
86
|
+
assert_search "bing", ["Bingo"]
|
87
|
+
assert_search "bingoo", ["Bingo"]
|
88
|
+
assert_search "ringo", ["Bingo"]
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_edit_distance_long_word
|
92
|
+
store_names ["thisisareallylongword"]
|
93
|
+
assert_search "thisisareallylongwor", ["thisisareallylongword"] # missing letter
|
94
|
+
assert_search "thisisareelylongword", [] # edit distance = 2
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_misspelling_tabasco
|
98
|
+
store_names ["Tabasco"]
|
99
|
+
assert_search "tobasco", ["Tabasco"]
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_misspelling_zucchini
|
103
|
+
store_names ["Zucchini"]
|
104
|
+
assert_search "zuchini", ["Zucchini"]
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_misspelling_ziploc
|
108
|
+
store_names ["Ziploc"]
|
109
|
+
assert_search "zip lock", ["Ziploc"]
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_misspelling_zucchini_transposition
|
113
|
+
skip if elasticsearch_below14?
|
114
|
+
store_names ["zucchini"]
|
115
|
+
assert_search "zuccihni", ["zucchini"]
|
116
|
+
assert_search "zuccihni", [], misspellings: {transpositions: false}
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_misspelling_lasagna
|
120
|
+
skip if elasticsearch_below14?
|
121
|
+
store_names ["lasagna"]
|
122
|
+
assert_search "lasanga", ["lasagna"], misspellings: {transpositions: true}
|
123
|
+
assert_search "lasgana", ["lasagna"], misspellings: {transpositions: true}
|
124
|
+
assert_search "lasaang", [], misspellings: {transpositions: true} # triple transposition, shouldn't work
|
125
|
+
assert_search "lsagana", [], misspellings: {transpositions: true} # triple transposition, shouldn't work
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_misspelling_lasagna_pasta
|
129
|
+
skip if elasticsearch_below14?
|
130
|
+
store_names ["lasagna pasta"]
|
131
|
+
assert_search "lasanga", ["lasagna pasta"], misspellings: {transpositions: true}
|
132
|
+
assert_search "lasanga pasta", ["lasagna pasta"], misspellings: {transpositions: true}
|
133
|
+
assert_search "lasanga pasat", ["lasagna pasta"], misspellings: {transpositions: true} # both words misspelled with a transposition should still work
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_misspellings_word_start
|
137
|
+
store_names ["Sriracha"]
|
138
|
+
assert_search "siracha", ["Sriracha"], fields: [{name: :word_start}]
|
139
|
+
end
|
140
|
+
|
141
|
+
# spaces
|
142
|
+
|
143
|
+
def test_spaces_in_field
|
144
|
+
store_names ["Red Bull"]
|
145
|
+
assert_search "redbull", ["Red Bull"]
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_spaces_in_query
|
149
|
+
store_names ["Dishwasher"]
|
150
|
+
assert_search "dish washer", ["Dishwasher"]
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_spaces_three_words
|
154
|
+
store_names ["Dish Washer Soap", "Dish Washer"]
|
155
|
+
assert_search "dish washer soap", ["Dish Washer Soap"]
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_spaces_stemming
|
159
|
+
store_names ["Almond Milk"]
|
160
|
+
assert_search "almondmilks", ["Almond Milk"]
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_all
|
164
|
+
store_names ["Product A", "Product B"]
|
165
|
+
assert_search "*", ["Product A", "Product B"]
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_no_arguments
|
169
|
+
assert_equal [], Product.search.to_a
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_no_term
|
173
|
+
store_names ["Product A"]
|
174
|
+
assert_equal ["Product A"], Product.search(where: {name: "Product A"}).map(&:name)
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_to_be_or_not_to_be
|
178
|
+
store_names ["to be or not to be"]
|
179
|
+
assert_search "to be", ["to be or not to be"]
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_apostrophe
|
183
|
+
store_names ["Ben and Jerry's"]
|
184
|
+
assert_search "ben and jerrys", ["Ben and Jerry's"]
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_ampersand_index
|
188
|
+
store_names ["Ben & Jerry's"]
|
189
|
+
assert_search "ben and jerrys", ["Ben & Jerry's"]
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_ampersand_search
|
193
|
+
store_names ["Ben and Jerry's"]
|
194
|
+
assert_search "ben & jerrys", ["Ben and Jerry's"]
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_phrase
|
198
|
+
store_names ["Fresh Honey", "Honey Fresh"]
|
199
|
+
assert_search "fresh honey", ["Fresh Honey"], match: :phrase
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_unsearchable
|
203
|
+
store [
|
204
|
+
{name: "Unsearchable", description: "Almond"}
|
205
|
+
]
|
206
|
+
assert_search "almond", []
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_unsearchable_where
|
210
|
+
store [
|
211
|
+
{name: "Unsearchable", description: "Almond"}
|
212
|
+
]
|
213
|
+
assert_search "*", ["Unsearchable"], where: {description: "Almond"}
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_emoji
|
217
|
+
skip unless defined?(EmojiParser)
|
218
|
+
store_names ["Banana"]
|
219
|
+
assert_search "🍌", ["Banana"], emoji: true
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_emoji_multiple
|
223
|
+
skip unless defined?(EmojiParser)
|
224
|
+
store_names ["Ice Cream Cake"]
|
225
|
+
assert_search "🍨🍰", ["Ice Cream Cake"], emoji: true
|
226
|
+
end
|
227
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class MisspellingsTest < Minitest::Test
|
4
|
+
def test_misspellings
|
5
|
+
store_names ["abc", "abd", "aee"]
|
6
|
+
assert_search "abc", ["abc"], misspellings: false
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_misspellings_distance
|
10
|
+
store_names ["abbb", "aabb"]
|
11
|
+
assert_search "aaaa", ["aabb"], misspellings: {distance: 2}
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_misspellings_prefix_length
|
15
|
+
store_names ["ap", "api", "apt", "any", "nap", "ah", "ahi"]
|
16
|
+
assert_search "ap", ["ap"], misspellings: {prefix_length: 2}
|
17
|
+
assert_search "api", ["ap", "api", "apt"], misspellings: {prefix_length: 2}
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_misspellings_prefix_length_operator
|
21
|
+
store_names ["ap", "api", "apt", "any", "nap", "ah", "aha"]
|
22
|
+
assert_search "ap ah", ["ap", "ah"], operator: "or", misspellings: {prefix_length: 2}
|
23
|
+
assert_search "api ahi", ["ap", "api", "apt", "ah", "aha"], operator: "or", misspellings: {prefix_length: 2}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_misspellings_fields_operator
|
27
|
+
store [
|
28
|
+
{name: "red", color: "red"},
|
29
|
+
{name: "blue", color: "blue"},
|
30
|
+
{name: "cyan", color: "blue green"},
|
31
|
+
{name: "magenta", color: "red blue"},
|
32
|
+
{name: "green", color: "green"}
|
33
|
+
]
|
34
|
+
assert_search "red blue", ["red", "blue", "cyan", "magenta"], operator: "or", fields: ["color"], misspellings: false
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_misspellings_below_unmet
|
38
|
+
store_names ["abc", "abd", "aee"]
|
39
|
+
assert_search "abc", ["abc", "abd"], misspellings: {below: 2}
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_misspellings_below_met
|
43
|
+
store_names ["abc", "abd", "aee"]
|
44
|
+
assert_search "abc", ["abc"], misspellings: {below: 1}
|
45
|
+
end
|
46
|
+
end
|
data/test/model_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class ModelTest < Minitest::Test
|
4
|
+
def test_disable_callbacks_model
|
5
|
+
store_names ["product a"]
|
6
|
+
|
7
|
+
Product.disable_search_callbacks
|
8
|
+
assert !Product.search_callbacks?
|
9
|
+
|
10
|
+
store_names ["product b"]
|
11
|
+
assert_search "product", ["product a"]
|
12
|
+
|
13
|
+
Product.enable_search_callbacks
|
14
|
+
Product.reindex
|
15
|
+
|
16
|
+
assert_search "product", ["product a", "product b"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_disable_callbacks_global
|
20
|
+
# make sure callbacks default to on
|
21
|
+
assert Searchkick.callbacks?
|
22
|
+
|
23
|
+
store_names ["product a"]
|
24
|
+
|
25
|
+
Searchkick.disable_callbacks
|
26
|
+
assert !Searchkick.callbacks?
|
27
|
+
|
28
|
+
store_names ["product b"]
|
29
|
+
assert_search "product", ["product a"]
|
30
|
+
|
31
|
+
Searchkick.enable_callbacks
|
32
|
+
Product.reindex
|
33
|
+
|
34
|
+
assert_search "product", ["product a", "product b"]
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_multiple_models
|
38
|
+
store_names ["Product A"]
|
39
|
+
store_names ["Product B"], Store
|
40
|
+
assert_equal Product.all + Store.all, Searchkick.search("product", index_name: [Product, Store], order: "name").to_a
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class MultiSearchTest < Minitest::Test
|
4
|
+
def test_basic
|
5
|
+
store_names ["Product A"]
|
6
|
+
store_names ["Store A"], Store
|
7
|
+
products = Product.search("*", execute: false)
|
8
|
+
stores = Store.search("*", execute: false)
|
9
|
+
Searchkick.multi_search([products, stores])
|
10
|
+
assert_equal ["Product A"], products.map(&:name)
|
11
|
+
assert_equal ["Store A"], stores.map(&:name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_error
|
15
|
+
store_names ["Product A"]
|
16
|
+
products = Product.search("*", execute: false)
|
17
|
+
stores = Store.search("*", order: [:bad_field], execute: false)
|
18
|
+
Searchkick.multi_search([products, stores])
|
19
|
+
assert !products.error
|
20
|
+
assert stores.error
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class MultiTenancyTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
skip unless defined?(Apartment)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_basic
|
9
|
+
Apartment::Tenant.switch!("tenant1")
|
10
|
+
store_names ["Product A"], Tenant
|
11
|
+
Apartment::Tenant.switch!("tenant2")
|
12
|
+
store_names ["Product B"], Tenant
|
13
|
+
Apartment::Tenant.switch!("tenant1")
|
14
|
+
assert_search "product", ["Product A"], {load: false}, Tenant
|
15
|
+
Apartment::Tenant.switch!("tenant2")
|
16
|
+
assert_search "product", ["Product B"], {load: false}, Tenant
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
Apartment::Tenant.reset if defined?(Apartment)
|
21
|
+
end
|
22
|
+
end
|
data/test/order_test.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class OrderTest < Minitest::Test
|
4
|
+
def test_order_hash
|
5
|
+
store_names ["Product A", "Product B", "Product C", "Product D"]
|
6
|
+
assert_order "product", ["Product D", "Product C", "Product B", "Product A"], order: {name: :desc}
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_order_string
|
10
|
+
store_names ["Product A", "Product B", "Product C", "Product D"]
|
11
|
+
assert_order "product", ["Product A", "Product B", "Product C", "Product D"], order: "name"
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_order_id
|
15
|
+
store_names ["Product A", "Product B"]
|
16
|
+
product_a = Product.where(name: "Product A").first
|
17
|
+
product_b = Product.where(name: "Product B").first
|
18
|
+
assert_order "product", [product_a, product_b].sort_by(&:id).map(&:name), order: {id: :asc}
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_order_multiple
|
22
|
+
store [
|
23
|
+
{name: "Product A", color: "blue", store_id: 1},
|
24
|
+
{name: "Product B", color: "red", store_id: 3},
|
25
|
+
{name: "Product C", color: "red", store_id: 2}
|
26
|
+
]
|
27
|
+
assert_order "product", ["Product A", "Product B", "Product C"], order: {color: :asc, store_id: :desc}
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_order_ignore_unmapped
|
31
|
+
skip unless elasticsearch_below50?
|
32
|
+
assert_order "product", [], order: {not_mapped: {ignore_unmapped: true}}
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_order_unmapped_type
|
36
|
+
skip if elasticsearch_below50?
|
37
|
+
assert_order "product", [], order: {not_mapped: {unmapped_type: "long"}}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_order_array
|
41
|
+
store [{name: "San Francisco", latitude: 37.7833, longitude: -122.4167}]
|
42
|
+
assert_order "francisco", ["San Francisco"], order: [{_geo_distance: {location: "0,0"}}]
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class PaginationTest < Minitest::Test
|
4
|
+
def test_limit
|
5
|
+
store_names ["Product A", "Product B", "Product C", "Product D"]
|
6
|
+
assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_no_limit
|
10
|
+
names = 20.times.map { |i| "Product #{i}" }
|
11
|
+
store_names names
|
12
|
+
assert_search "product", names
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_offset
|
16
|
+
store_names ["Product A", "Product B", "Product C", "Product D"]
|
17
|
+
assert_order "product", ["Product C", "Product D"], order: {name: :asc}, offset: 2
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_pagination
|
21
|
+
store_names ["Product A", "Product B", "Product C", "Product D", "Product E", "Product F"]
|
22
|
+
products = Product.search("product", order: {name: :asc}, page: 2, per_page: 2, padding: 1)
|
23
|
+
assert_equal ["Product D", "Product E"], products.map(&:name)
|
24
|
+
assert_equal "product", products.entry_name
|
25
|
+
assert_equal 2, products.current_page
|
26
|
+
assert_equal 1, products.padding
|
27
|
+
assert_equal 2, products.per_page
|
28
|
+
assert_equal 2, products.size
|
29
|
+
assert_equal 2, products.length
|
30
|
+
assert_equal 3, products.total_pages
|
31
|
+
assert_equal 6, products.total_count
|
32
|
+
assert_equal 6, products.total_entries
|
33
|
+
assert_equal 2, products.limit_value
|
34
|
+
assert_equal 3, products.offset_value
|
35
|
+
assert_equal 3, products.offset
|
36
|
+
assert_equal 3, products.next_page
|
37
|
+
assert_equal 1, products.previous_page
|
38
|
+
assert_equal 1, products.prev_page
|
39
|
+
assert !products.first_page?
|
40
|
+
assert !products.last_page?
|
41
|
+
assert !products.empty?
|
42
|
+
assert !products.out_of_range?
|
43
|
+
assert products.any?
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_pagination_nil_page
|
47
|
+
store_names ["Product A", "Product B", "Product C", "Product D", "Product E"]
|
48
|
+
products = Product.search("product", order: {name: :asc}, page: nil, per_page: 2)
|
49
|
+
assert_equal ["Product A", "Product B"], products.map(&:name)
|
50
|
+
assert_equal 1, products.current_page
|
51
|
+
assert products.first_page?
|
52
|
+
end
|
53
|
+
end
|
data/test/query_test.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class QueryTest < Minitest::Test
|
4
|
+
def test_basic
|
5
|
+
store_names ["Milk", "Apple"]
|
6
|
+
query = Product.search("milk", execute: false)
|
7
|
+
# query.body = {query: {match_all: {}}}
|
8
|
+
# query.body = {query: {match: {name: "Apple"}}}
|
9
|
+
query.body[:query] = {match_all: {}}
|
10
|
+
assert_equal ["Apple", "Milk"], query.map(&:name).sort
|
11
|
+
assert_equal ["Apple", "Milk"], query.execute.map(&:name).sort
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class ReindexJobTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
Searchkick.disable_callbacks
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
Searchkick.enable_callbacks
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_create
|
14
|
+
product = Product.create!(name: "Boom")
|
15
|
+
Product.searchkick_index.refresh
|
16
|
+
assert_search "*", []
|
17
|
+
Searchkick::ReindexJob.new("Product", product.id.to_s).perform
|
18
|
+
Product.searchkick_index.refresh
|
19
|
+
assert_search "*", ["Boom"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_destroy
|
23
|
+
product = Product.create!(name: "Boom")
|
24
|
+
Product.reindex
|
25
|
+
assert_search "*", ["Boom"]
|
26
|
+
product.destroy
|
27
|
+
Searchkick::ReindexJob.new("Product", product.id.to_s).perform
|
28
|
+
Product.searchkick_index.refresh
|
29
|
+
assert_search "*", []
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class ReindexV2JobTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
skip unless defined?(ActiveJob)
|
6
|
+
super
|
7
|
+
Searchkick.disable_callbacks
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
Searchkick.enable_callbacks
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_create
|
15
|
+
product = Product.create!(name: "Boom")
|
16
|
+
Product.searchkick_index.refresh
|
17
|
+
assert_search "*", []
|
18
|
+
Searchkick::ReindexV2Job.perform_later("Product", product.id.to_s)
|
19
|
+
Product.searchkick_index.refresh
|
20
|
+
assert_search "*", ["Boom"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_destroy
|
24
|
+
product = Product.create!(name: "Boom")
|
25
|
+
Product.reindex
|
26
|
+
assert_search "*", ["Boom"]
|
27
|
+
product.destroy
|
28
|
+
Searchkick::ReindexV2Job.perform_later("Product", product.id.to_s)
|
29
|
+
Product.searchkick_index.refresh
|
30
|
+
assert_search "*", []
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class RoutingTest < Minitest::Test
|
4
|
+
def test_routing_query
|
5
|
+
query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false)
|
6
|
+
assert_equal query.params[:routing], "Dollar Tree"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_routing_mappings
|
10
|
+
index_options = Store.searchkick_index.index_options
|
11
|
+
assert_equal index_options[:mappings][:_default_][:_routing], required: true
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class ShouldIndexTest < Minitest::Test
|
4
|
+
def test_basic
|
5
|
+
store_names ["INDEX", "DO NOT INDEX"]
|
6
|
+
assert_search "index", ["INDEX"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_default_true
|
10
|
+
assert Animal.new.should_index?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_change_to_true
|
14
|
+
store_names ["DO NOT INDEX"]
|
15
|
+
assert_search "index", []
|
16
|
+
product = Product.first
|
17
|
+
product.name = "INDEX"
|
18
|
+
product.save!
|
19
|
+
Product.searchkick_index.refresh
|
20
|
+
assert_search "index", ["INDEX"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_change_to_false
|
24
|
+
store_names ["INDEX"]
|
25
|
+
assert_search "index", ["INDEX"]
|
26
|
+
product = Product.first
|
27
|
+
product.name = "DO NOT INDEX"
|
28
|
+
product.save!
|
29
|
+
Product.searchkick_index.refresh
|
30
|
+
assert_search "index", []
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class SimilarTest < Minitest::Test
|
4
|
+
def test_similar
|
5
|
+
store_names ["Annie's Naturals Organic Shiitake & Sesame Dressing"]
|
6
|
+
assert_search "Annie's Naturals Shiitake & Sesame Vinaigrette", ["Annie's Naturals Organic Shiitake & Sesame Dressing"], similar: true
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_fields
|
10
|
+
store_names ["1% Organic Milk", "2% Organic Milk", "Popcorn"]
|
11
|
+
assert_equal ["2% Organic Milk"], Product.where(name: "1% Organic Milk").first.similar(fields: ["name"]).map(&:name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_order
|
15
|
+
store_names ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"]
|
16
|
+
assert_order "Lucerne Fat Free Chocolate Milk", ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"], similar: true
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_limit
|
20
|
+
store_names ["1% Organic Milk", "2% Organic Milk", "Fat Free Organic Milk", "Popcorn"]
|
21
|
+
assert_equal ["2% Organic Milk"], Product.where(name: "1% Organic Milk").first.similar(fields: ["name"], order: ["name"], limit: 1).map(&:name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_per_page
|
25
|
+
store_names ["1% Organic Milk", "2% Organic Milk", "Fat Free Organic Milk", "Popcorn"]
|
26
|
+
assert_equal ["2% Organic Milk"], Product.where(name: "1% Organic Milk").first.similar(fields: ["name"], order: ["name"], per_page: 1).map(&:name)
|
27
|
+
end
|
28
|
+
end
|