searchkick 2.3.2 → 4.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +251 -84
  3. data/LICENSE.txt +1 -1
  4. data/README.md +552 -432
  5. data/lib/searchkick/bulk_indexer.rb +173 -0
  6. data/lib/searchkick/bulk_reindex_job.rb +2 -2
  7. data/lib/searchkick/hash_wrapper.rb +12 -0
  8. data/lib/searchkick/index.rb +187 -348
  9. data/lib/searchkick/index_options.rb +494 -282
  10. data/lib/searchkick/logging.rb +17 -13
  11. data/lib/searchkick/model.rb +52 -97
  12. data/lib/searchkick/multi_search.rb +9 -10
  13. data/lib/searchkick/process_batch_job.rb +17 -4
  14. data/lib/searchkick/process_queue_job.rb +20 -12
  15. data/lib/searchkick/query.rb +415 -199
  16. data/lib/searchkick/railtie.rb +7 -0
  17. data/lib/searchkick/record_data.rb +128 -0
  18. data/lib/searchkick/record_indexer.rb +79 -0
  19. data/lib/searchkick/reindex_queue.rb +1 -1
  20. data/lib/searchkick/reindex_v2_job.rb +14 -12
  21. data/lib/searchkick/results.rb +135 -41
  22. data/lib/searchkick/version.rb +1 -1
  23. data/lib/searchkick.rb +130 -61
  24. data/lib/tasks/searchkick.rake +34 -0
  25. metadata +18 -162
  26. data/.gitignore +0 -22
  27. data/.travis.yml +0 -39
  28. data/Gemfile +0 -16
  29. data/Rakefile +0 -20
  30. data/benchmark/Gemfile +0 -23
  31. data/benchmark/benchmark.rb +0 -97
  32. data/lib/searchkick/tasks.rb +0 -33
  33. data/searchkick.gemspec +0 -28
  34. data/test/aggs_test.rb +0 -197
  35. data/test/autocomplete_test.rb +0 -75
  36. data/test/boost_test.rb +0 -202
  37. data/test/callbacks_test.rb +0 -59
  38. data/test/ci/before_install.sh +0 -17
  39. data/test/errors_test.rb +0 -19
  40. data/test/gemfiles/activerecord31.gemfile +0 -7
  41. data/test/gemfiles/activerecord32.gemfile +0 -7
  42. data/test/gemfiles/activerecord40.gemfile +0 -8
  43. data/test/gemfiles/activerecord41.gemfile +0 -8
  44. data/test/gemfiles/activerecord42.gemfile +0 -7
  45. data/test/gemfiles/activerecord50.gemfile +0 -7
  46. data/test/gemfiles/apartment.gemfile +0 -8
  47. data/test/gemfiles/cequel.gemfile +0 -8
  48. data/test/gemfiles/mongoid2.gemfile +0 -7
  49. data/test/gemfiles/mongoid3.gemfile +0 -6
  50. data/test/gemfiles/mongoid4.gemfile +0 -7
  51. data/test/gemfiles/mongoid5.gemfile +0 -7
  52. data/test/gemfiles/mongoid6.gemfile +0 -12
  53. data/test/gemfiles/nobrainer.gemfile +0 -8
  54. data/test/gemfiles/parallel_tests.gemfile +0 -8
  55. data/test/geo_shape_test.rb +0 -175
  56. data/test/highlight_test.rb +0 -78
  57. data/test/index_test.rb +0 -166
  58. data/test/inheritance_test.rb +0 -83
  59. data/test/marshal_test.rb +0 -8
  60. data/test/match_test.rb +0 -276
  61. data/test/misspellings_test.rb +0 -56
  62. data/test/model_test.rb +0 -42
  63. data/test/multi_search_test.rb +0 -36
  64. data/test/multi_tenancy_test.rb +0 -22
  65. data/test/order_test.rb +0 -46
  66. data/test/pagination_test.rb +0 -70
  67. data/test/partial_reindex_test.rb +0 -58
  68. data/test/query_test.rb +0 -35
  69. data/test/records_test.rb +0 -10
  70. data/test/reindex_test.rb +0 -64
  71. data/test/reindex_v2_job_test.rb +0 -32
  72. data/test/routing_test.rb +0 -23
  73. data/test/should_index_test.rb +0 -32
  74. data/test/similar_test.rb +0 -28
  75. data/test/sql_test.rb +0 -214
  76. data/test/suggest_test.rb +0 -95
  77. data/test/support/kaminari.yml +0 -21
  78. data/test/synonyms_test.rb +0 -67
  79. data/test/test_helper.rb +0 -567
  80. data/test/where_test.rb +0 -223
