searchkick 2.3.2 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +377 -84
- data/LICENSE.txt +1 -1
- data/README.md +859 -602
- data/lib/searchkick/bulk_reindex_job.rb +13 -9
- data/lib/searchkick/controller_runtime.rb +40 -0
- data/lib/searchkick/hash_wrapper.rb +12 -0
- data/lib/searchkick/index.rb +281 -356
- data/lib/searchkick/index_cache.rb +30 -0
- data/lib/searchkick/index_options.rb +487 -281
- data/lib/searchkick/indexer.rb +15 -8
- data/lib/searchkick/log_subscriber.rb +57 -0
- data/lib/searchkick/middleware.rb +9 -2
- data/lib/searchkick/model.rb +72 -118
- data/lib/searchkick/multi_search.rb +9 -10
- data/lib/searchkick/process_batch_job.rb +12 -15
- data/lib/searchkick/process_queue_job.rb +22 -13
- data/lib/searchkick/query.rb +458 -217
- data/lib/searchkick/railtie.rb +7 -0
- data/lib/searchkick/record_data.rb +128 -0
- data/lib/searchkick/record_indexer.rb +164 -0
- data/lib/searchkick/reindex_queue.rb +51 -9
- data/lib/searchkick/reindex_v2_job.rb +10 -32
- data/lib/searchkick/relation.rb +247 -0
- data/lib/searchkick/relation_indexer.rb +155 -0
- data/lib/searchkick/results.rb +201 -82
- data/lib/searchkick/version.rb +1 -1
- data/lib/searchkick/where.rb +11 -0
- data/lib/searchkick.rb +269 -97
- data/lib/tasks/searchkick.rake +37 -0
- metadata +24 -178
- 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/logging.rb +0 -242
- 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/boost_test.rb
DELETED
@@ -1,202 +0,0 @@
|
|
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_multiple_conversions_with_boost_term
|
32
|
-
store [
|
33
|
-
{name: "Speaker A", conversions_a: {"speaker" => 4, "speaker_1" => 1}},
|
34
|
-
{name: "Speaker B", conversions_a: {"speaker" => 3, "speaker_1" => 2}},
|
35
|
-
{name: "Speaker C", conversions_a: {"speaker" => 2, "speaker_1" => 3}},
|
36
|
-
{name: "Speaker D", conversions_a: {"speaker" => 1, "speaker_1" => 4}}
|
37
|
-
], Speaker
|
38
|
-
|
39
|
-
assert_order "speaker", ["Speaker A", "Speaker B", "Speaker C", "Speaker D"], {conversions: "conversions_a"}, Speaker
|
40
|
-
assert_order "speaker", ["Speaker D", "Speaker C", "Speaker B", "Speaker A"], {conversions: "conversions_a", conversions_term: "speaker_1"}, Speaker
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_conversions_stemmed
|
44
|
-
store [
|
45
|
-
{name: "Tomato A", conversions: {"tomato" => 1, "tomatos" => 1, "Tomatoes" => 1}},
|
46
|
-
{name: "Tomato B", conversions: {"tomato" => 2}}
|
47
|
-
]
|
48
|
-
assert_order "tomato", ["Tomato A", "Tomato B"]
|
49
|
-
end
|
50
|
-
|
51
|
-
# global boost
|
52
|
-
|
53
|
-
def test_boost
|
54
|
-
store [
|
55
|
-
{name: "Tomato A"},
|
56
|
-
{name: "Tomato B", orders_count: 10},
|
57
|
-
{name: "Tomato C", orders_count: 100}
|
58
|
-
]
|
59
|
-
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost: "orders_count"
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_boost_zero
|
63
|
-
store [
|
64
|
-
{name: "Zero Boost", orders_count: 0}
|
65
|
-
]
|
66
|
-
assert_order "zero", ["Zero Boost"], boost: "orders_count"
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_conversions_weight
|
70
|
-
store [
|
71
|
-
{name: "Product Boost", orders_count: 20},
|
72
|
-
{name: "Product Conversions", conversions: {"product" => 10}}
|
73
|
-
]
|
74
|
-
assert_order "product", ["Product Conversions", "Product Boost"], boost: "orders_count"
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_boost_fields
|
78
|
-
store [
|
79
|
-
{name: "Red", color: "White"},
|
80
|
-
{name: "White", color: "Red Red Red"}
|
81
|
-
]
|
82
|
-
assert_order "red", ["Red", "White"], fields: ["name^10", "color"]
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_boost_fields_decimal
|
86
|
-
store [
|
87
|
-
{name: "Red", color: "White"},
|
88
|
-
{name: "White", color: "Red Red Red"}
|
89
|
-
]
|
90
|
-
assert_order "red", ["Red", "White"], fields: ["name^10.5", "color"]
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_boost_fields_word_start
|
94
|
-
store [
|
95
|
-
{name: "Red", color: "White"},
|
96
|
-
{name: "White", color: "Red Red Red"}
|
97
|
-
]
|
98
|
-
assert_order "red", ["Red", "White"], fields: [{"name^10" => :word_start}, "color"]
|
99
|
-
end
|
100
|
-
|
101
|
-
# for issue #855
|
102
|
-
def test_apostrophes
|
103
|
-
store_names ["Valentine's Day Special"]
|
104
|
-
assert_search "Valentines", ["Valentine's Day Special"], fields: ["name^5"]
|
105
|
-
assert_search "Valentine's", ["Valentine's Day Special"], fields: ["name^5"]
|
106
|
-
assert_search "Valentine", ["Valentine's Day Special"], fields: ["name^5"]
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_boost_by
|
110
|
-
store [
|
111
|
-
{name: "Tomato A"},
|
112
|
-
{name: "Tomato B", orders_count: 10},
|
113
|
-
{name: "Tomato C", orders_count: 100}
|
114
|
-
]
|
115
|
-
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: [:orders_count]
|
116
|
-
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_by: {orders_count: {factor: 10}}
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_boost_by_missing
|
120
|
-
store [
|
121
|
-
{name: "Tomato A"},
|
122
|
-
{name: "Tomato B", orders_count: 10},
|
123
|
-
]
|
124
|
-
|
125
|
-
if elasticsearch_below50?
|
126
|
-
assert_raises(ArgumentError) do
|
127
|
-
assert_order "tomato", ["Tomato A", "Tomato B"], boost_by: {orders_count: {missing: 100}}
|
128
|
-
end
|
129
|
-
else
|
130
|
-
assert_order "tomato", ["Tomato A", "Tomato B"], boost_by: {orders_count: {missing: 100}}
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_boost_by_boost_mode_multiply
|
135
|
-
store [
|
136
|
-
{name: "Tomato A", found_rate: 0.9},
|
137
|
-
{name: "Tomato B"},
|
138
|
-
{name: "Tomato C", found_rate: 0.5}
|
139
|
-
]
|
140
|
-
|
141
|
-
assert_order "tomato", ["Tomato B", "Tomato A", "Tomato C"], boost_by: {found_rate: {boost_mode: "multiply"}}
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_boost_where
|
145
|
-
store [
|
146
|
-
{name: "Tomato A"},
|
147
|
-
{name: "Tomato B", user_ids: [1, 2]},
|
148
|
-
{name: "Tomato C", user_ids: [3]}
|
149
|
-
]
|
150
|
-
assert_first "tomato", "Tomato B", boost_where: {user_ids: 2}
|
151
|
-
assert_first "tomato", "Tomato B", boost_where: {user_ids: 1..2}
|
152
|
-
assert_first "tomato", "Tomato B", boost_where: {user_ids: [1, 4]}
|
153
|
-
assert_first "tomato", "Tomato B", boost_where: {user_ids: {value: 2, factor: 10}}
|
154
|
-
assert_first "tomato", "Tomato B", boost_where: {user_ids: {value: [1, 4], factor: 10}}
|
155
|
-
assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"], boost_where: {user_ids: [{value: 1, factor: 10}, {value: 3, factor: 20}]}
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_boost_by_distance
|
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: {field: :location, origin: [37, -122], scale: "1000mi"}
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_boost_by_distance_hash
|
168
|
-
store [
|
169
|
-
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
170
|
-
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
|
171
|
-
{name: "San Marino", latitude: 43.9333, longitude: 12.4667}
|
172
|
-
]
|
173
|
-
assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {field: :location, origin: {lat: 37, lon: -122}, scale: "1000mi"}
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_boost_by_distance_v2
|
177
|
-
store [
|
178
|
-
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
179
|
-
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
|
180
|
-
{name: "San Marino", latitude: 43.9333, longitude: 12.4667}
|
181
|
-
]
|
182
|
-
assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {location: {origin: [37, -122], scale: "1000mi"}}
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_boost_by_distance_v2_hash
|
186
|
-
store [
|
187
|
-
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
188
|
-
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
|
189
|
-
{name: "San Marino", latitude: 43.9333, longitude: 12.4667}
|
190
|
-
]
|
191
|
-
assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {location: {origin: {lat: 37, lon: -122}, scale: "1000mi"}}
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_boost_by_indices
|
195
|
-
skip if cequel?
|
196
|
-
|
197
|
-
store_names ["Rex"], Animal
|
198
|
-
store_names ["Rexx"], Product
|
199
|
-
|
200
|
-
assert_order "Rex", ["Rexx", "Rex"], {index_name: [Animal, Product], indices_boost: {Animal => 1, Product => 200}, fields: [:name]}, Store
|
201
|
-
end
|
202
|
-
end
|
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
|