searchkick 2.3.2 → 4.4.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 +5 -5
- data/CHANGELOG.md +251 -84
- data/LICENSE.txt +1 -1
- data/README.md +552 -432
- data/lib/searchkick/bulk_indexer.rb +173 -0
- data/lib/searchkick/bulk_reindex_job.rb +2 -2
- data/lib/searchkick/hash_wrapper.rb +12 -0
- data/lib/searchkick/index.rb +187 -348
- data/lib/searchkick/index_options.rb +494 -282
- data/lib/searchkick/logging.rb +17 -13
- data/lib/searchkick/model.rb +52 -97
- data/lib/searchkick/multi_search.rb +9 -10
- data/lib/searchkick/process_batch_job.rb +17 -4
- data/lib/searchkick/process_queue_job.rb +20 -12
- data/lib/searchkick/query.rb +415 -199
- data/lib/searchkick/railtie.rb +7 -0
- data/lib/searchkick/record_data.rb +128 -0
- data/lib/searchkick/record_indexer.rb +79 -0
- data/lib/searchkick/reindex_queue.rb +1 -1
- data/lib/searchkick/reindex_v2_job.rb +14 -12
- data/lib/searchkick/results.rb +135 -41
- data/lib/searchkick/version.rb +1 -1
- data/lib/searchkick.rb +130 -61
- data/lib/tasks/searchkick.rake +34 -0
- metadata +18 -162
- data/.gitignore +0 -22
- data/.travis.yml +0 -39
- data/Gemfile +0 -16
- data/Rakefile +0 -20
- data/benchmark/Gemfile +0 -23
- data/benchmark/benchmark.rb +0 -97
- data/lib/searchkick/tasks.rb +0 -33
- data/searchkick.gemspec +0 -28
- data/test/aggs_test.rb +0 -197
- data/test/autocomplete_test.rb +0 -75
- data/test/boost_test.rb +0 -202
- data/test/callbacks_test.rb +0 -59
- data/test/ci/before_install.sh +0 -17
- data/test/errors_test.rb +0 -19
- data/test/gemfiles/activerecord31.gemfile +0 -7
- data/test/gemfiles/activerecord32.gemfile +0 -7
- data/test/gemfiles/activerecord40.gemfile +0 -8
- data/test/gemfiles/activerecord41.gemfile +0 -8
- data/test/gemfiles/activerecord42.gemfile +0 -7
- data/test/gemfiles/activerecord50.gemfile +0 -7
- data/test/gemfiles/apartment.gemfile +0 -8
- data/test/gemfiles/cequel.gemfile +0 -8
- data/test/gemfiles/mongoid2.gemfile +0 -7
- data/test/gemfiles/mongoid3.gemfile +0 -6
- data/test/gemfiles/mongoid4.gemfile +0 -7
- data/test/gemfiles/mongoid5.gemfile +0 -7
- data/test/gemfiles/mongoid6.gemfile +0 -12
- data/test/gemfiles/nobrainer.gemfile +0 -8
- data/test/gemfiles/parallel_tests.gemfile +0 -8
- data/test/geo_shape_test.rb +0 -175
- data/test/highlight_test.rb +0 -78
- data/test/index_test.rb +0 -166
- data/test/inheritance_test.rb +0 -83
- data/test/marshal_test.rb +0 -8
- data/test/match_test.rb +0 -276
- data/test/misspellings_test.rb +0 -56
- data/test/model_test.rb +0 -42
- data/test/multi_search_test.rb +0 -36
- data/test/multi_tenancy_test.rb +0 -22
- data/test/order_test.rb +0 -46
- data/test/pagination_test.rb +0 -70
- data/test/partial_reindex_test.rb +0 -58
- data/test/query_test.rb +0 -35
- data/test/records_test.rb +0 -10
- data/test/reindex_test.rb +0 -64
- data/test/reindex_v2_job_test.rb +0 -32
- data/test/routing_test.rb +0 -23
- data/test/should_index_test.rb +0 -32
- data/test/similar_test.rb +0 -28
- data/test/sql_test.rb +0 -214
- data/test/suggest_test.rb +0 -95
- data/test/support/kaminari.yml +0 -21
- data/test/synonyms_test.rb +0 -67
- data/test/test_helper.rb +0 -567
- data/test/where_test.rb +0 -223
data/test/callbacks_test.rb
DELETED
@@ -1,59 +0,0 @@
|
|
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
|
data/test/ci/before_install.sh
DELETED
@@ -1,17 +0,0 @@
|
|
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
DELETED
@@ -1,19 +0,0 @@
|
|
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
|
data/test/geo_shape_test.rb
DELETED
@@ -1,175 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class GeoShapeTest < Minitest::Test
|
4
|
-
def setup
|
5
|
-
Region.destroy_all
|
6
|
-
store [
|
7
|
-
{
|
8
|
-
name: "Region A",
|
9
|
-
text: "The witch had a cat",
|
10
|
-
territory: {
|
11
|
-
type: "polygon",
|
12
|
-
coordinates: [[[30, 40], [35, 45], [40, 40], [40, 30], [30, 30], [30, 40]]]
|
13
|
-
}
|
14
|
-
},
|
15
|
-
{
|
16
|
-
name: "Region B",
|
17
|
-
text: "and a very tall hat",
|
18
|
-
territory: {
|
19
|
-
type: "polygon",
|
20
|
-
coordinates: [[[50, 60], [55, 65], [60, 60], [60, 50], [50, 50], [50, 60]]]
|
21
|
-
}
|
22
|
-
},
|
23
|
-
{
|
24
|
-
name: "Region C",
|
25
|
-
text: "and long ginger hair which she wore in a plait",
|
26
|
-
territory: {
|
27
|
-
type: "polygon",
|
28
|
-
coordinates: [[[10, 20], [15, 25], [20, 20], [20, 10], [10, 10], [10, 20]]]
|
29
|
-
}
|
30
|
-
}
|
31
|
-
], Region
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_circle
|
35
|
-
assert_search "*", ["Region A"], {
|
36
|
-
where: {
|
37
|
-
territory: {
|
38
|
-
geo_shape: {
|
39
|
-
type: "circle",
|
40
|
-
coordinates: {lat: 28.0, lon: 38.0},
|
41
|
-
radius: "444000m"
|
42
|
-
}
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}, Region
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_envelope
|
49
|
-
assert_search "*", ["Region A"], {
|
50
|
-
where: {
|
51
|
-
territory: {
|
52
|
-
geo_shape: {
|
53
|
-
type: "envelope",
|
54
|
-
coordinates: [[28, 42], [32, 38]]
|
55
|
-
}
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}, Region
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_polygon
|
62
|
-
assert_search "*", ["Region A"], {
|
63
|
-
where: {
|
64
|
-
territory: {
|
65
|
-
geo_shape: {
|
66
|
-
type: "polygon",
|
67
|
-
coordinates: [[[38, 42], [42, 42], [42, 38], [38, 38], [38, 42]]]
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}, Region
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_multipolygon
|
75
|
-
assert_search "*", ["Region A", "Region B"], {
|
76
|
-
where: {
|
77
|
-
territory: {
|
78
|
-
geo_shape: {
|
79
|
-
type: "multipolygon",
|
80
|
-
coordinates: [
|
81
|
-
[[[38, 42], [42, 42], [42, 38], [38, 38], [38, 42]]],
|
82
|
-
[[[58, 62], [62, 62], [62, 58], [58, 58], [58, 62]]]
|
83
|
-
]
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
}, Region
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_disjoint
|
91
|
-
assert_search "*", ["Region B", "Region C"], {
|
92
|
-
where: {
|
93
|
-
territory: {
|
94
|
-
geo_shape: {
|
95
|
-
type: "envelope",
|
96
|
-
relation: "disjoint",
|
97
|
-
coordinates: [[28, 42], [32, 38]]
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}, Region
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_within
|
105
|
-
assert_search "*", ["Region A"], {
|
106
|
-
where: {
|
107
|
-
territory: {
|
108
|
-
geo_shape: {
|
109
|
-
type: "envelope",
|
110
|
-
relation: "within",
|
111
|
-
coordinates: [[20, 50], [50, 20]]
|
112
|
-
}
|
113
|
-
}
|
114
|
-
}
|
115
|
-
}, Region
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_search_math
|
119
|
-
# TODO find out why this is failing
|
120
|
-
skip unless elasticsearch_below60?
|
121
|
-
|
122
|
-
assert_search "witch", ["Region A"], {
|
123
|
-
where: {
|
124
|
-
territory: {
|
125
|
-
geo_shape: {
|
126
|
-
type: "envelope",
|
127
|
-
coordinates: [[28, 42], [32, 38]]
|
128
|
-
}
|
129
|
-
}
|
130
|
-
}
|
131
|
-
}, Region
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_search_no_match
|
135
|
-
assert_search "ginger hair", [], {
|
136
|
-
where: {
|
137
|
-
territory: {
|
138
|
-
geo_shape: {
|
139
|
-
type: "envelope",
|
140
|
-
coordinates: [[28, 42], [32, 38]]
|
141
|
-
}
|
142
|
-
}
|
143
|
-
}
|
144
|
-
}, Region
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_contains
|
148
|
-
skip if elasticsearch_below22?
|
149
|
-
assert_search "*", ["Region C"], {
|
150
|
-
where: {
|
151
|
-
territory: {
|
152
|
-
geo_shape: {
|
153
|
-
type: "envelope",
|
154
|
-
relation: "contains",
|
155
|
-
coordinates: [[12, 13], [13, 12]]
|
156
|
-
}
|
157
|
-
}
|
158
|
-
}
|
159
|
-
}, Region
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_latlon
|
163
|
-
assert_search "*", ["Region A"], {
|
164
|
-
where: {
|
165
|
-
territory: {
|
166
|
-
geo_shape: {
|
167
|
-
type: "envelope",
|
168
|
-
coordinates: [{lat: 42, lon: 28}, {lat: 38, lon: 32}]
|
169
|
-
}
|
170
|
-
}
|
171
|
-
}
|
172
|
-
}, Region
|
173
|
-
end
|
174
|
-
|
175
|
-
end
|
data/test/highlight_test.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class HighlightTest < Minitest::Test
|
4
|
-
def test_basic
|
5
|
-
store_names ["Two Door Cinema Club"]
|
6
|
-
assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", fields: [:name], highlight: true).first.search_highlights[:name]
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_tag
|
10
|
-
store_names ["Two Door Cinema Club"]
|
11
|
-
assert_equal "Two Door <strong>Cinema</strong> Club", Product.search("cinema", fields: [:name], highlight: {tag: "<strong>"}).first.search_highlights[:name]
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_tag_class
|
15
|
-
store_names ["Two Door Cinema Club"]
|
16
|
-
assert_equal "Two Door <strong class='classy'>Cinema</strong> Club", Product.search("cinema", fields: [:name], highlight: {tag: "<strong class='classy'>"}).first.search_highlights[:name]
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_multiple_fields
|
20
|
-
store [{name: "Two Door Cinema Club", color: "Cinema Orange"}]
|
21
|
-
highlights = Product.search("cinema", fields: [:name, :color], highlight: true).first.search_highlights
|
22
|
-
assert_equal "Two Door <em>Cinema</em> Club", highlights[:name]
|
23
|
-
assert_equal "<em>Cinema</em> Orange", highlights[:color]
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_fields
|
27
|
-
store [{name: "Two Door Cinema Club", color: "Cinema Orange"}]
|
28
|
-
highlights = Product.search("cinema", fields: [:name, :color], highlight: {fields: [:name]}).first.search_highlights
|
29
|
-
assert_equal "Two Door <em>Cinema</em> Club", highlights[:name]
|
30
|
-
assert_nil highlights[:color]
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_field_options
|
34
|
-
store_names ["Two Door Cinema Club are a Northern Irish indie rock band"]
|
35
|
-
fragment_size = ENV["MATCH"] == "word_start" ? 26 : 21
|
36
|
-
assert_equal "Two Door <em>Cinema</em> Club are", Product.search("cinema", fields: [:name], highlight: {fields: {name: {fragment_size: fragment_size}}}).first.search_highlights[:name]
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_multiple_words
|
40
|
-
store_names ["Hello World Hello"]
|
41
|
-
assert_equal "<em>Hello</em> World <em>Hello</em>", Product.search("hello", fields: [:name], highlight: true).first.search_highlights[:name]
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_encoder
|
45
|
-
store_names ["<b>Hello</b>"]
|
46
|
-
assert_equal "<b><em>Hello</em></b>", Product.search("hello", fields: [:name], highlight: {encoder: "html"}, misspellings: false).first.search_highlights[:name]
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_word_middle
|
50
|
-
store_names ["Two Door Cinema Club"]
|
51
|
-
assert_equal "Two Door <em>Cinema</em> Club", Product.search("ine", fields: [:name], match: :word_middle, highlight: true).first.search_highlights[:name]
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_body
|
55
|
-
skip if ENV["MATCH"] == "word_start"
|
56
|
-
store_names ["Two Door Cinema Club"]
|
57
|
-
body = {
|
58
|
-
query: {
|
59
|
-
match: {
|
60
|
-
"name.analyzed" => "cinema"
|
61
|
-
}
|
62
|
-
},
|
63
|
-
highlight: {
|
64
|
-
pre_tags: ["<strong>"],
|
65
|
-
post_tags: ["</strong>"],
|
66
|
-
fields: {
|
67
|
-
"name.analyzed" => {}
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
assert_equal "Two Door <strong>Cinema</strong> Club", Product.search(body: body).first.search_highlights[:"name.analyzed"]
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_legacy
|
75
|
-
store_names ["Two Door Cinema Club"]
|
76
|
-
assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", fields: [:name], highlight: true).with_details.first[1][:highlight][:name]
|
77
|
-
end
|
78
|
-
end
|
data/test/index_test.rb
DELETED
@@ -1,166 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class IndexTest < Minitest::Test
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
Region.destroy_all
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_clean_indices
|
10
|
-
suffix = Searchkick.index_suffix ? "_#{Searchkick.index_suffix}" : ""
|
11
|
-
old_index = Searchkick::Index.new("products_test#{suffix}_20130801000000000")
|
12
|
-
different_index = Searchkick::Index.new("items_test#{suffix}_20130801000000000")
|
13
|
-
|
14
|
-
old_index.delete if old_index.exists?
|
15
|
-
different_index.delete if different_index.exists?
|
16
|
-
|
17
|
-
# create indexes
|
18
|
-
old_index.create
|
19
|
-
different_index.create
|
20
|
-
|
21
|
-
Product.searchkick_index.clean_indices
|
22
|
-
|
23
|
-
assert Product.searchkick_index.exists?
|
24
|
-
assert different_index.exists?
|
25
|
-
assert !old_index.exists?
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_clean_indices_old_format
|
29
|
-
suffix = Searchkick.index_suffix ? "_#{Searchkick.index_suffix}" : ""
|
30
|
-
old_index = Searchkick::Index.new("products_test#{suffix}_20130801000000")
|
31
|
-
old_index.create
|
32
|
-
|
33
|
-
Product.searchkick_index.clean_indices
|
34
|
-
|
35
|
-
assert !old_index.exists?
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_retain
|
39
|
-
Product.reindex
|
40
|
-
assert_equal 1, Product.searchkick_index.all_indices.size
|
41
|
-
Product.reindex(retain: true)
|
42
|
-
assert_equal 2, Product.searchkick_index.all_indices.size
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_total_docs
|
46
|
-
store_names ["Product A"]
|
47
|
-
assert_equal 1, Product.searchkick_index.total_docs
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_mapping
|
51
|
-
store_names ["Dollar Tree"], Store
|
52
|
-
assert_equal [], Store.search(body: {query: {match: {name: "dollar"}}}).map(&:name)
|
53
|
-
assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}).map(&:name)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_body
|
57
|
-
store_names ["Dollar Tree"], Store
|
58
|
-
assert_equal [], Store.search(body: {query: {match: {name: "dollar"}}}).map(&:name)
|
59
|
-
assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}, load: false).map(&:name)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_body_warning
|
63
|
-
assert_output(nil, "The body option replaces the entire body, so the following options are ignored: where\n") { Store.search(body: {query: {match: {name: "dollar"}}}, where: {id: 1}) }
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_block
|
67
|
-
store_names ["Dollar Tree"]
|
68
|
-
products =
|
69
|
-
Product.search "boom" do |body|
|
70
|
-
body[:query] = {match_all: {}}
|
71
|
-
end
|
72
|
-
assert_equal ["Dollar Tree"], products.map(&:name)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_tokens
|
76
|
-
assert_equal ["dollar", "dollartre", "tree"], Product.searchkick_index.tokens("Dollar Tree", analyzer: "searchkick_index")
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_tokens_analyzer
|
80
|
-
assert_equal ["dollar", "tree"], Product.searchkick_index.tokens("Dollar Tree", analyzer: "searchkick_search2")
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_record_not_found
|
84
|
-
store_names ["Product A", "Product B"]
|
85
|
-
Product.where(name: "Product A").delete_all
|
86
|
-
assert_search "product", ["Product B"]
|
87
|
-
ensure
|
88
|
-
Product.reindex
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_bad_mapping
|
92
|
-
Product.searchkick_index.delete
|
93
|
-
store_names ["Product A"]
|
94
|
-
assert_raises(Searchkick::InvalidQueryError) { Product.search "test" }
|
95
|
-
ensure
|
96
|
-
Product.reindex
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_remove_blank_id
|
100
|
-
store_names ["Product A"]
|
101
|
-
Product.searchkick_index.remove(Product.new)
|
102
|
-
assert_search "product", ["Product A"]
|
103
|
-
ensure
|
104
|
-
Product.reindex
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_missing_index
|
108
|
-
assert_raises(Searchkick::MissingIndexError) { Product.search("test", index_name: "not_found") }
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_unsupported_version
|
112
|
-
raises_exception = ->(_) { raise Elasticsearch::Transport::Transport::Error, "[500] No query registered for [multi_match]" }
|
113
|
-
Searchkick.client.stub :search, raises_exception do
|
114
|
-
assert_raises(Searchkick::UnsupportedVersionError) { Product.search("test") }
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_invalid_body
|
119
|
-
assert_raises(Searchkick::InvalidQueryError) { Product.search(body: {boom: true}) }
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_transaction
|
123
|
-
skip unless defined?(ActiveRecord)
|
124
|
-
Product.transaction do
|
125
|
-
store_names ["Product A"]
|
126
|
-
raise ActiveRecord::Rollback
|
127
|
-
end
|
128
|
-
assert_search "*", []
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_filterable
|
132
|
-
# skip for 5.0 since it throws
|
133
|
-
# Cannot search on field [alt_description] since it is not indexed.
|
134
|
-
skip unless elasticsearch_below50?
|
135
|
-
store [{name: "Product A", alt_description: "Hello"}]
|
136
|
-
assert_search "*", [], where: {alt_description: "Hello"}
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_filterable_non_string
|
140
|
-
store [{name: "Product A", store_id: 1}]
|
141
|
-
assert_search "*", ["Product A"], where: {store_id: 1}
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_large_value
|
145
|
-
skip if nobrainer?
|
146
|
-
large_value = 1000.times.map { "hello" }.join(" ")
|
147
|
-
store [{name: "Product A", text: large_value}], Region
|
148
|
-
assert_search "product", ["Product A"], {}, Region
|
149
|
-
assert_search "hello", ["Product A"], {fields: [:name, :text]}, Region
|
150
|
-
|
151
|
-
# needs fields for ES 6
|
152
|
-
if elasticsearch_below60?
|
153
|
-
assert_search "hello", ["Product A"], {}, Region
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_very_large_value
|
158
|
-
skip if nobrainer? || elasticsearch_below22?
|
159
|
-
large_value = 10000.times.map { "hello" }.join(" ")
|
160
|
-
store [{name: "Product A", text: large_value}], Region
|
161
|
-
assert_search "product", ["Product A"], {}, Region
|
162
|
-
assert_search "hello", ["Product A"], {fields: [:name, :text]}, Region
|
163
|
-
# values that exceed ignore_above are not included in _all field :(
|
164
|
-
# assert_search "hello", ["Product A"], {}, Region
|
165
|
-
end
|
166
|
-
end
|