search_flip 1.1.0 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +110 -0
- data/.travis.yml +11 -30
- data/CHANGELOG.md +17 -5
- data/README.md +32 -0
- data/docker-compose.yml +6 -0
- data/lib/search_flip.rb +2 -42
- data/lib/search_flip/aggregatable.rb +1 -1
- data/lib/search_flip/aggregation.rb +15 -9
- data/lib/search_flip/bulk.rb +8 -5
- data/lib/search_flip/config.rb +0 -11
- data/lib/search_flip/connection.rb +131 -0
- data/lib/search_flip/criteria.rb +89 -73
- data/lib/search_flip/exceptions.rb +5 -0
- data/lib/search_flip/filterable.rb +3 -1
- data/lib/search_flip/index.rb +32 -26
- data/lib/search_flip/model.rb +1 -1
- data/lib/search_flip/post_filterable.rb +5 -3
- data/lib/search_flip/response.rb +1 -1
- data/lib/search_flip/version.rb +1 -1
- data/search_flip.gemspec +10 -9
- data/test/search_flip/aggregation_test.rb +39 -21
- data/test/search_flip/bulk_test.rb +1 -1
- data/test/search_flip/connection_test.rb +70 -0
- data/test/search_flip/criteria_test.rb +87 -44
- data/test/search_flip/http_client_test.rb +1 -1
- data/test/search_flip/index_test.rb +49 -17
- data/test/search_flip/model_test.rb +1 -1
- data/test/search_flip/response_test.rb +4 -3
- data/test/search_flip/to_json_test.rb +1 -1
- data/test/test_helper.rb +5 -5
- metadata +28 -26
- data/test/database.yml +0 -4
- data/test/search_flip_test.rb +0 -26
@@ -1,12 +1,34 @@
|
|
1
1
|
|
2
|
-
require File.expand_path("
|
2
|
+
require File.expand_path("../test_helper", __dir__)
|
3
3
|
|
4
4
|
class SearchFlip::IndexTest < SearchFlip::TestCase
|
5
|
-
should_delegate_methods :profile, :where, :where_not, :filter, :range, :match_all, :exists,
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
5
|
+
should_delegate_methods :profile, :where, :where_not, :filter, :range, :match_all, :exists,
|
6
|
+
:exists_not, :post_where, :post_where_not, :post_filter, :post_must, :post_must_not,
|
7
|
+
:post_should, :post_range, :post_exists, :post_exists_not, :aggregate, :scroll, :source,
|
8
|
+
:includes, :eager_load, :preload, :sort, :resort, :order, :reorder, :offset, :limit,
|
9
|
+
:paginate, :page, :per, :search, :find_in_batches, :highlight, :suggest, :custom, :find_each,
|
10
|
+
:failsafe, :total_entries, :total_count, :terminate_after, :timeout, :should, :should_not,
|
11
|
+
:must, :must_not, to: :criteria, subject: ProductIndex
|
12
|
+
|
13
|
+
def test_serialize_exception
|
14
|
+
klass = Class.new do
|
15
|
+
include SearchFlip::Index
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_raises SearchFlip::MethodNotImplemented do
|
19
|
+
klass.serialize(Hashie::Mash)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_type_name_exception
|
24
|
+
klass = Class.new do
|
25
|
+
include SearchFlip::Index
|
26
|
+
end
|
27
|
+
|
28
|
+
assert_raises SearchFlip::MethodNotImplemented do
|
29
|
+
klass.serialize(Hashie::Mash)
|
30
|
+
end
|
31
|
+
end
|
10
32
|
|
11
33
|
def test_create_index
|
12
34
|
assert TestIndex.create_index
|
@@ -75,10 +97,6 @@ class SearchFlip::IndexTest < SearchFlip::TestCase
|
|
75
97
|
end
|
76
98
|
end
|
77
99
|
|
78
|
-
def test_base_url
|
79
|
-
assert_equal "http://127.0.0.1:9200", ProductIndex.base_url
|
80
|
-
end
|
81
|
-
|
82
100
|
def test_index_url
|
83
101
|
assert_equal "http://127.0.0.1:9200/products", ProductIndex.index_url
|
84
102
|
|
@@ -151,7 +169,9 @@ class SearchFlip::IndexTest < SearchFlip::TestCase
|
|
151
169
|
ProductIndex.import products
|
152
170
|
end
|
153
171
|
|
154
|
-
|
172
|
+
actual = products.map { |product| ProductIndex.get(product.id)["_version"] }
|
173
|
+
|
174
|
+
assert_equal [3, 3], actual
|
155
175
|
end
|
156
176
|
|
157
177
|
def test_index_array
|
@@ -267,32 +287,38 @@ class SearchFlip::IndexTest < SearchFlip::TestCase
|
|
267
287
|
|
268
288
|
products = create_list(:product, 2)
|
269
289
|
|
270
|
-
if
|
290
|
+
if ProductIndex.connection.version.to_i >= 5
|
271
291
|
assert_difference "ProductIndex.total_entries", 2 do
|
272
292
|
ProductIndex.create products, {}, routing: "r1"
|
273
293
|
end
|
274
294
|
|
275
|
-
|
295
|
+
actual = ProductIndex.get(products.first.id, routing: "r1")["_routing"]
|
296
|
+
|
297
|
+
assert_equal "r1", actual
|
276
298
|
else
|
277
299
|
assert_difference "ProductIndex.total_entries", 2 do
|
278
300
|
ProductIndex.create products, {}, version: 2, version_type: "external"
|
279
301
|
end
|
280
302
|
|
281
|
-
|
303
|
+
actual = products.map { |product| ProductIndex.get(product.id)["_version"] }
|
304
|
+
|
305
|
+
assert_equal [2, 2], actual
|
282
306
|
end
|
283
307
|
end
|
284
308
|
|
285
309
|
def test_create_with_class_options
|
286
310
|
products = create_list(:product, 2)
|
287
311
|
|
288
|
-
if
|
312
|
+
if ProductIndex.connection.version.to_i >= 5
|
289
313
|
ProductIndex.stubs(:index_options).returns(routing: "r1")
|
290
314
|
|
291
315
|
assert_difference "ProductIndex.total_entries", 2 do
|
292
316
|
ProductIndex.create products
|
293
317
|
end
|
294
318
|
|
295
|
-
|
319
|
+
actual = products.map { |product| ProductIndex.get(product.id, routing: "r1")["_routing"] }
|
320
|
+
|
321
|
+
assert_equal ["r1", "r1"], actual
|
296
322
|
else
|
297
323
|
ProductIndex.stubs(:index_options).returns(version: 2, version_type: "external")
|
298
324
|
|
@@ -300,7 +326,9 @@ class SearchFlip::IndexTest < SearchFlip::TestCase
|
|
300
326
|
ProductIndex.create products
|
301
327
|
end
|
302
328
|
|
303
|
-
|
329
|
+
actual = products.map { |product| ProductIndex.get(product.id)["_version"] }
|
330
|
+
|
331
|
+
assert_equal [2, 2], actual
|
304
332
|
end
|
305
333
|
end
|
306
334
|
|
@@ -346,5 +374,9 @@ class SearchFlip::IndexTest < SearchFlip::TestCase
|
|
346
374
|
end
|
347
375
|
end
|
348
376
|
end
|
377
|
+
|
378
|
+
def test_connection
|
379
|
+
assert_equal ProductIndex.connection.base_url, "http://127.0.0.1:9200"
|
380
|
+
end
|
349
381
|
end
|
350
382
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.expand_path("
|
2
|
+
require File.expand_path("../test_helper", __dir__)
|
3
3
|
|
4
4
|
class SearchFlip::ResponseTest < SearchFlip::TestCase
|
5
5
|
def test_total_entries
|
@@ -124,10 +124,11 @@ class SearchFlip::ResponseTest < SearchFlip::TestCase
|
|
124
124
|
ProductIndex.import [product1, product2, product3]
|
125
125
|
|
126
126
|
query = ProductIndex.aggregate(:category) do |aggregation|
|
127
|
-
aggregation.aggregate(price_sum: { sum: { field: "price" }})
|
127
|
+
aggregation.aggregate(price_sum: { sum: { field: "price" } })
|
128
128
|
end
|
129
129
|
|
130
|
-
assert_equal Hash["category1" => 2, "category2" => 1],
|
130
|
+
assert_equal Hash["category1" => 2, "category2" => 1],
|
131
|
+
query.aggregations(:category).each_with_object({}) { |(key, agg), hash| hash[key] = agg.doc_count }
|
131
132
|
|
132
133
|
assert_equal 40, query.aggregations(:category)["category1"].price_sum.value
|
133
134
|
assert_equal 20, query.aggregations(:category)["category2"].price_sum.value
|
data/test/test_helper.rb
CHANGED
@@ -11,7 +11,7 @@ require "yaml"
|
|
11
11
|
|
12
12
|
WebMock.allow_net_connect!
|
13
13
|
|
14
|
-
ActiveRecord::Base.establish_connection
|
14
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
15
15
|
|
16
16
|
SearchFlip::Config[:auto_refresh] = true
|
17
17
|
|
@@ -23,7 +23,7 @@ ActiveRecord::Base.connection.create_table :products do |t|
|
|
23
23
|
t.float :price
|
24
24
|
t.string :category
|
25
25
|
t.integer :version, default: 1
|
26
|
-
t.integer :rank, :
|
26
|
+
t.integer :rank, default: 0
|
27
27
|
t.integer :user_id
|
28
28
|
t.timestamps null: false
|
29
29
|
end
|
@@ -99,7 +99,7 @@ class ProductIndex
|
|
99
99
|
include SearchFlip::Index
|
100
100
|
|
101
101
|
def self.mapping
|
102
|
-
if
|
102
|
+
if ProductIndex.connection.version.to_i >= 5
|
103
103
|
{
|
104
104
|
products: {
|
105
105
|
properties: {
|
@@ -180,7 +180,7 @@ class SearchFlip::TestCase < MiniTest::Test
|
|
180
180
|
|
181
181
|
assert target.respond_to?(as), "#{to} doesn't respond to #{as}"
|
182
182
|
|
183
|
-
params = subject.method(method).arity.abs
|
183
|
+
params = Array.new(subject.method(method).arity.abs) { |i| "param-#{i}" }
|
184
184
|
|
185
185
|
mock_target = mock
|
186
186
|
mock_target.expects(as).with(*params)
|
@@ -198,7 +198,7 @@ class SearchFlip::TestCase < MiniTest::Test
|
|
198
198
|
end
|
199
199
|
|
200
200
|
def assert_difference(expressions, difference = 1, &block)
|
201
|
-
callables = Array(expressions).map { |e|
|
201
|
+
callables = Array(expressions).map { |e| -> { eval(e, block.binding) } }
|
202
202
|
|
203
203
|
before = callables.map(&:call)
|
204
204
|
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: search_flip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '3.0'
|
20
20
|
type: :development
|
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: '0'
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: factory_bot
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: mocha
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,21 +95,21 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: sqlite3
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 1.3.6
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 1.3.6
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: timecop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: webmock
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: hashie
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -151,7 +151,7 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: http
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
@@ -186,18 +186,22 @@ extensions: []
|
|
186
186
|
extra_rdoc_files: []
|
187
187
|
files:
|
188
188
|
- ".gitignore"
|
189
|
+
- ".rubocop.yml"
|
189
190
|
- ".travis.yml"
|
190
191
|
- CHANGELOG.md
|
191
192
|
- Gemfile
|
192
193
|
- LICENSE.txt
|
193
194
|
- README.md
|
194
195
|
- Rakefile
|
196
|
+
- docker-compose.yml
|
195
197
|
- lib/search_flip.rb
|
196
198
|
- lib/search_flip/aggregatable.rb
|
197
199
|
- lib/search_flip/aggregation.rb
|
198
200
|
- lib/search_flip/bulk.rb
|
199
201
|
- lib/search_flip/config.rb
|
202
|
+
- lib/search_flip/connection.rb
|
200
203
|
- lib/search_flip/criteria.rb
|
204
|
+
- lib/search_flip/exceptions.rb
|
201
205
|
- lib/search_flip/filterable.rb
|
202
206
|
- lib/search_flip/http_client.rb
|
203
207
|
- lib/search_flip/index.rb
|
@@ -209,16 +213,15 @@ files:
|
|
209
213
|
- lib/search_flip/to_json.rb
|
210
214
|
- lib/search_flip/version.rb
|
211
215
|
- search_flip.gemspec
|
212
|
-
- test/database.yml
|
213
216
|
- test/search_flip/aggregation_test.rb
|
214
217
|
- test/search_flip/bulk_test.rb
|
218
|
+
- test/search_flip/connection_test.rb
|
215
219
|
- test/search_flip/criteria_test.rb
|
216
220
|
- test/search_flip/http_client_test.rb
|
217
221
|
- test/search_flip/index_test.rb
|
218
222
|
- test/search_flip/model_test.rb
|
219
223
|
- test/search_flip/response_test.rb
|
220
224
|
- test/search_flip/to_json_test.rb
|
221
|
-
- test/search_flip_test.rb
|
222
225
|
- test/test_helper.rb
|
223
226
|
homepage: https://github.com/mrkamel/search_flip
|
224
227
|
licenses:
|
@@ -235,24 +238,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
235
238
|
version: '0'
|
236
239
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
240
|
requirements:
|
238
|
-
- - "
|
241
|
+
- - ">"
|
239
242
|
- !ruby/object:Gem::Version
|
240
|
-
version:
|
243
|
+
version: 1.3.1
|
241
244
|
requirements: []
|
242
245
|
rubyforge_project:
|
243
|
-
rubygems_version: 2.
|
246
|
+
rubygems_version: 2.7.3
|
244
247
|
signing_key:
|
245
248
|
specification_version: 4
|
246
249
|
summary: Powerful ElasticSearch client library to easily build complex queries
|
247
250
|
test_files:
|
248
|
-
- test/database.yml
|
249
251
|
- test/search_flip/aggregation_test.rb
|
250
252
|
- test/search_flip/bulk_test.rb
|
253
|
+
- test/search_flip/connection_test.rb
|
251
254
|
- test/search_flip/criteria_test.rb
|
252
255
|
- test/search_flip/http_client_test.rb
|
253
256
|
- test/search_flip/index_test.rb
|
254
257
|
- test/search_flip/model_test.rb
|
255
258
|
- test/search_flip/response_test.rb
|
256
259
|
- test/search_flip/to_json_test.rb
|
257
|
-
- test/search_flip_test.rb
|
258
260
|
- test/test_helper.rb
|
data/test/database.yml
DELETED
data/test/search_flip_test.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
|
2
|
-
require File.expand_path("../test_helper", __FILE__)
|
3
|
-
|
4
|
-
class SearchFlipTest < SearchFlip::TestCase
|
5
|
-
def test_msearch
|
6
|
-
ProductIndex.import create(:product)
|
7
|
-
CommentIndex.import create(:comment)
|
8
|
-
|
9
|
-
responses = SearchFlip.msearch([ProductIndex.match_all, CommentIndex.match_all])
|
10
|
-
|
11
|
-
assert_equal 2, responses.size
|
12
|
-
assert_equal 1, responses[0].total_entries
|
13
|
-
assert_equal 1, responses[1].total_entries
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_aliases
|
17
|
-
assert SearchFlip.aliases(actions: [
|
18
|
-
add: { index: "products", alias: "alias1" }
|
19
|
-
])
|
20
|
-
|
21
|
-
assert SearchFlip.aliases(actions: [
|
22
|
-
remove: { index: "products", alias: "alias1" }
|
23
|
-
])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|