elasticband 0.4.0 → 0.5.0
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 +8 -8
- data/lib/elasticband/filter.rb +2 -2
- data/lib/elasticband/filter/near.rb +5 -3
- data/lib/elasticband/version.rb +1 -1
- data/spec/filter/near_spec.rb +42 -4
- data/spec/filter_spec.rb +3 -1
- data/spec/query_spec.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWU0ZWNlNDdlMmZkM2YzMjBmOTc0MjNlMmZiNWM5MjdiMjY3MDM5NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjI5MGQ5ZGY1MWEwM2IwMGQzODQ0NTBlYTlkZDliZDIzNDk1ZDVlNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTk5YjUyZjBkNDNiZTI4MzI3MDI0N2YyNDJiNmU2NWZkNjg1ZDRlYzk1YjFj
|
10
|
+
NWY4MDliM2M0OThkYzMzNzVkNmE2MTg3N2NlZGMxY2Q4OTZlNjYyZGJlNWQ2
|
11
|
+
Yzk0MmU2NDQ1NjM0ZGIwMjIwYzEzNjA0NWI4MGEyZGZhOWM0YjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjcxNjU3OGFjMGVkZDZjNGM5OGQ1ZWUxNjQ5MDlmYjY3NDVjNDdkYWQzMDU0
|
14
|
+
YjZkYTg2NmQ5MmFkMDkxOTE3NWYxMDc0NDZiYjk0NTM3OTAwYjE0ZDA4NTcw
|
15
|
+
NzYwODE5MjlmYzdmMDE4NTJmNmQ0N2I2YmY1NjE1OGJlZjNiMmU=
|
data/lib/elasticband/filter.rb
CHANGED
@@ -41,8 +41,8 @@ module Elasticband
|
|
41
41
|
# Filter.parse(range: { companies_count: { gt: 1, gteq: 1, lt: 1, lteq: 1 } })
|
42
42
|
# => { range: { companies_count: { gt: 1, gte: 1, lt: 1, lte: 1 } } }
|
43
43
|
#
|
44
|
-
# Filter.parse(near: { latitude: 12, longitude: 34, distance: '5km' })
|
45
|
-
# => { geo_distance: { location: { lat: 12, lon: 34 } }, distance: '5km' }
|
44
|
+
# Filter.parse(near: { latitude: 12, longitude: 34, distance: '5km', type: :arc })
|
45
|
+
# => { geo_distance: { location: { lat: 12, lon: 34 } }, distance: '5km', distance_type: :arc }
|
46
46
|
#
|
47
47
|
# Filter.parse(script: ['(param1 + param2) > 0', param1: 1, param2: 1])
|
48
48
|
# => { script: { script: '(param1 + param2) > 0', params: { param1: 1, param2: 1 } } }
|
@@ -1,20 +1,22 @@
|
|
1
1
|
module Elasticband
|
2
2
|
class Filter
|
3
3
|
class Near < Filter
|
4
|
-
attr_accessor :on, :latitude, :longitude, :distance
|
4
|
+
attr_accessor :on, :latitude, :longitude, :distance, :type
|
5
5
|
|
6
|
-
def initialize(on: :location, latitude: nil, longitude: nil, distance: '100km')
|
6
|
+
def initialize(on: :location, latitude: nil, longitude: nil, distance: '100km', type: :arc)
|
7
7
|
self.on = on
|
8
8
|
self.latitude = latitude
|
9
9
|
self.longitude = longitude
|
10
10
|
self.distance = distance
|
11
|
+
self.type = type
|
11
12
|
end
|
12
13
|
|
13
14
|
def to_h
|
14
15
|
{
|
15
16
|
geo_distance: {
|
16
17
|
on => { lat: latitude, lon: longitude },
|
17
|
-
distance: distance
|
18
|
+
distance: distance,
|
19
|
+
distance_type: type
|
18
20
|
}
|
19
21
|
}
|
20
22
|
end
|
data/lib/elasticband/version.rb
CHANGED
data/spec/filter/near_spec.rb
CHANGED
@@ -4,22 +4,60 @@ RSpec.describe Elasticband::Filter::Near do
|
|
4
4
|
describe '#to_h' do
|
5
5
|
subject { described_class.new(options).to_h }
|
6
6
|
|
7
|
-
context 'with `:
|
7
|
+
context 'with `:latitude` and `:longitude` option' do
|
8
8
|
let(:options) { { latitude: 12.5, longitude: -34.6 } }
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'contains the given latitude and longitude options' do
|
11
|
+
is_expected.to eq(
|
12
|
+
geo_distance: {
|
13
|
+
location: { lat: 12.5, lon: -34.6 },
|
14
|
+
distance: '100km',
|
15
|
+
distance_type: :arc
|
16
|
+
}
|
17
|
+
)
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
context 'with `:on` option' do
|
14
22
|
let(:options) { { on: :loc, latitude: 12.5, longitude: -34.6 } }
|
15
23
|
|
16
|
-
it
|
24
|
+
it 'contains the given on option' do
|
25
|
+
is_expected.to eq(
|
26
|
+
geo_distance: {
|
27
|
+
loc: { lat: 12.5, lon: -34.6 },
|
28
|
+
distance: '100km',
|
29
|
+
distance_type: :arc
|
30
|
+
}
|
31
|
+
)
|
32
|
+
end
|
17
33
|
end
|
18
34
|
|
19
35
|
context 'with `:distance` option' do
|
20
36
|
let(:options) { { distance: '5km', latitude: 12.5, longitude: -34.6 } }
|
21
37
|
|
22
|
-
it
|
38
|
+
it 'contains the given distance option' do
|
39
|
+
is_expected.to eq(
|
40
|
+
geo_distance: {
|
41
|
+
location: { lat: 12.5, lon: -34.6 },
|
42
|
+
distance: '5km',
|
43
|
+
distance_type: :arc
|
44
|
+
}
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with `:type` option' do
|
50
|
+
let(:options) { { distance: '5km', latitude: 12.5, longitude: -34.6, type: :plane } }
|
51
|
+
|
52
|
+
it 'contains the given type option' do
|
53
|
+
is_expected.to eq(
|
54
|
+
geo_distance: {
|
55
|
+
location: { lat: 12.5, lon: -34.6 },
|
56
|
+
distance: '5km',
|
57
|
+
distance_type: :plane
|
58
|
+
}
|
59
|
+
)
|
60
|
+
end
|
23
61
|
end
|
24
62
|
end
|
25
63
|
end
|
data/spec/filter_spec.rb
CHANGED
@@ -100,7 +100,9 @@ RSpec.describe Elasticband::Filter do
|
|
100
100
|
|
101
101
|
context 'with `:near` option' do
|
102
102
|
let(:options) { { near: { on: :location, latitude: 12.5, longitude: -34.9, distance: '5km' } } }
|
103
|
-
let(:filter)
|
103
|
+
let(:filter) do
|
104
|
+
{ geo_distance: { location: { lat: 12.5, lon: -34.9 }, distance: '5km', distance_type: :arc } }
|
105
|
+
end
|
104
106
|
|
105
107
|
it { is_expected.to eq(filter) }
|
106
108
|
end
|
data/spec/query_spec.rb
CHANGED
@@ -265,7 +265,9 @@ RSpec.describe Elasticband::Query do
|
|
265
265
|
let(:options) { { near: { on: :location, latitude: 12.5, longitude: -34.9, distance: '5km' } } }
|
266
266
|
|
267
267
|
let(:query) { { match: { _all: 'foo' } } }
|
268
|
-
let(:filter)
|
268
|
+
let(:filter) do
|
269
|
+
{ geo_distance: { location: { lat: 12.5, lon: -34.9 }, distance: '5km', distance_type: :arc } }
|
270
|
+
end
|
269
271
|
|
270
272
|
it 'return a filtered query by geo_distance' do
|
271
273
|
is_expected.to eq(filtered: { query: query, filter: filter })
|