searchkick 1.5.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -13
- data/CHANGELOG.md +15 -0
- data/README.md +21 -54
- data/lib/searchkick.rb +2 -3
- data/lib/searchkick/index.rb +12 -18
- data/lib/searchkick/index_options.rb +5 -25
- data/lib/searchkick/model.rb +25 -44
- data/lib/searchkick/query.rb +135 -297
- data/lib/searchkick/results.rb +0 -4
- data/lib/searchkick/version.rb +1 -1
- data/searchkick.gemspec +4 -4
- data/test/aggs_test.rb +2 -6
- data/test/autocomplete_test.rb +3 -3
- data/test/boost_test.rb +0 -22
- data/test/index_test.rb +6 -12
- data/test/inheritance_test.rb +2 -2
- data/test/match_test.rb +0 -3
- data/test/query_test.rb +1 -2
- data/test/reindex_test.rb +25 -0
- data/test/sql_test.rb +16 -64
- data/test/test_helper.rb +3 -38
- metadata +9 -14
- data/lib/searchkick/reindex_job.rb +0 -26
- data/test/dangerous_reindex_test.rb +0 -27
- data/test/facets_test.rb +0 -90
- data/test/reindex_job_test.rb +0 -31
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: elasticsearch
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,7 +116,6 @@ files:
|
|
116
116
|
- lib/searchkick/middleware.rb
|
117
117
|
- lib/searchkick/model.rb
|
118
118
|
- lib/searchkick/query.rb
|
119
|
-
- lib/searchkick/reindex_job.rb
|
120
119
|
- lib/searchkick/reindex_v2_job.rb
|
121
120
|
- lib/searchkick/results.rb
|
122
121
|
- lib/searchkick/tasks.rb
|
@@ -127,9 +126,7 @@ files:
|
|
127
126
|
- test/boost_test.rb
|
128
127
|
- test/callbacks_test.rb
|
129
128
|
- test/ci/before_install.sh
|
130
|
-
- test/dangerous_reindex_test.rb
|
131
129
|
- test/errors_test.rb
|
132
|
-
- test/facets_test.rb
|
133
130
|
- test/gemfiles/activerecord31.gemfile
|
134
131
|
- test/gemfiles/activerecord32.gemfile
|
135
132
|
- test/gemfiles/activerecord40.gemfile
|
@@ -156,7 +153,7 @@ files:
|
|
156
153
|
- test/partial_reindex_test.rb
|
157
154
|
- test/query_test.rb
|
158
155
|
- test/records_test.rb
|
159
|
-
- test/
|
156
|
+
- test/reindex_test.rb
|
160
157
|
- test/reindex_v2_job_test.rb
|
161
158
|
- test/routing_test.rb
|
162
159
|
- test/should_index_test.rb
|
@@ -198,9 +195,7 @@ test_files:
|
|
198
195
|
- test/boost_test.rb
|
199
196
|
- test/callbacks_test.rb
|
200
197
|
- test/ci/before_install.sh
|
201
|
-
- test/dangerous_reindex_test.rb
|
202
198
|
- test/errors_test.rb
|
203
|
-
- test/facets_test.rb
|
204
199
|
- test/gemfiles/activerecord31.gemfile
|
205
200
|
- test/gemfiles/activerecord32.gemfile
|
206
201
|
- test/gemfiles/activerecord40.gemfile
|
@@ -227,7 +222,7 @@ test_files:
|
|
227
222
|
- test/partial_reindex_test.rb
|
228
223
|
- test/query_test.rb
|
229
224
|
- test/records_test.rb
|
230
|
-
- test/
|
225
|
+
- test/reindex_test.rb
|
231
226
|
- test/reindex_v2_job_test.rb
|
232
227
|
- test/routing_test.rb
|
233
228
|
- test/should_index_test.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Searchkick
|
2
|
-
class ReindexJob
|
3
|
-
def initialize(klass, id)
|
4
|
-
@klass = klass
|
5
|
-
@id = id
|
6
|
-
end
|
7
|
-
|
8
|
-
def perform
|
9
|
-
model = @klass.constantize
|
10
|
-
record = model.find(@id) rescue nil # TODO fix lazy coding
|
11
|
-
index = model.searchkick_index
|
12
|
-
if !record || !record.should_index?
|
13
|
-
# hacky
|
14
|
-
record ||= model.new
|
15
|
-
record.id = @id
|
16
|
-
begin
|
17
|
-
index.remove record
|
18
|
-
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
19
|
-
# do nothing
|
20
|
-
end
|
21
|
-
else
|
22
|
-
index.store record
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class DangerousReindexTest < Minitest::Test
|
4
|
-
def setup
|
5
|
-
skip if mongoid2? || nobrainer? || activerecord_below41?
|
6
|
-
super
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_dangerous_reindex
|
10
|
-
assert_raises(Searchkick::DangerousOperation) { Product.where(id: [1, 2, 3]).reindex }
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_dangerous_index_associations
|
14
|
-
Store.create!(name: "Test")
|
15
|
-
assert_raises(Searchkick::DangerousOperation) { Store.first.products.reindex }
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_dangerous_reindex_accepted
|
19
|
-
store_names ["Product A", "Product B"]
|
20
|
-
Product.where(name: "Product A").reindex(accept_danger: true)
|
21
|
-
assert_search "product", ["Product A"]
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_dangerous_reindex_inheritance
|
25
|
-
assert_raises(Searchkick::DangerousOperation) { Dog.where(id: [1, 2, 3]).reindex }
|
26
|
-
end
|
27
|
-
end
|
data/test/facets_test.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class FacetsTest < Minitest::Test
|
4
|
-
def setup
|
5
|
-
skip unless elasticsearch_below20?
|
6
|
-
super
|
7
|
-
store [
|
8
|
-
{name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21, created_at: 2.days.ago},
|
9
|
-
{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},
|
10
|
-
{name: "Product B", latitude: 43.9333, longitude: -122.4667, store_id: 2, in_stock: false, color: "red", price: 5},
|
11
|
-
{name: "Foo", latitude: 43.9333, longitude: 12.4667, store_id: 3, in_stock: false, color: "yellow", price: 15}
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_basic
|
16
|
-
assert_equal ({1 => 1, 2 => 2}), store_facet(facets: [:store_id])
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_where
|
20
|
-
assert_equal ({1 => 1}), store_facet(facets: {store_id: {where: {in_stock: true}}})
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_field
|
24
|
-
assert_equal ({1 => 1, 2 => 2}), store_facet(facets: {store_id: {}})
|
25
|
-
assert_equal ({1 => 1, 2 => 2}), store_facet(facets: {store_id: {field: "store_id"}})
|
26
|
-
assert_equal ({1 => 1, 2 => 2}), store_facet({facets: {store_id_new: {field: "store_id"}}}, "store_id_new")
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_limit
|
30
|
-
facet = Product.search("Product", facets: {store_id: {limit: 1}}).facets["store_id"]
|
31
|
-
assert_equal 1, facet["terms"].size
|
32
|
-
assert_equal 3, facet["total"]
|
33
|
-
assert_equal 1, facet["other"]
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_ranges
|
37
|
-
price_ranges = [{to: 10}, {from: 10, to: 20}, {from: 20}]
|
38
|
-
facet = Product.search("Product", facets: {price: {ranges: price_ranges}}).facets["price"]
|
39
|
-
|
40
|
-
assert_equal 3, facet["ranges"].size
|
41
|
-
assert_equal 10.0, facet["ranges"][0]["to"]
|
42
|
-
assert_equal 20.0, facet["ranges"][2]["from"]
|
43
|
-
assert_equal 1, facet["ranges"][0]["count"]
|
44
|
-
assert_equal 0, facet["ranges"][1]["count"]
|
45
|
-
assert_equal 2, facet["ranges"][2]["count"]
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_ranges_dates
|
49
|
-
ranges = [{to: 1.day.ago}, {from: 1.day.ago, to: 1.day.from_now}, {from: 1.day.from_now}]
|
50
|
-
facet = Product.search("Product", facets: {created_at: {ranges: ranges}}).facets["created_at"]
|
51
|
-
|
52
|
-
assert_equal 1, facet["ranges"][0]["count"]
|
53
|
-
assert_equal 1, facet["ranges"][1]["count"]
|
54
|
-
assert_equal 1, facet["ranges"][2]["count"]
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_where_no_smart_facets
|
58
|
-
assert_equal ({2 => 2}), store_facet(where: {color: "red"}, facets: {store_id: {where: {in_stock: false}}})
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_smart_facets
|
62
|
-
assert_equal ({1 => 1}), store_facet(where: {in_stock: true}, facets: [:store_id], smart_facets: true)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_smart_facets_where
|
66
|
-
assert_equal ({2 => 1}), store_facet(where: {color: "red"}, facets: {store_id: {where: {in_stock: false}}}, smart_facets: true)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_smart_facets_skip_facet
|
70
|
-
assert_equal ({1 => 1, 2 => 2}), store_facet(where: {store_id: 2}, facets: [:store_id], smart_facets: true)
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_smart_facets_skip_facet_complex
|
74
|
-
assert_equal ({1 => 1, 2 => 1}), store_facet(where: {store_id: 2, price: {gt: 5}}, facets: [:store_id], smart_facets: true)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_stats_facets
|
78
|
-
skip if Gem::Version.new(Searchkick.server_version) >= Gem::Version.new("1.4.0")
|
79
|
-
options = {where: {store_id: 2}, facets: {store_id: {stats: true}}}
|
80
|
-
facets = Product.search("Product", options).facets["store_id"]["terms"]
|
81
|
-
expected_facets_keys = %w(term count total_count min max total mean)
|
82
|
-
assert_equal expected_facets_keys, facets.first.keys
|
83
|
-
end
|
84
|
-
|
85
|
-
protected
|
86
|
-
|
87
|
-
def store_facet(options, facet_key = "store_id")
|
88
|
-
Hash[Product.search("Product", options).facets[facet_key]["terms"].map { |v| [v["term"], v["count"]] }]
|
89
|
-
end
|
90
|
-
end
|
data/test/reindex_job_test.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|