searchkick-hooopo 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +35 -0
- data/CHANGELOG.md +491 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +1908 -0
- data/Rakefile +20 -0
- data/benchmark/Gemfile +23 -0
- data/benchmark/benchmark.rb +97 -0
- data/lib/searchkick/bulk_reindex_job.rb +17 -0
- data/lib/searchkick/index.rb +500 -0
- data/lib/searchkick/index_options.rb +333 -0
- data/lib/searchkick/indexer.rb +28 -0
- data/lib/searchkick/logging.rb +242 -0
- data/lib/searchkick/middleware.rb +12 -0
- data/lib/searchkick/model.rb +156 -0
- data/lib/searchkick/process_batch_job.rb +23 -0
- data/lib/searchkick/process_queue_job.rb +23 -0
- data/lib/searchkick/query.rb +901 -0
- data/lib/searchkick/reindex_queue.rb +38 -0
- data/lib/searchkick/reindex_v2_job.rb +39 -0
- data/lib/searchkick/results.rb +216 -0
- data/lib/searchkick/tasks.rb +33 -0
- data/lib/searchkick/version.rb +3 -0
- data/lib/searchkick.rb +215 -0
- data/searchkick.gemspec +28 -0
- data/test/aggs_test.rb +197 -0
- data/test/autocomplete_test.rb +75 -0
- data/test/boost_test.rb +175 -0
- data/test/callbacks_test.rb +59 -0
- data/test/ci/before_install.sh +17 -0
- data/test/errors_test.rb +19 -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/activerecord42.gemfile +7 -0
- data/test/gemfiles/activerecord50.gemfile +7 -0
- data/test/gemfiles/apartment.gemfile +8 -0
- data/test/gemfiles/cequel.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/mongoid6.gemfile +8 -0
- data/test/gemfiles/nobrainer.gemfile +8 -0
- data/test/gemfiles/parallel_tests.gemfile +8 -0
- data/test/geo_shape_test.rb +172 -0
- data/test/highlight_test.rb +78 -0
- data/test/index_test.rb +153 -0
- data/test/inheritance_test.rb +83 -0
- data/test/marshal_test.rb +8 -0
- data/test/match_test.rb +276 -0
- data/test/misspellings_test.rb +56 -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 +46 -0
- data/test/pagination_test.rb +53 -0
- data/test/partial_reindex_test.rb +58 -0
- data/test/query_test.rb +35 -0
- data/test/records_test.rb +10 -0
- data/test/reindex_test.rb +52 -0
- data/test/reindex_v2_job_test.rb +32 -0
- data/test/routing_test.rb +23 -0
- data/test/should_index_test.rb +32 -0
- data/test/similar_test.rb +28 -0
- data/test/sql_test.rb +198 -0
- data/test/suggest_test.rb +85 -0
- data/test/synonyms_test.rb +67 -0
- data/test/test_helper.rb +527 -0
- data/test/where_test.rb +223 -0
- metadata +250 -0
data/test/aggs_test.rb
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class AggsTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
store [
|
7
|
+
{name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21, created_at: 2.days.ago},
|
8
|
+
{name: "Product Hide", latitude: 29.4167, longitude: -98.5000, store_id: 2, in_stock: false, color: "green", price: 25, created_at: 2.days.from_now},
|
9
|
+
{name: "Product B", latitude: 43.9333, longitude: -122.4667, store_id: 2, in_stock: false, color: "red", price: 5, created_at: Time.now},
|
10
|
+
{name: "Foo", latitude: 43.9333, longitude: 12.4667, store_id: 3, in_stock: false, color: "yellow", price: 15, created_at: Time.now}
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_basic
|
15
|
+
assert_equal ({1 => 1, 2 => 2}), store_agg(aggs: [:store_id])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_where
|
19
|
+
assert_equal ({1 => 1}), store_agg(aggs: {store_id: {where: {in_stock: true}}})
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_order
|
23
|
+
agg = Product.search("Product", aggs: {color: {order: {"_term" => "desc"}}}).aggs["color"]
|
24
|
+
assert_equal %w(red green blue), agg["buckets"].map { |b| b["key"] }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_field
|
28
|
+
assert_equal ({1 => 1, 2 => 2}), store_agg(aggs: {store_id: {}})
|
29
|
+
assert_equal ({1 => 1, 2 => 2}), store_agg(aggs: {store_id: {field: "store_id"}})
|
30
|
+
assert_equal ({1 => 1, 2 => 2}), store_agg({aggs: {store_id_new: {field: "store_id"}}}, "store_id_new")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_min_doc_count
|
34
|
+
assert_equal ({2 => 2}), store_agg(aggs: {store_id: {min_doc_count: 2}})
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_no_aggs
|
38
|
+
assert_nil Product.search("*").aggs
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_limit
|
42
|
+
agg = Product.search("Product", aggs: {store_id: {limit: 1}}).aggs["store_id"]
|
43
|
+
assert_equal 1, agg["buckets"].size
|
44
|
+
# assert_equal 3, agg["doc_count"]
|
45
|
+
assert_equal(1, agg["sum_other_doc_count"])
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_ranges
|
49
|
+
price_ranges = [{to: 10}, {from: 10, to: 20}, {from: 20}]
|
50
|
+
agg = Product.search("Product", aggs: {price: {ranges: price_ranges}}).aggs["price"]
|
51
|
+
|
52
|
+
assert_equal 3, agg["buckets"].size
|
53
|
+
assert_equal 10.0, agg["buckets"][0]["to"]
|
54
|
+
assert_equal 20.0, agg["buckets"][2]["from"]
|
55
|
+
assert_equal 1, agg["buckets"][0]["doc_count"]
|
56
|
+
assert_equal 0, agg["buckets"][1]["doc_count"]
|
57
|
+
assert_equal 2, agg["buckets"][2]["doc_count"]
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_date_ranges
|
61
|
+
ranges = [{to: 1.day.ago}, {from: 1.day.ago, to: 1.day.from_now}, {from: 1.day.from_now}]
|
62
|
+
agg = Product.search("Product", aggs: {created_at: {date_ranges: ranges}}).aggs["created_at"]
|
63
|
+
|
64
|
+
assert_equal 1, agg["buckets"][0]["doc_count"]
|
65
|
+
assert_equal 1, agg["buckets"][1]["doc_count"]
|
66
|
+
assert_equal 1, agg["buckets"][2]["doc_count"]
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_query_where
|
70
|
+
assert_equal ({1 => 1}), store_agg(where: {in_stock: true}, aggs: [:store_id])
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_two_wheres
|
74
|
+
assert_equal ({2 => 1}), store_agg(where: {color: "red"}, aggs: {store_id: {where: {in_stock: false}}})
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_where_override
|
78
|
+
assert_equal ({}), store_agg(where: {color: "red"}, aggs: {store_id: {where: {in_stock: false, color: "blue"}}})
|
79
|
+
assert_equal ({2 => 1}), store_agg(where: {color: "blue"}, aggs: {store_id: {where: {in_stock: false, color: "red"}}})
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_skip
|
83
|
+
assert_equal ({1 => 1, 2 => 2}), store_agg(where: {store_id: 2}, aggs: [:store_id])
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_skip_complex
|
87
|
+
assert_equal ({1 => 1, 2 => 1}), store_agg(where: {store_id: 2, price: {gt: 5}}, aggs: [:store_id])
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_multiple
|
91
|
+
assert_equal ({"store_id" => {1 => 1, 2 => 2}, "color" => {"blue" => 1, "green" => 1, "red" => 1}}), store_multiple_aggs(aggs: [:store_id, :color])
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_smart_aggs_false
|
95
|
+
assert_equal ({2 => 2}), store_agg(where: {color: "red"}, aggs: {store_id: {where: {in_stock: false}}}, smart_aggs: false)
|
96
|
+
assert_equal ({2 => 2}), store_agg(where: {color: "blue"}, aggs: {store_id: {where: {in_stock: false}}}, smart_aggs: false)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_aggs_group_by_date
|
100
|
+
store [{name: "Old Product", created_at: 3.years.ago}]
|
101
|
+
products =
|
102
|
+
Product.search("Product", {
|
103
|
+
where: {
|
104
|
+
created_at: {lt: Time.now}
|
105
|
+
},
|
106
|
+
aggs: {
|
107
|
+
products_per_year: {
|
108
|
+
date_histogram: {
|
109
|
+
field: :created_at,
|
110
|
+
interval: :year
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
})
|
115
|
+
|
116
|
+
assert_equal 4, products.aggs["products_per_year"]["buckets"].size
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_aggs_avg
|
120
|
+
products =
|
121
|
+
Product.search("*", {
|
122
|
+
aggs: {
|
123
|
+
avg_price: {
|
124
|
+
avg: {
|
125
|
+
field: :price
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
})
|
130
|
+
assert_equal 16.5, products.aggs["avg_price"]["value"]
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_aggs_cardinality
|
134
|
+
products =
|
135
|
+
Product.search("*", {
|
136
|
+
aggs: {
|
137
|
+
total_stores: {
|
138
|
+
cardinality: {
|
139
|
+
field: :store_id
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
})
|
144
|
+
assert_equal 3, products.aggs["total_stores"]["value"]
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_aggs_min_max
|
148
|
+
products =
|
149
|
+
Product.search("*", {
|
150
|
+
aggs: {
|
151
|
+
min_price: {
|
152
|
+
min: {
|
153
|
+
field: :price
|
154
|
+
}
|
155
|
+
},
|
156
|
+
max_price: {
|
157
|
+
max: {
|
158
|
+
field: :price
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
})
|
163
|
+
assert_equal 5, products.aggs["min_price"]["value"]
|
164
|
+
assert_equal 25, products.aggs["max_price"]["value"]
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_aggs_sum
|
168
|
+
products =
|
169
|
+
Product.search("*", {
|
170
|
+
aggs: {
|
171
|
+
sum_price: {
|
172
|
+
sum: {
|
173
|
+
field: :price
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
})
|
178
|
+
assert_equal 66, products.aggs["sum_price"]["value"]
|
179
|
+
end
|
180
|
+
|
181
|
+
protected
|
182
|
+
|
183
|
+
def buckets_as_hash(agg)
|
184
|
+
Hash[agg["buckets"].map { |v| [v["key"], v["doc_count"]] }]
|
185
|
+
end
|
186
|
+
|
187
|
+
def store_agg(options, agg_key = "store_id")
|
188
|
+
buckets = Product.search("Product", options).aggs[agg_key]
|
189
|
+
buckets_as_hash(buckets)
|
190
|
+
end
|
191
|
+
|
192
|
+
def store_multiple_aggs(options)
|
193
|
+
Hash[Product.search("Product", options).aggs.map do |field, filtered_agg|
|
194
|
+
[field, buckets_as_hash(filtered_agg)]
|
195
|
+
end]
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class AutocompleteTest < Minitest::Test
|
4
|
+
def test_autocomplete
|
5
|
+
store_names ["Hummus"]
|
6
|
+
assert_search "hum", ["Hummus"], match: :text_start
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_autocomplete_two_words
|
10
|
+
store_names ["Organic Hummus"]
|
11
|
+
assert_search "hum", [], match: :text_start
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_autocomplete_fields
|
15
|
+
store_names ["Hummus"]
|
16
|
+
assert_search "hum", ["Hummus"], match: :text_start, fields: [:name]
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_text_start
|
20
|
+
store_names ["Where in the World is Carmen San Diego"]
|
21
|
+
assert_search "where in the world is", ["Where in the World is Carmen San Diego"], fields: [{name: :text_start}]
|
22
|
+
assert_search "in the world", [], fields: [{name: :text_start}]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_text_middle
|
26
|
+
store_names ["Where in the World is Carmen San Diego"]
|
27
|
+
assert_search "where in the world is", ["Where in the World is Carmen San Diego"], fields: [{name: :text_middle}]
|
28
|
+
assert_search "n the wor", ["Where in the World is Carmen San Diego"], fields: [{name: :text_middle}]
|
29
|
+
assert_search "men san diego", ["Where in the World is Carmen San Diego"], fields: [{name: :text_middle}]
|
30
|
+
assert_search "world carmen", [], fields: [{name: :text_middle}]
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_text_end
|
34
|
+
store_names ["Where in the World is Carmen San Diego"]
|
35
|
+
assert_search "men san diego", ["Where in the World is Carmen San Diego"], fields: [{name: :text_end}]
|
36
|
+
assert_search "carmen san", [], fields: [{name: :text_end}]
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_word_start
|
40
|
+
store_names ["Where in the World is Carmen San Diego"]
|
41
|
+
assert_search "car san wor", ["Where in the World is Carmen San Diego"], fields: [{name: :word_start}]
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_word_middle
|
45
|
+
store_names ["Where in the World is Carmen San Diego"]
|
46
|
+
assert_search "orl", ["Where in the World is Carmen San Diego"], fields: [{name: :word_middle}]
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_word_end
|
50
|
+
store_names ["Where in the World is Carmen San Diego"]
|
51
|
+
assert_search "rld men ego", ["Where in the World is Carmen San Diego"], fields: [{name: :word_end}]
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_word_start_multiple_words
|
55
|
+
store_names ["Dark Grey", "Dark Blue"]
|
56
|
+
assert_search "dark grey", ["Dark Grey"], fields: [{name: :word_start}]
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_word_start_exact
|
60
|
+
store_names ["Back Scratcher", "Backpack"]
|
61
|
+
assert_order "back", ["Back Scratcher", "Backpack"], fields: [{name: :word_start}]
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_word_start_exact_martin
|
65
|
+
store_names ["Martina", "Martin"]
|
66
|
+
assert_order "martin", ["Martin", "Martina"], fields: [{name: :word_start}]
|
67
|
+
end
|
68
|
+
|
69
|
+
# TODO find a better place
|
70
|
+
|
71
|
+
def test_exact
|
72
|
+
store_names ["hi@example.org"]
|
73
|
+
assert_search "hi@example.org", ["hi@example.org"], fields: [{name: :exact}]
|
74
|
+
end
|
75
|
+
end
|
data/test/boost_test.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class BoostTest < Minitest::Test
|
4
|
+
# conversions
|
5
|
+
|
6
|
+
def test_conversions
|
7
|
+
store [
|
8
|
+
{name: "Tomato A", conversions: {"tomato" => 1}},
|
9
|
+
{name: "Tomato B", conversions: {"tomato" => 2}},
|
10
|
+
{name: "Tomato C", conversions: {"tomato" => 3}}
|
11
|
+
]
|
12
|
+
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"]
|
13
|
+
assert_equal_scores "tomato", conversions: false
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_multiple_conversions
|
17
|
+
store [
|
18
|
+
{name: "Speaker A", conversions_a: {"speaker" => 1}, conversions_b: {"speaker" => 6}},
|
19
|
+
{name: "Speaker B", conversions_a: {"speaker" => 2}, conversions_b: {"speaker" => 5}},
|
20
|
+
{name: "Speaker C", conversions_a: {"speaker" => 3}, conversions_b: {"speaker" => 4}}
|
21
|
+
], Speaker
|
22
|
+
|
23
|
+
assert_equal_scores "speaker", {conversions: false}, Speaker
|
24
|
+
assert_equal_scores "speaker", {}, Speaker
|
25
|
+
assert_equal_scores "speaker", {conversions: ["conversions_a", "conversions_b"]}, Speaker
|
26
|
+
assert_equal_scores "speaker", {conversions: ["conversions_b", "conversions_a"]}, Speaker
|
27
|
+
assert_order "speaker", ["Speaker C", "Speaker B", "Speaker A"], {conversions: "conversions_a"}, Speaker
|
28
|
+
assert_order "speaker", ["Speaker A", "Speaker B", "Speaker C"], {conversions: "conversions_b"}, Speaker
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_conversions_stemmed
|
32
|
+
store [
|
33
|
+
{name: "Tomato A", conversions: {"tomato" => 1, "tomatos" => 1, "Tomatoes" => 1}},
|
34
|
+
{name: "Tomato B", conversions: {"tomato" => 2}}
|
35
|
+
]
|
36
|
+
assert_order "tomato", ["Tomato A", "Tomato B"]
|
37
|
+
end
|
38
|
+
|
39
|
+
# global boost
|
40
|
+
|
41
|
+
def test_boost
|
42
|
+
store [
|
43
|
+
{name: "Tomato A"},
|
44
|
+
{name: "Tomato B", orders_count: 10},
|
45
|
+
{name: "Tomato C", orders_count: 100}
|
46
|
+
]
|
47
|
+
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost: "orders_count"
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_boost_zero
|
51
|
+
store [
|
52
|
+
{name: "Zero Boost", orders_count: 0}
|
53
|
+
]
|
54
|
+
assert_order "zero", ["Zero Boost"], boost: "orders_count"
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_conversions_weight
|
58
|
+
store [
|
59
|
+
{name: "Product Boost", orders_count: 20},
|
60
|
+
{name: "Product Conversions", conversions: {"product" => 10}}
|
61
|
+
]
|
62
|
+
assert_order "product", ["Product Conversions", "Product Boost"], boost: "orders_count"
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_boost_fields
|
66
|
+
store [
|
67
|
+
{name: "Red", color: "White"},
|
68
|
+
{name: "White", color: "Red Red Red"}
|
69
|
+
]
|
70
|
+
assert_order "red", ["Red", "White"], fields: ["name^10", "color"]
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_boost_fields_decimal
|
74
|
+
store [
|
75
|
+
{name: "Red", color: "White"},
|
76
|
+
{name: "White", color: "Red Red Red"}
|
77
|
+
]
|
78
|
+
assert_order "red", ["Red", "White"], fields: ["name^10.5", "color"]
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_boost_fields_word_start
|
82
|
+
store [
|
83
|
+
{name: "Red", color: "White"},
|
84
|
+
{name: "White", color: "Red Red Red"}
|
85
|
+
]
|
86
|
+
assert_order "red", ["Red", "White"], fields: [{"name^10" => :word_start}, "color"]
|
87
|
+
end
|
88
|
+
|
89
|
+
# for issue #855
|
90
|
+
def test_apostrophes
|
91
|
+
store_names ["Valentine's Day Special"]
|
92
|
+
assert_search "Valentines", ["Valentine's Day Special"], fields: ["name^5"]
|
93
|
+
assert_search "Valentine's", ["Valentine's Day Special"], fields: ["name^5"]
|
94
|
+
assert_search "Valentine", ["Valentine's Day Special"], fields: ["name^5"]
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_boost_by
|
98
|
+
store [
|
99
|
+
{name: "Tomato A"},
|
100
|
+
{name: "Tomato B", orders_count: 10},
|
101
|
+
{name: "Tomato C", orders_count: 100}
|
102
|
+
]
|
103
|
+
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: [:orders_count]
|
104
|
+
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 10}}
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_boost_by_boost_mode_multiply
|
108
|
+
store [
|
109
|
+
{name: "Tomato A", found_rate: 0.9},
|
110
|
+
{name: "Tomato B"},
|
111
|
+
{name: "Tomato C", found_rate: 0.5}
|
112
|
+
]
|
113
|
+
|
114
|
+
assert_order "tomato", ["Tomato B", "Tomato A", "Tomato C"], boost_by: {found_rate: {boost_mode: "multiply"}}
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_boost_where
|
118
|
+
store [
|
119
|
+
{name: "Tomato A"},
|
120
|
+
{name: "Tomato B", user_ids: [1, 2]},
|
121
|
+
{name: "Tomato C", user_ids: [3]}
|
122
|
+
]
|
123
|
+
assert_first "tomato", "Tomato B", boost_where: {user_ids: 2}
|
124
|
+
assert_first "tomato", "Tomato B", boost_where: {user_ids: 1..2}
|
125
|
+
assert_first "tomato", "Tomato B", boost_where: {user_ids: [1, 4]}
|
126
|
+
assert_first "tomato", "Tomato B", boost_where: {user_ids: {value: 2, factor: 10}}
|
127
|
+
assert_first "tomato", "Tomato B", boost_where: {user_ids: {value: [1, 4], factor: 10}}
|
128
|
+
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_where: {user_ids: [{value: 1, factor: 10}, {value: 3, factor: 20}]}
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_boost_by_distance
|
132
|
+
store [
|
133
|
+
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
134
|
+
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
|
135
|
+
{name: "San Marino", latitude: 43.9333, longitude: 12.4667}
|
136
|
+
]
|
137
|
+
assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {field: :location, origin: [37, -122], scale: "1000mi"}
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_boost_by_distance_hash
|
141
|
+
store [
|
142
|
+
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
143
|
+
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
|
144
|
+
{name: "San Marino", latitude: 43.9333, longitude: 12.4667}
|
145
|
+
]
|
146
|
+
assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {field: :location, origin: {lat: 37, lon: -122}, scale: "1000mi"}
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_boost_by_distance_v2
|
150
|
+
store [
|
151
|
+
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
152
|
+
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
|
153
|
+
{name: "San Marino", latitude: 43.9333, longitude: 12.4667}
|
154
|
+
]
|
155
|
+
assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {location: {origin: [37, -122], scale: "1000mi"}}
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_boost_by_distance_v2_hash
|
159
|
+
store [
|
160
|
+
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
161
|
+
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
|
162
|
+
{name: "San Marino", latitude: 43.9333, longitude: 12.4667}
|
163
|
+
]
|
164
|
+
assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {location: {origin: {lat: 37, lon: -122}, scale: "1000mi"}}
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_boost_by_indices
|
168
|
+
skip if cequel?
|
169
|
+
|
170
|
+
store_names ["Rex"], Animal
|
171
|
+
store_names ["Rexx"], Product
|
172
|
+
|
173
|
+
assert_order "Rex", ["Rexx", "Rex"], {index_name: [Animal, Product], indices_boost: {Animal => 1, Product => 200}, fields: [:name]}, Store
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class CallbacksTest < Minitest::Test
|
4
|
+
def test_true_create
|
5
|
+
Searchkick.callbacks(true) do
|
6
|
+
store_names ["Product A", "Product B"]
|
7
|
+
end
|
8
|
+
Product.searchkick_index.refresh
|
9
|
+
assert_search "product", ["Product A", "Product B"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_false_create
|
13
|
+
Searchkick.callbacks(false) do
|
14
|
+
store_names ["Product A", "Product B"]
|
15
|
+
end
|
16
|
+
Product.searchkick_index.refresh
|
17
|
+
assert_search "product", []
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_bulk_create
|
21
|
+
Searchkick.callbacks(:bulk) do
|
22
|
+
store_names ["Product A", "Product B"]
|
23
|
+
end
|
24
|
+
Product.searchkick_index.refresh
|
25
|
+
assert_search "product", ["Product A", "Product B"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_queue
|
29
|
+
skip unless defined?(ActiveJob) && defined?(Redis)
|
30
|
+
|
31
|
+
reindex_queue = Product.searchkick_index.reindex_queue
|
32
|
+
reindex_queue.clear
|
33
|
+
|
34
|
+
Searchkick.callbacks(:queue) do
|
35
|
+
store_names ["Product A", "Product B"]
|
36
|
+
end
|
37
|
+
Product.searchkick_index.refresh
|
38
|
+
assert_search "product", [], load: false, conversions: false
|
39
|
+
assert_equal 2, reindex_queue.length
|
40
|
+
|
41
|
+
Searchkick::ProcessQueueJob.perform_later(class_name: "Product")
|
42
|
+
Product.searchkick_index.refresh
|
43
|
+
assert_search "product", ["Product A", "Product B"], load: false
|
44
|
+
assert_equal 0, reindex_queue.length
|
45
|
+
|
46
|
+
Searchkick.callbacks(:queue) do
|
47
|
+
Product.where(name: "Product B").destroy_all
|
48
|
+
Product.create!(name: "Product C")
|
49
|
+
end
|
50
|
+
Product.searchkick_index.refresh
|
51
|
+
assert_search "product", ["Product A", "Product B"], load: false
|
52
|
+
assert_equal 2, reindex_queue.length
|
53
|
+
|
54
|
+
Searchkick::ProcessQueueJob.perform_later(class_name: "Product")
|
55
|
+
Product.searchkick_index.refresh
|
56
|
+
assert_search "product", ["Product A", "Product C"], load: false
|
57
|
+
assert_equal 0, reindex_queue.length
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
gem install bundler
|
6
|
+
|
7
|
+
if [[ $ELASTICSEARCH_VERSION == 1* ]]; then
|
8
|
+
curl -L -O https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
9
|
+
elif [[ $ELASTICSEARCH_VERSION == 2* ]]; then
|
10
|
+
curl -L -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/$ELASTICSEARCH_VERSION/elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
11
|
+
else
|
12
|
+
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
13
|
+
fi
|
14
|
+
tar -xvf elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
15
|
+
cd elasticsearch-$ELASTICSEARCH_VERSION/bin
|
16
|
+
./elasticsearch -d
|
17
|
+
wget -O- --waitretry=1 --tries=30 --retry-connrefused -v http://127.0.0.1:9200/
|
data/test/errors_test.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class ErrorsTest < Minitest::Test
|
4
|
+
def test_bulk_import_raises_error
|
5
|
+
valid_dog = Product.create(name: "2016-01-02")
|
6
|
+
invalid_dog = Product.create(name: "Ol' One-Leg")
|
7
|
+
index = Searchkick::Index.new "dogs", mappings: {
|
8
|
+
dog: {
|
9
|
+
properties: {
|
10
|
+
name: {type: "date"}
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
index.store valid_dog
|
15
|
+
assert_raises(Searchkick::ImportError) do
|
16
|
+
index.bulk_index [valid_dog, invalid_dog]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|