daedal 0.0.14 → 0.0.15
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 +4 -4
- data/Gemfile.lock +15 -16
- data/README.md +2 -4
- data/lib/daedal.rb +1 -0
- data/lib/daedal/filters/geo_distance_range_filter.rb +55 -0
- data/lib/daedal/queries/range_query.rb +3 -4
- data/lib/daedal/version.rb +2 -2
- data/spec/unit/daedal/filters/geo_distance_range_filter_spec.rb +110 -0
- data/spec/unit/daedal/queries/range_query_spec.rb +2 -2
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11c6ae3d232c10eb5d671406d9fe201d778c77dc
|
4
|
+
data.tar.gz: b59495f804fbc653fb9515c1fe6d0f29478d4a55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1886174417cd61ff5ffa31cd6807bb6eb1211f05f6237951ab39f7c09542edc744391bb70793caed483b92943a73b7b8bf4dd185f6a1d8cd97762f9bbe26a2f1
|
7
|
+
data.tar.gz: f2a586eefd70d05cbfcd925427ee691198d8bb2caab383ab66e641325a0ecb8d4378e2eb2200b0a4981b0efef057cac0f940b54c5a7b1f4b348f1348a5ef56f4
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
daedal (0.0.
|
4
|
+
daedal (0.0.15)
|
5
5
|
virtus (>= 1.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
axiom-types (0.
|
11
|
-
descendants_tracker (~> 0.0.
|
12
|
-
ice_nine (~> 0.
|
13
|
-
|
10
|
+
axiom-types (0.0.5)
|
11
|
+
descendants_tracker (~> 0.0.1)
|
12
|
+
ice_nine (~> 0.9)
|
13
|
+
backports (3.3.5)
|
14
14
|
celluloid (0.15.2)
|
15
15
|
timers (~> 1.1.0)
|
16
16
|
coderay (1.1.0)
|
17
|
-
coercible (
|
17
|
+
coercible (0.2.0)
|
18
|
+
backports (~> 3.0, >= 3.1.0)
|
18
19
|
descendants_tracker (~> 0.0.1)
|
19
20
|
coveralls (0.7.0)
|
20
21
|
multi_json (~> 1.3)
|
@@ -22,10 +23,9 @@ GEM
|
|
22
23
|
simplecov (>= 0.7)
|
23
24
|
term-ansicolor
|
24
25
|
thor
|
25
|
-
descendants_tracker (0.0.
|
26
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
26
|
+
descendants_tracker (0.0.3)
|
27
27
|
diff-lcs (1.2.5)
|
28
|
-
equalizer (0.0.
|
28
|
+
equalizer (0.0.8)
|
29
29
|
ffi (1.9.3)
|
30
30
|
formatador (0.2.4)
|
31
31
|
fuubar (1.2.1)
|
@@ -41,7 +41,7 @@ GEM
|
|
41
41
|
guard-rspec (4.2.0)
|
42
42
|
guard (>= 2.1.1)
|
43
43
|
rspec (>= 2.14, < 4.0)
|
44
|
-
ice_nine (0.
|
44
|
+
ice_nine (0.10.0)
|
45
45
|
listen (2.4.0)
|
46
46
|
celluloid (>= 0.15.2)
|
47
47
|
rb-fsevent (>= 0.9.3)
|
@@ -77,14 +77,13 @@ GEM
|
|
77
77
|
term-ansicolor (1.2.2)
|
78
78
|
tins (~> 0.8)
|
79
79
|
thor (0.18.1)
|
80
|
-
thread_safe (0.3.4)
|
81
80
|
timers (1.1.0)
|
82
81
|
tins (0.13.1)
|
83
|
-
virtus (1.0.
|
84
|
-
axiom-types (~> 0.
|
85
|
-
coercible (~>
|
86
|
-
descendants_tracker (~> 0.0.
|
87
|
-
equalizer (~> 0.0.
|
82
|
+
virtus (1.0.0)
|
83
|
+
axiom-types (~> 0.0.5)
|
84
|
+
coercible (~> 0.2)
|
85
|
+
descendants_tracker (~> 0.0.1)
|
86
|
+
equalizer (~> 0.0.7)
|
88
87
|
|
89
88
|
PLATFORMS
|
90
89
|
ruby
|
data/README.md
CHANGED
@@ -23,9 +23,6 @@ query DSL into Ruby objects, Daedal addresses the following issues:
|
|
23
23
|
Daedal also makes it easy to define custom queries tailored to your specific use case - you can see
|
24
24
|
a simple example at the end of the documentation.
|
25
25
|
|
26
|
-
Daedal itself is designed more as a "low level" library, and doesn't necessarily make for terribly elegant code.
|
27
|
-
If you'd prefer a more Ruby-friendly block DSL, you can take a look at a new project I've been working on, [DaedalSL](https://github.com/RallyPointNetworks/daedal-sl).
|
28
|
-
|
29
26
|
Installation
|
30
27
|
------------
|
31
28
|
|
@@ -135,6 +132,7 @@ Currently, the following filters have been implemented:
|
|
135
132
|
* [and filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-and-filter.html)
|
136
133
|
* [bool filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html)
|
137
134
|
* [geo distance filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-filter.html)
|
135
|
+
* [geo distance range filter](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/geo-distance.html#geo-distance-range)
|
138
136
|
* [or filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-or-filter.html)
|
139
137
|
* [range filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html)
|
140
138
|
* [term filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html)
|
@@ -257,4 +255,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
257
255
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
258
256
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
259
257
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
260
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
258
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/daedal.rb
CHANGED
@@ -26,6 +26,7 @@ require 'daedal/filters/term_filter'
|
|
26
26
|
require 'daedal/filters/terms_filter'
|
27
27
|
require 'daedal/filters/range_filter'
|
28
28
|
require 'daedal/filters/geo_distance_filter'
|
29
|
+
require 'daedal/filters/geo_distance_range_filter'
|
29
30
|
require 'daedal/filters/and_filter'
|
30
31
|
require 'daedal/filters/or_filter'
|
31
32
|
require 'daedal/filters/bool_filter'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Daedal
|
2
|
+
module Filters
|
3
|
+
"""Class for the geo filter with range abilities"""
|
4
|
+
class GeoDistanceRangeFilter < Filter
|
5
|
+
POSSIBLE_COMPARE_OPTIONS = %i(gte gt lte lt)
|
6
|
+
|
7
|
+
# required attributes
|
8
|
+
attribute :field, Daedal::Attributes::Field
|
9
|
+
attribute :lat, Float
|
10
|
+
attribute :lon, Float
|
11
|
+
|
12
|
+
# non required attributes
|
13
|
+
attribute :unit, Daedal::Attributes::DistanceUnit, default: 'km'
|
14
|
+
POSSIBLE_COMPARE_OPTIONS.each do |possible_compare|
|
15
|
+
attribute possible_compare, Daedal::Attributes::QueryValue, required: false
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(options={})
|
19
|
+
super options
|
20
|
+
validate_compare_options(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_hash
|
24
|
+
{
|
25
|
+
geo_distance_range: {
|
26
|
+
field => {
|
27
|
+
lat: lat,
|
28
|
+
lon: lon
|
29
|
+
}
|
30
|
+
}.merge(compare_options)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def compare_options
|
37
|
+
POSSIBLE_COMPARE_OPTIONS.each_with_object({}) do |compare_option, compare_options|
|
38
|
+
compare_options[compare_option] = decorate_distance(attributes[compare_option]) if attributes[compare_option]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def decorate_distance(distance)
|
43
|
+
"#{distance}#{unit}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_compare_options(options)
|
47
|
+
if options.values_at(*POSSIBLE_COMPARE_OPTIONS).compact.empty?
|
48
|
+
raise 'Must give at least one of gte, gt, lt, or lte'
|
49
|
+
end
|
50
|
+
raise 'gte & gt are not valid together' if gte && gt
|
51
|
+
raise 'gte & gt are not valid together' if lte && lt
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -23,11 +23,10 @@ module Daedal
|
|
23
23
|
|
24
24
|
def to_hash
|
25
25
|
inner_result = attributes.select { |k,v| MINIMUM_ATTRIBUTES.include?(k) && !v.nil? }
|
26
|
-
inner_result.merge(boost: boost) if boost
|
27
|
-
|
28
|
-
{range: {field => inner_result} }
|
26
|
+
inner_result.merge!(boost: boost) if boost
|
29
27
|
|
28
|
+
{range: {field => inner_result} }
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
33
|
-
end
|
32
|
+
end
|
data/lib/daedal/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Daedal
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
2
|
+
VERSION = '0.0.15'
|
3
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Daedal::Filters::GeoDistanceRangeFilter do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
Daedal::Filters::GeoDistanceRangeFilter
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'without a field specified' do
|
10
|
+
it 'will raise an error' do
|
11
|
+
expect{subject.new(lat: 10, lon: 30, gte: 5)}.to raise_error(Virtus::CoercionError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without a compare options specified' do
|
16
|
+
it 'will raise an error' do
|
17
|
+
expect{subject.new(field: :location, lat: 10, lon: 30)}.to raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'without a lat specified' do
|
22
|
+
it 'will raise an error' do
|
23
|
+
expect{subject.new(field: :location, gte: 5, lon: 30)}.to raise_error(Virtus::CoercionError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'without a lon specified' do
|
28
|
+
it 'will raise an error' do
|
29
|
+
expect{subject.new(field: :location, lat: 10, gte: 5)}.to raise_error(Virtus::CoercionError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with an invalid unit specified' do
|
34
|
+
it 'will raise an error' do
|
35
|
+
expect{subject.new(field: :test, gte: 5, lat: 10, lon: 30, unit: 'test')}.to raise_error(Virtus::CoercionError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with an invalid lat specified' do
|
40
|
+
it 'will raise an error' do
|
41
|
+
expect{subject.new(field: :location, gte: 5, lat: 'test', lon: 30)}.to raise_error(Virtus::CoercionError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with an invalid lon specified' do
|
46
|
+
it 'will raise an error' do
|
47
|
+
expect{subject.new(field: :location, gte: 5, lat: 10, lon: 'test')}.to raise_error(Virtus::CoercionError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with wrong compare options' do
|
52
|
+
it 'will raise error with less than or equal to + less than compare' do
|
53
|
+
expect{subject.new(field: :test, lat: 10, lon: 30, lte: 5, lt: 5)}.to raise_error
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'will raise error with more than or equal to + more than compare' do
|
57
|
+
expect{subject.new(field: :test, lat: 10, lon: 30, gte: 5, gt: 5)}.to raise_error
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with all attributes' do
|
62
|
+
let(:filter) do
|
63
|
+
subject.new(field: :location, lat: 10, lon: 30, gte: 1, lte: 2)
|
64
|
+
end
|
65
|
+
|
66
|
+
let(:filter_hash) do
|
67
|
+
{
|
68
|
+
geo_distance_range: {
|
69
|
+
gte: '1km',
|
70
|
+
lte: '2km',
|
71
|
+
location: {
|
72
|
+
lat: 10,
|
73
|
+
lon: 30
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'will have correct filter hash' do
|
80
|
+
expect(filter.to_hash).to eq filter_hash
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'will use km as the default unit' do
|
84
|
+
expect(filter.unit).to eq 'km'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with miles as unit' do
|
89
|
+
let(:filter) do
|
90
|
+
subject.new(field: :location, lat: 10, lon: 30, gte: 1, lte: 2, unit: 'mi')
|
91
|
+
end
|
92
|
+
|
93
|
+
let(:filter_hash) do
|
94
|
+
{
|
95
|
+
geo_distance_range: {
|
96
|
+
gte: '1mi',
|
97
|
+
lte: '2mi',
|
98
|
+
location: {
|
99
|
+
lat: 10,
|
100
|
+
lon: 30
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should be possible to specify miles' do
|
107
|
+
expect(filter.to_hash).to eq filter_hash
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -64,7 +64,7 @@ describe Daedal::Queries::RangeQuery do
|
|
64
64
|
context 'with field, boost and one or more minimum attribute' do
|
65
65
|
let(:params) { { field: field, boost: boost }.merge(attr_hash) }
|
66
66
|
let(:query) { subject.new(params) }
|
67
|
-
let(:hash_query) { { range: { field => attr_hash } } }
|
67
|
+
let(:hash_query) { { range: { field => attr_hash.merge(boost: boost) } } }
|
68
68
|
it "will not raise an error when only #{attrs.join(', ')} is specified" do
|
69
69
|
expect { query }.to_not raise_error
|
70
70
|
end
|
@@ -84,4 +84,4 @@ describe Daedal::Queries::RangeQuery do
|
|
84
84
|
it_behaves_like "range query with minimum attributes", attrs
|
85
85
|
end
|
86
86
|
end
|
87
|
-
end
|
87
|
+
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daedal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Schuch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.0.0
|
27
27
|
description: Classes for easier ElasticSearch query creation
|
@@ -30,9 +30,9 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
33
|
+
- .gitignore
|
34
|
+
- .rspec
|
35
|
+
- .travis.yml
|
36
36
|
- Gemfile
|
37
37
|
- Gemfile.lock
|
38
38
|
- Guardfile
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/daedal/filters/exists_filter.rb
|
60
60
|
- lib/daedal/filters/filter.rb
|
61
61
|
- lib/daedal/filters/geo_distance_filter.rb
|
62
|
+
- lib/daedal/filters/geo_distance_range_filter.rb
|
62
63
|
- lib/daedal/filters/nested_filter.rb
|
63
64
|
- lib/daedal/filters/or_filter.rb
|
64
65
|
- lib/daedal/filters/range_filter.rb
|
@@ -85,6 +86,7 @@ files:
|
|
85
86
|
- spec/unit/daedal/filters/bool_filter_spec.rb
|
86
87
|
- spec/unit/daedal/filters/exists_filter_spec.rb
|
87
88
|
- spec/unit/daedal/filters/geo_distance_filter_spec.rb
|
89
|
+
- spec/unit/daedal/filters/geo_distance_range_filter_spec.rb
|
88
90
|
- spec/unit/daedal/filters/nested_filter_spec.rb
|
89
91
|
- spec/unit/daedal/filters/or_filter_spec.rb
|
90
92
|
- spec/unit/daedal/filters/range_filter_spec.rb
|
@@ -114,19 +116,18 @@ require_paths:
|
|
114
116
|
- lib
|
115
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
116
118
|
requirements:
|
117
|
-
- -
|
119
|
+
- - '>='
|
118
120
|
- !ruby/object:Gem::Version
|
119
121
|
version: '0'
|
120
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
123
|
requirements:
|
122
|
-
- -
|
124
|
+
- - '>='
|
123
125
|
- !ruby/object:Gem::Version
|
124
126
|
version: '0'
|
125
127
|
requirements: []
|
126
128
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.0.6
|
128
130
|
signing_key:
|
129
131
|
specification_version: 4
|
130
132
|
summary: ElasticSearch Query DSL Builders
|
131
133
|
test_files: []
|
132
|
-
has_rdoc:
|