@@ -1,83 +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
- Animal.searchkick_index.refresh
13
- assert_equal 1, Animal.search("*").size
14
- end
15
-
16
- def test_child_index_name
17
- assert_equal "animals-#{Date.today.year}", Dog.searchkick_index.name
18
- end
19
-
20
- def test_child_search
21
- store_names ["Bear"], Dog
22
- store_names ["Bear"], Cat
23
- assert_equal 1, Dog.search("bear").size
24
- end
25
-
26
- def test_parent_search
27
- store_names ["Bear"], Dog
28
- store_names ["Bear"], Cat
29
- assert_equal 2, Animal.search("bear").size
30
- end
31
-
32
- def test_force_one_type
33
- store_names ["Green Bear"], Dog
34
- store_names ["Blue Bear"], Cat
35
- assert_equal ["Blue Bear"], Animal.search("bear", type: [Cat]).map(&:name)
36
- end
37
-
38
- def test_force_multiple_types
39
- store_names ["Green Bear"], Dog
40
- store_names ["Blue Bear"], Cat
41
- store_names ["Red Bear"], Animal
42
- assert_equal ["Green Bear", "Blue Bear"], Animal.search("bear", type: [Dog, Cat]).map(&:name)
43
- end
44
-
45
- def test_child_autocomplete
46
- store_names ["Max"], Cat
47
- store_names ["Mark"], Dog
48
- assert_equal ["Max"], Cat.search("ma", fields: [:name], match: :text_start).map(&:name)
49
- end
50
-
51
- def test_parent_autocomplete
52
- store_names ["Max"], Cat
53
- store_names ["Bear"], Dog
54
- assert_equal ["Bear"], Animal.search("bea", fields: [:name], match: :text_start).map(&:name).sort
55
- end
56
-
57
- # def test_child_suggest
58
- # store_names ["Shark"], Cat
59
- # store_names ["Sharp"], Dog
60
- # assert_equal ["shark"], Cat.search("shar", fields: [:name], suggest: true).suggestions
61
- # end
62
-
63
- def test_parent_suggest
64
- store_names ["Shark"], Cat
65
- store_names ["Tiger"], Dog
66
- assert_equal ["tiger"], Animal.search("tige", fields: [:name], suggest: true).suggestions.sort
67
- end
68
-
69
- def test_reindex
70
- store_names ["Bear A"], Cat
71
- store_names ["Bear B"], Dog
72
- Animal.reindex
73
- assert_equal 1, Dog.search("bear").size
74
- end
75
-
76
- # TODO move somewhere better
77
-
78
- def test_multiple_indices
79
- store_names ["Product A"]
80
- store_names ["Product B"], Animal
81
- assert_search "product", ["Product A", "Product B"], index_name: [Product.searchkick_index.name, Animal.searchkick_index.name], conversions: false
82
- end
83
- end
data/test/marshal_test.rb DELETED
@@ -1,8 +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("*", load: {dumpable: true}).results)
7
- end
8
- end
data/test/match_test.rb DELETED
@@ -1,276 +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_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
- # Note: "2% Milk" doesn't get matched in ES below 5.1.1
38
- # This could be a bug since it has an edit distance of 1
39
- store_names ["1% Milk", "Whole Milk"]
40
- assert_search "1%", ["1% Milk"]
41
- end
42
-
43
- # ascii
44
-
45
- def test_jalapenos
46
- store_names ["Jalapeño"]
47
- assert_search "jalapeno", ["Jalapeño"]
48
- end
49
-
50
- def test_swedish
51
- store_names ["ÅÄÖ"]
52
- assert_search "aao", ["ÅÄÖ"]
53
- end
54
-
55
- # stemming
56
-
57
- def test_stemming
58
- store_names ["Whole Milk", "Fat Free Milk", "Milk"]
59
- assert_search "milks", ["Milk", "Whole Milk", "Fat Free Milk"]
60
- end
61
-
62
- # fuzzy
63
-
64
- def test_misspelling_sriracha
65
- store_names ["Sriracha"]
66
- assert_search "siracha", ["Sriracha"]
67
- end
68
-
69
- def test_misspelling_multiple
70
- store_names ["Greek Yogurt", "Green Onions"]
71
- assert_search "greed", ["Greek Yogurt", "Green Onions"]
72
- end
73
-
74
- def test_short_word
75
- store_names ["Finn"]
76
- assert_search "fin", ["Finn"]
77
- end
78
-
79
- def test_edit_distance_two
80
- store_names ["Bingo"]
81
- assert_search "bin", []
82
- assert_search "bingooo", []
83
- assert_search "mango", []
84
- end
85
-
86
- def test_edit_distance_one
87
- store_names ["Bingo"]
88
- assert_search "bing", ["Bingo"]
89
- assert_search "bingoo", ["Bingo"]
90
- assert_search "ringo", ["Bingo"]
91
- end
92
-
93
- def test_edit_distance_long_word
94
- store_names ["thisisareallylongword"]
95
- assert_search "thisisareallylongwor", ["thisisareallylongword"] # missing letter
96
- assert_search "thisisareelylongword", [] # edit distance = 2
97
- end
98
-
99
- def test_misspelling_tabasco
100
- store_names ["Tabasco"]
101
- assert_search "tobasco", ["Tabasco"]
102
- end
103
-
104
- def test_misspelling_zucchini
105
- store_names ["Zucchini"]
106
- assert_search "zuchini", ["Zucchini"]
107
- end
108
-
109
- def test_misspelling_ziploc
110
- store_names ["Ziploc"]
111
- assert_search "zip lock", ["Ziploc"]
112
- end
113
-
114
- def test_misspelling_zucchini_transposition
115
- store_names ["zucchini"]
116
- assert_search "zuccihni", ["zucchini"]
117
- assert_search "zuccihni", [], misspellings: {transpositions: false}
118
- end
119
-
120
- def test_misspelling_lasagna
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
- store_names ["lasagna pasta"]
130
- assert_search "lasanga", ["lasagna pasta"], misspellings: {transpositions: true}
131
- assert_search "lasanga pasta", ["lasagna pasta"], misspellings: {transpositions: true}
132
- assert_search "lasanga pasat", ["lasagna pasta"], misspellings: {transpositions: true} # both words misspelled with a transposition should still work
133
- end
134
-
135
- def test_misspellings_word_start
136
- store_names ["Sriracha"]
137
- assert_search "siracha", ["Sriracha"], fields: [{name: :word_start}]
138
- end
139
-
140
- # spaces
141
-
142
- def test_spaces_in_field
143
- store_names ["Red Bull"]
144
- assert_search "redbull", ["Red Bull"]
145
- end
146
-
147
- def test_spaces_in_query
148
- store_names ["Dishwasher"]
149
- assert_search "dish washer", ["Dishwasher"]
150
- end
151
-
152
- def test_spaces_three_words
153
- store_names ["Dish Washer Soap", "Dish Washer"]
154
- assert_search "dish washer soap", ["Dish Washer Soap"]
155
- end
156
-
157
- def test_spaces_stemming
158
- store_names ["Almond Milk"]
159
- assert_search "almondmilks", ["Almond Milk"]
160
- end
161
-
162
- # butter
163
-
164
- def test_exclude_butter
165
- store_names ["Butter Tub", "Peanut Butter Tub"]
166
- assert_search "butter", ["Butter Tub"], exclude: ["peanut butter"]
167
- end
168
-
169
- def test_exclude_butter_word_start
170
- store_names ["Butter Tub", "Peanut Butter Tub"]
171
- assert_search "butter", ["Butter Tub"], exclude: ["peanut butter"], match: :word_start
172
- end
173
-
174
- def test_exclude_butter_exact
175
- store_names ["Butter Tub", "Peanut Butter Tub"]
176
- assert_search "butter", [], exclude: ["peanut butter"], match: :exact
177
- end
178
-
179
- def test_exclude_same_exact
180
- store_names ["Butter Tub", "Peanut Butter Tub"]
181
- assert_search "Butter Tub", [], exclude: ["Butter Tub"], match: :exact
182
- end
183
-
184
- def test_exclude_egg_word_start
185
- store_names ["eggs", "eggplant"]
186
- assert_search "egg", ["eggs"], exclude: ["eggplant"], match: :word_start
187
- end
188
-
189
- def test_exclude_string
190
- store_names ["Butter Tub", "Peanut Butter Tub"]
191
- assert_search "butter", ["Butter Tub"], exclude: "peanut butter"
192
- end
193
-
194
- # other
195
-
196
- def test_all
197
- store_names ["Product A", "Product B"]
198
- assert_search "*", ["Product A", "Product B"]
199
- end
200
-
201
- def test_no_arguments
202
- store_names []
203
- assert_equal [], Product.search.to_a
204
- end
205
-
206
- def test_no_term
207
- store_names ["Product A"]
208
- assert_equal ["Product A"], Product.search(where: {name: "Product A"}).map(&:name)
209
- end
210
-
211
- def test_to_be_or_not_to_be
212
- store_names ["to be or not to be"]
213
- assert_search "to be", ["to be or not to be"]
214
- end
215
-
216
- def test_apostrophe
217
- store_names ["Ben and Jerry's"]
218
- assert_search "ben and jerrys", ["Ben and Jerry's"]
219
- end
220
-
221
- def test_apostrophe_search
222
- store_names ["Ben and Jerrys"]
223
- assert_search "ben and jerry's", ["Ben and Jerrys"]
224
- end
225
-
226
- def test_ampersand_index
227
- store_names ["Ben & Jerry's"]
228
- assert_search "ben and jerrys", ["Ben & Jerry's"]
229
- end
230
-
231
- def test_ampersand_search
232
- store_names ["Ben and Jerry's"]
233
- assert_search "ben & jerrys", ["Ben and Jerry's"]
234
- end
235
-
236
- def test_phrase
237
- store_names ["Fresh Honey", "Honey Fresh"]
238
- assert_search "fresh honey", ["Fresh Honey"], match: :phrase
239
- end
240
-
241
- def test_phrase_order
242
- store_names ["Wheat Bread", "Whole Wheat Bread"]
243
- assert_order "wheat bread", ["Wheat Bread", "Whole Wheat Bread"], match: :phrase
244
- end
245
-
246
- def test_dynamic_fields
247
- store_names ["Red Bull"], Speaker
248
- assert_search "redbull", ["Red Bull"], {fields: [:name]}, Speaker
249
- end
250
-
251
- def test_unsearchable
252
- store [
253
- {name: "Unsearchable", description: "Almond"}
254
- ]
255
- assert_search "almond", []
256
- end
257
-
258
- def test_unsearchable_where
259
- store [
260
- {name: "Unsearchable", description: "Almond"}
261
- ]
262
- assert_search "*", ["Unsearchable"], where: {description: "Almond"}
263
- end
264
-
265
- def test_emoji
266
- skip unless defined?(EmojiParser)
267
- store_names ["Banana"]
268
- assert_search "🍌", ["Banana"], emoji: true
269
- end
270
-
271
- def test_emoji_multiple
272
- skip unless defined?(EmojiParser)
273
- store_names ["Ice Cream Cake"]
274
- assert_search "🍨🍰", ["Ice Cream Cake"], emoji: true
275
- end
276
- end
@@ -1,56 +0,0 @@
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_unmet_result
43
- store_names ["abc", "abd", "aee"]
44
- assert Product.search("abc", misspellings: {below: 2}).misspellings?
45
- end
46
-
47
- def test_misspellings_below_met
48
- store_names ["abc", "abd", "aee"]
49
- assert_search "abc", ["abc"], misspellings: {below: 1}
50
- end
51
-
52
- def test_misspellings_below_met_result
53
- store_names ["abc", "abd", "aee"]
54
- assert !Product.search("abc", misspellings: {below: 1}).misspellings?
55
- end
56
- end
data/test/model_test.rb DELETED
@@ -1,42 +0,0 @@
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"], Speaker
40
- assert_equal Product.all.to_a + Speaker.all.to_a, Searchkick.search("product", index_name: [Product, Speaker], fields: [:name], order: "name").to_a
41
- end
42
- end
@@ -1,36 +0,0 @@
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
-
23
- def test_misspellings_below_unmet
24
- store_names ["abc", "abd", "aee"]
25
- products = Product.search("abc", misspellings: {below: 2}, execute: false)
26
- Searchkick.multi_search([products])
27
- assert_equal ["abc"], products.map(&:name)
28
- end
29
-
30
- def test_misspellings_below_unmet_retry
31
- store_names ["abc", "abd", "aee"]
32
- products = Product.search("abc", misspellings: {below: 2}, execute: false)
33
- Searchkick.multi_search([products], retry_misspellings: true)
34
- assert_equal ["abc", "abd"], products.map(&:name)
35
- end
36
- end
@@ -1,22 +0,0 @@
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 DELETED
@@ -1,46 +0,0 @@
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
- skip if cequel?
16
-
17
- store_names ["Product A", "Product B"]
18
- product_a = Product.where(name: "Product A").first
19
- product_b = Product.where(name: "Product B").first
20
- assert_order "product", [product_a, product_b].sort_by(&:id).map(&:name), order: {id: :asc}
21
- end
22
-
23
- def test_order_multiple
24
- store [
25
- {name: "Product A", color: "blue", store_id: 1},
26
- {name: "Product B", color: "red", store_id: 3},
27
- {name: "Product C", color: "red", store_id: 2}
28
- ]
29
- assert_order "product", ["Product A", "Product B", "Product C"], order: {color: :asc, store_id: :desc}
30
- end
31
-
32
- def test_order_ignore_unmapped
33
- skip unless elasticsearch_below50?
34
- assert_order "product", [], order: {not_mapped: {ignore_unmapped: true}}, conversions: false
35
- end
36
-
37
- def test_order_unmapped_type
38
- skip if elasticsearch_below50?
39
- assert_order "product", [], order: {not_mapped: {unmapped_type: "long"}}, conversions: false
40
- end
41
-
42
- def test_order_array
43
- store [{name: "San Francisco", latitude: 37.7833, longitude: -122.4167}]
44
- assert_order "francisco", ["San Francisco"], order: [{_geo_distance: {location: "0,0"}}]
45
- end
46
- end
@@ -1,70 +0,0 @@
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
-
54
- def test_kaminari
55
- skip unless defined?(Kaminari)
56
-
57
- require "action_view"
58
-
59
- I18n.load_path = Dir["test/support/kaminari.yml"]
60
- I18n.backend.load_translations
61
-
62
- view = ActionView::Base.new
63
-
64
- store_names ["Product A"]
65
- assert_equal "Displaying <b>1</b> product", view.page_entries_info(Product.search("product"))
66
-
67
- store_names ["Product B"]
68
- assert_equal "Displaying <b>all 2</b> products", view.page_entries_info(Product.search("product"))
69
- end
70
- end