searchkick 0.9.1 → 1.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 +10 -9
- data/CHANGELOG.md +14 -0
- data/README.md +190 -14
- data/lib/searchkick.rb +1 -0
- data/lib/searchkick/index.rb +8 -8
- data/lib/searchkick/logging.rb +4 -2
- data/lib/searchkick/model.rb +13 -10
- data/lib/searchkick/query.rb +107 -39
- data/lib/searchkick/reindex_job.rb +0 -2
- data/lib/searchkick/reindex_v2_job.rb +0 -1
- data/lib/searchkick/results.rb +18 -1
- data/lib/searchkick/tasks.rb +0 -2
- data/lib/searchkick/version.rb +1 -1
- data/test/aggs_test.rb +102 -0
- data/test/autocomplete_test.rb +1 -3
- data/test/boost_test.rb +1 -3
- data/{ci → test/ci}/before_install.sh +4 -3
- data/test/facets_test.rb +4 -6
- data/{gemfiles → test/gemfiles}/activerecord31.gemfile +1 -1
- data/{gemfiles → test/gemfiles}/activerecord32.gemfile +1 -1
- data/{gemfiles → test/gemfiles}/activerecord40.gemfile +1 -1
- data/{gemfiles → test/gemfiles}/activerecord41.gemfile +1 -1
- data/{gemfiles → test/gemfiles}/mongoid2.gemfile +1 -1
- data/{gemfiles → test/gemfiles}/mongoid3.gemfile +1 -1
- data/{gemfiles → test/gemfiles}/mongoid4.gemfile +1 -1
- data/test/gemfiles/mongoid5.gemfile +7 -0
- data/{gemfiles → test/gemfiles}/nobrainer.gemfile +1 -1
- data/test/highlight_test.rb +2 -4
- data/test/index_test.rb +20 -9
- data/test/inheritance_test.rb +1 -3
- data/test/match_test.rb +8 -7
- data/test/model_test.rb +2 -4
- data/test/query_test.rb +1 -3
- data/test/records_test.rb +0 -2
- data/test/reindex_job_test.rb +1 -3
- data/test/reindex_v2_job_test.rb +1 -3
- data/test/routing_test.rb +4 -3
- data/test/should_index_test.rb +1 -3
- data/test/similar_test.rb +1 -3
- data/test/sql_test.rb +7 -9
- data/test/suggest_test.rb +1 -3
- data/test/synonyms_test.rb +1 -3
- data/test/test_helper.rb +23 -10
- metadata +24 -11
data/test/boost_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class BoostTest < Minitest::Test
|
5
4
|
# conversions
|
6
5
|
|
7
6
|
def test_conversions
|
@@ -133,5 +132,4 @@ class TestBoost < Minitest::Test
|
|
133
132
|
]
|
134
133
|
assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {field: :location, origin: [37, -122], scale: "1000mi"}
|
135
134
|
end
|
136
|
-
|
137
135
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
sudo
|
3
|
+
sudo apt-get purge elasticsearch
|
4
|
+
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.7.3.deb
|
5
|
+
sudo dpkg -i elasticsearch-1.7.3.deb
|
6
|
+
sudo service elasticsearch start
|
6
7
|
|
7
8
|
if [ -n "$NOBRAINER" ]; then
|
8
9
|
source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
|
data/test/facets_test.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require_relative "test_helper"
|
2
|
-
require "active_support/core_ext"
|
3
|
-
|
4
|
-
class TestFacets < Minitest::Test
|
5
2
|
|
3
|
+
class FacetsTest < Minitest::Test
|
6
4
|
def setup
|
5
|
+
skip if elasticsearch2?
|
7
6
|
super
|
8
7
|
store [
|
9
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},
|
@@ -79,14 +78,13 @@ class TestFacets < Minitest::Test
|
|
79
78
|
skip if Gem::Version.new(Searchkick.server_version) >= Gem::Version.new("1.4.0")
|
80
79
|
options = {where: {store_id: 2}, facets: {store_id: {stats: true}}}
|
81
80
|
facets = Product.search("Product", options).facets["store_id"]["terms"]
|
82
|
-
expected_facets_keys = %w
|
81
|
+
expected_facets_keys = %w(term count total_count min max total mean)
|
83
82
|
assert_equal expected_facets_keys, facets.first.keys
|
84
83
|
end
|
85
84
|
|
86
85
|
protected
|
87
86
|
|
88
|
-
def store_facet(options, facet_key="store_id")
|
87
|
+
def store_facet(options, facet_key = "store_id")
|
89
88
|
Hash[Product.search("Product", options).facets[facet_key]["terms"].map { |v| [v["term"], v["count"]] }]
|
90
89
|
end
|
91
|
-
|
92
90
|
end
|
data/test/highlight_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class HighlightTest < Minitest::Test
|
5
4
|
def test_basic
|
6
5
|
store_names ["Two Door Cinema Club"]
|
7
6
|
assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", fields: [:name], highlight: true).with_details.first[1][:highlight][:name]
|
@@ -41,7 +40,7 @@ class TestHighlight < Minitest::Test
|
|
41
40
|
json = {
|
42
41
|
query: {
|
43
42
|
match: {
|
44
|
-
|
43
|
+
"name.analyzed" => "cinema"
|
45
44
|
}
|
46
45
|
},
|
47
46
|
highlight: {
|
@@ -54,5 +53,4 @@ class TestHighlight < Minitest::Test
|
|
54
53
|
}
|
55
54
|
assert_equal "Two Door <strong>Cinema</strong> Club", Product.search(json: json).with_details.first[1][:highlight][:"name.analyzed"]
|
56
55
|
end
|
57
|
-
|
58
56
|
end
|
data/test/index_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class IndexTest < Minitest::Test
|
5
4
|
def test_clean_indices
|
6
5
|
old_index = Searchkick::Index.new("products_test_20130801000000000")
|
7
6
|
different_index = Searchkick::Index.new("items_test_20130801000000000")
|
@@ -93,27 +92,39 @@ class TestIndex < Minitest::Test
|
|
93
92
|
end
|
94
93
|
|
95
94
|
def test_unsupported_version
|
96
|
-
raises_exception = ->(
|
95
|
+
raises_exception = ->(_) { raise Elasticsearch::Transport::Transport::Error.new("[500] No query registered for [multi_match]") }
|
97
96
|
Searchkick.client.stub :search, raises_exception do
|
98
97
|
assert_raises(Searchkick::UnsupportedVersionError) { Product.search("test") }
|
99
98
|
end
|
100
99
|
end
|
101
100
|
|
102
101
|
def test_invalid_query
|
103
|
-
assert_raises(Searchkick::InvalidQueryError) { Product.search(query: {}) }
|
102
|
+
assert_raises(Searchkick::InvalidQueryError) { Product.search(query: {boom: true}) }
|
104
103
|
end
|
105
104
|
|
106
|
-
|
105
|
+
unless mongoid2? || nobrainer? || activerecord_below41?
|
106
|
+
def test_dangerous_reindex
|
107
|
+
assert_raises(Searchkick::DangerousOperation) { Product.where(id: [1, 2, 3]).reindex }
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_dangerous_reindex_accepted
|
111
|
+
store_names ["Product A", "Product B"]
|
112
|
+
Product.where(name: "Product A").reindex(accept_danger: true)
|
113
|
+
assert_search "product", ["Product A"]
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_dangerous_reindex_inheritance
|
117
|
+
assert_raises(Searchkick::DangerousOperation) { Dog.where(id: [1, 2, 3]).reindex }
|
118
|
+
end
|
119
|
+
end
|
107
120
|
|
121
|
+
if defined?(ActiveRecord)
|
108
122
|
def test_transaction
|
109
123
|
Product.transaction do
|
110
124
|
store_names ["Product A"]
|
111
125
|
raise ActiveRecord::Rollback
|
112
126
|
end
|
113
|
-
|
114
|
-
assert_search "product", []
|
127
|
+
assert_search "product", [], conversions: false
|
115
128
|
end
|
116
|
-
|
117
129
|
end
|
118
|
-
|
119
130
|
end
|
data/test/inheritance_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class InheritanceTest < Minitest::Test
|
5
4
|
def test_child_reindex
|
6
5
|
store_names ["Max"], Cat
|
7
6
|
assert Dog.reindex
|
@@ -76,5 +75,4 @@ class TestInheritance < Minitest::Test
|
|
76
75
|
store_names ["Product B"], Animal
|
77
76
|
assert_search "product", ["Product A", "Product B"], index_name: [Product.searchkick_index.name, Animal.searchkick_index.name], conversions: false
|
78
77
|
end
|
79
|
-
|
80
78
|
end
|
data/test/match_test.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require_relative "test_helper"
|
4
2
|
|
5
|
-
class
|
6
|
-
|
3
|
+
class MatchTest < Minitest::Test
|
7
4
|
# exact
|
8
5
|
|
9
6
|
def test_match
|
@@ -114,8 +111,8 @@ class TestMatch < Minitest::Test
|
|
114
111
|
|
115
112
|
def test_misspelling_zucchini_transposition
|
116
113
|
store_names ["zucchini"]
|
117
|
-
assert_search "zuccihni", []
|
118
|
-
assert_search "zuccihni", [
|
114
|
+
assert_search "zuccihni", ["zucchini"]
|
115
|
+
assert_search "zuccihni", [], misspellings: {transpositions: false}
|
119
116
|
end
|
120
117
|
|
121
118
|
def test_misspelling_lasagna
|
@@ -133,6 +130,11 @@ class TestMatch < Minitest::Test
|
|
133
130
|
assert_search "lasanga pasat", ["lasagna pasta"], misspellings: {transpositions: true} # both words misspelled with a transposition should still work
|
134
131
|
end
|
135
132
|
|
133
|
+
def test_misspellings_word_start
|
134
|
+
store_names ["Sriracha"]
|
135
|
+
assert_search "siracha", ["Sriracha"], fields: [{name: :word_start}]
|
136
|
+
end
|
137
|
+
|
136
138
|
# spaces
|
137
139
|
|
138
140
|
def test_spaces_in_field
|
@@ -195,5 +197,4 @@ class TestMatch < Minitest::Test
|
|
195
197
|
]
|
196
198
|
assert_search "almond", []
|
197
199
|
end
|
198
|
-
|
199
200
|
end
|
data/test/model_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class ModelTest < Minitest::Test
|
5
4
|
def test_disable_callbacks_model
|
6
5
|
store_names ["product a"]
|
7
6
|
|
@@ -20,7 +19,7 @@ class TestModel < Minitest::Test
|
|
20
19
|
def test_disable_callbacks_global
|
21
20
|
# make sure callbacks default to on
|
22
21
|
assert Searchkick.callbacks?
|
23
|
-
|
22
|
+
|
24
23
|
store_names ["product a"]
|
25
24
|
|
26
25
|
Searchkick.disable_callbacks
|
@@ -34,5 +33,4 @@ class TestModel < Minitest::Test
|
|
34
33
|
|
35
34
|
assert_search "product", ["product a", "product b"]
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
data/test/query_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class QueryTest < Minitest::Test
|
5
4
|
def test_basic
|
6
5
|
store_names ["Milk", "Apple"]
|
7
6
|
query = Product.search("milk", execute: false)
|
@@ -10,5 +9,4 @@ class TestQuery < Minitest::Test
|
|
10
9
|
query.body[:query] = {match_all: {}}
|
11
10
|
assert_equal ["Apple", "Milk"], query.execute.map(&:name).sort
|
12
11
|
end
|
13
|
-
|
14
12
|
end
|
data/test/records_test.rb
CHANGED
data/test/reindex_job_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class ReindexJobTest < Minitest::Test
|
5
4
|
def setup
|
6
5
|
super
|
7
6
|
Searchkick.disable_callbacks
|
@@ -29,5 +28,4 @@ class TestReindexJob < Minitest::Test
|
|
29
28
|
Product.searchkick_index.refresh
|
30
29
|
assert_search "*", []
|
31
30
|
end
|
32
|
-
|
33
31
|
end
|
data/test/reindex_v2_job_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class ReindexV2JobTest < Minitest::Test
|
5
4
|
def setup
|
6
5
|
skip unless defined?(ActiveJob)
|
7
6
|
super
|
@@ -30,5 +29,4 @@ class TestReindexV2Job < Minitest::Test
|
|
30
29
|
Product.searchkick_index.refresh
|
31
30
|
assert_search "*", []
|
32
31
|
end
|
33
|
-
|
34
32
|
end
|
data/test/routing_test.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class RoutingTest < Minitest::Test
|
5
4
|
def test_routing_query
|
5
|
+
skip if elasticsearch2?
|
6
6
|
query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false)
|
7
7
|
assert_equal query.params[:routing], "Dollar Tree"
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_routing_mappings
|
11
|
+
skip if elasticsearch2?
|
11
12
|
index_options = Store.searchkick_index.index_options
|
12
|
-
assert_equal index_options[:mappings][:_default_][:_routing],
|
13
|
+
assert_equal index_options[:mappings][:_default_][:_routing], required: true, path: "name"
|
13
14
|
end
|
14
15
|
end
|
data/test/should_index_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class ShouldIndexTest < Minitest::Test
|
5
4
|
def test_basic
|
6
5
|
store_names ["INDEX", "DO NOT INDEX"]
|
7
6
|
assert_search "index", ["INDEX"]
|
@@ -30,5 +29,4 @@ class TestShouldIndex < Minitest::Test
|
|
30
29
|
Product.searchkick_index.refresh
|
31
30
|
assert_search "index", []
|
32
31
|
end
|
33
|
-
|
34
32
|
end
|
data/test/similar_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class SimilarTest < Minitest::Test
|
5
4
|
def test_similar
|
6
5
|
store_names ["Annie's Naturals Organic Shiitake & Sesame Dressing"]
|
7
6
|
assert_search "Annie's Naturals Shiitake & Sesame Vinaigrette", ["Annie's Naturals Organic Shiitake & Sesame Dressing"], similar: true
|
@@ -16,5 +15,4 @@ class TestSimilar < Minitest::Test
|
|
16
15
|
store_names ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"]
|
17
16
|
assert_order "Lucerne Fat Free Chocolate Milk", ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"], similar: true
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
data/test/sql_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class SqlTest < Minitest::Test
|
5
4
|
def test_limit
|
6
5
|
store_names ["Product A", "Product B", "Product C", "Product D"]
|
7
6
|
assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2
|
@@ -139,11 +138,11 @@ class TestSql < Minitest::Test
|
|
139
138
|
# https://gist.github.com/jprante/7099463
|
140
139
|
def test_where_range_array
|
141
140
|
store [
|
142
|
-
{name: "Product A", user_ids: [11, 23, 13, 16, 17, 23
|
143
|
-
{name: "Product B", user_ids: [1, 2, 3, 4, 5, 6, 7, 8,
|
141
|
+
{name: "Product A", user_ids: [11, 23, 13, 16, 17, 23]},
|
142
|
+
{name: "Product B", user_ids: [1, 2, 3, 4, 5, 6, 7, 8, 9]},
|
144
143
|
{name: "Product C", user_ids: [101, 230, 150, 200]}
|
145
144
|
]
|
146
|
-
assert_search "product", ["Product A"], where: {user_ids: {gt: 10, lt:
|
145
|
+
assert_search "product", ["Product A"], where: {user_ids: {gt: 10, lt: 24}}
|
147
146
|
end
|
148
147
|
|
149
148
|
def test_where_range_array_again
|
@@ -301,9 +300,9 @@ class TestSql < Minitest::Test
|
|
301
300
|
|
302
301
|
def test_big_decimal
|
303
302
|
store [
|
304
|
-
{name: "Product", latitude:
|
303
|
+
{name: "Product", latitude: 80.0}
|
305
304
|
]
|
306
|
-
assert_search "product", ["Product"], where: {latitude: {gt:
|
305
|
+
assert_search "product", ["Product"], where: {latitude: {gt: 79}}
|
307
306
|
end
|
308
307
|
|
309
308
|
# load
|
@@ -333,7 +332,7 @@ class TestSql < Minitest::Test
|
|
333
332
|
def test_select
|
334
333
|
store [{name: "Product A", store_id: 1}]
|
335
334
|
result = Product.search("product", load: false, select: [:name, :store_id]).first
|
336
|
-
assert_equal %w
|
335
|
+
assert_equal %w(id name store_id), result.keys.reject { |k| k.start_with?("_") }.sort
|
337
336
|
assert_equal ["Product A"], result.name # this is not great
|
338
337
|
end
|
339
338
|
|
@@ -363,5 +362,4 @@ class TestSql < Minitest::Test
|
|
363
362
|
assert Product.search("product", include: [:store]).first.association(:store).loaded?
|
364
363
|
end
|
365
364
|
end
|
366
|
-
|
367
365
|
end
|