daedal 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +3 -3
- data/lib/daedal.rb +1 -0
- data/lib/daedal/queries/range_query.rb +33 -0
- data/lib/daedal/version.rb +1 -1
- data/spec/unit/daedal/queries/range_query_spec.rb +87 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c4bde7051a2f331ec26642e3ffc6b517bec4ffc
|
4
|
+
data.tar.gz: 834a366bd9a23949f0db2a878c71450fc83ed09e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7e1c3d7af4517105b94b3182e205f1de57b50c5e9ac9e1cfbbb8dd65463ac37ecef64bb0c092246aa608c63a41e86a110be4da5e4d5987c10cb976bbee63997
|
7
|
+
data.tar.gz: 5d3c1e527051b559fd0eec04254c8f68ee596cbb3515805630e035153c51c6b2a084bcbaa94b5aff1bfaf36f60790d88674617e0848fed0f29d8737d08952577
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
daedal (0.0.
|
4
|
+
daedal (0.0.14)
|
5
5
|
virtus (>= 1.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -77,7 +77,7 @@ GEM
|
|
77
77
|
term-ansicolor (1.2.2)
|
78
78
|
tins (~> 0.8)
|
79
79
|
thor (0.18.1)
|
80
|
-
thread_safe (0.3.
|
80
|
+
thread_safe (0.3.4)
|
81
81
|
timers (1.1.0)
|
82
82
|
tins (0.13.1)
|
83
83
|
virtus (1.0.2)
|
data/README.md
CHANGED
@@ -104,13 +104,13 @@ Currently, the following queries have been implemented:
|
|
104
104
|
* [nested query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html)
|
105
105
|
* [prefix query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html)
|
106
106
|
* [query string query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)
|
107
|
+
* [range query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-range-query.html)
|
108
|
+
* [term query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-query.html)
|
109
|
+
* [terms query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html)
|
107
110
|
|
108
111
|
On deck:
|
109
112
|
* [function score query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)
|
110
|
-
* [range query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-range-query.html)
|
111
113
|
* [regexp query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html)
|
112
|
-
* [term query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-query.html)
|
113
|
-
* [terms query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html)
|
114
114
|
* [wildcard query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html)
|
115
115
|
|
116
116
|
Queries I'm not planning on implementing at all, since they're deprecated:
|
data/lib/daedal.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Daedal
|
2
|
+
module Queries
|
3
|
+
"" "Class for range query" ""
|
4
|
+
class RangeQuery < Query
|
5
|
+
|
6
|
+
# required attributes
|
7
|
+
attribute :field, Daedal::Attributes::Field
|
8
|
+
|
9
|
+
# non required attributes, but at least one must be given
|
10
|
+
MINIMUM_ATTRIBUTES = [:gte, :gt, :lte, :lt].sort
|
11
|
+
MINIMUM_ATTRIBUTES.each { |a| attribute a, Daedal::Attributes::QueryValue, required: false }
|
12
|
+
|
13
|
+
#non required attributes
|
14
|
+
attribute :boost, Daedal::Attributes::Boost, required: false
|
15
|
+
|
16
|
+
def initialize(options={})
|
17
|
+
super options
|
18
|
+
|
19
|
+
# ensure at least one of the minimum attributes is provided
|
20
|
+
raise "Must give at least one of the following: #{MINIMUM_ATTRIBUTES.join(', ')}" unless (attributes.reject { |k,v| v.nil? }.keys & MINIMUM_ATTRIBUTES).length > 0
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_hash
|
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} }
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/daedal/version.rb
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Daedal::Queries::RangeQuery do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
Daedal::Queries::RangeQuery
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:field) { :foo }
|
10
|
+
let(:boost) { 1.0 }
|
11
|
+
|
12
|
+
minimum_attributes = [:lt, :lte, :gt, :gte].sort
|
13
|
+
minimum_attributes.each { |a| let(a) { rand(0..100) } }
|
14
|
+
|
15
|
+
context 'without a field specified' do
|
16
|
+
it 'will raise an error' do
|
17
|
+
expect { subject.new(lt: 42) }.to raise_error(Virtus::CoercionError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with field specified only (without minimum attribute or boost)' do
|
22
|
+
it 'will raise an error' do
|
23
|
+
expect { subject.new(field: field) }.to raise_error(RuntimeError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with field and boost specified (without minimum attribute)' do
|
28
|
+
it 'will raise an error' do
|
29
|
+
expect { subject.new(field: field, boost: boost) }.to raise_error(RuntimeError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with field and one minimum attribute' do
|
34
|
+
minimum_attributes.each do |a|
|
35
|
+
let(:params) { { field: field, a => self.send(a) } }
|
36
|
+
it "will populate the field attribute appropriately" do
|
37
|
+
expect(subject.new(params).field).to eq field
|
38
|
+
end
|
39
|
+
it "will populate the #{a} attribute appropriately" do
|
40
|
+
expect(subject.new(params).send(a)).to eq params[a]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
shared_examples "range query with minimum attributes" do |attrs|
|
46
|
+
let(:attr_hash) { attrs.each_with_object({}) { |a, h| h.merge!(a => self.send(a)) } }
|
47
|
+
context "with minimum attributes #{attrs.inspect}" do
|
48
|
+
context 'with field and one or more minimum attribute' do
|
49
|
+
let(:params) { { field: field }.merge(attr_hash) }
|
50
|
+
let(:query) { subject.new(params) }
|
51
|
+
let(:hash_query) { { range: { field => attr_hash } } }
|
52
|
+
it "will not raise an error when only #{attrs.join(', ')} is specified" do
|
53
|
+
expect { query }.to_not raise_error
|
54
|
+
end
|
55
|
+
it "will have the correct hash representation when only #{attrs.join(', ')} is specified" do
|
56
|
+
expect(query.to_hash).to eq hash_query
|
57
|
+
end
|
58
|
+
|
59
|
+
it "will have the correct json representation when only #{attrs.join(', ')} is specified" do
|
60
|
+
expect(query.to_json).to eq hash_query.to_json
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'with field, boost and one or more minimum attribute' do
|
65
|
+
let(:params) { { field: field, boost: boost }.merge(attr_hash) }
|
66
|
+
let(:query) { subject.new(params) }
|
67
|
+
let(:hash_query) { { range: { field => attr_hash } } }
|
68
|
+
it "will not raise an error when only #{attrs.join(', ')} is specified" do
|
69
|
+
expect { query }.to_not raise_error
|
70
|
+
end
|
71
|
+
it "will have the correct hash representation when only #{attrs.join(', ')} is specified" do
|
72
|
+
expect(query.to_hash).to eq hash_query
|
73
|
+
end
|
74
|
+
|
75
|
+
it "will have the correct json representation when only #{attrs.join(', ')} is specified" do
|
76
|
+
expect(query.to_json).to eq hash_query.to_json
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
(1..minimum_attributes.length).to_a.each do |slice|
|
83
|
+
minimum_attributes.combination(slice).each do |attrs|
|
84
|
+
it_behaves_like "range query with minimum attributes", attrs
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Schuch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/daedal/queries/prefix_query.rb
|
77
77
|
- lib/daedal/queries/query.rb
|
78
78
|
- lib/daedal/queries/query_string_query.rb
|
79
|
+
- lib/daedal/queries/range_query.rb
|
79
80
|
- lib/daedal/queries/term_query.rb
|
80
81
|
- lib/daedal/queries/terms_query.rb
|
81
82
|
- lib/daedal/version.rb
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- spec/unit/daedal/queries/nested_query_spec.rb
|
101
102
|
- spec/unit/daedal/queries/prefix_query_spec.rb
|
102
103
|
- spec/unit/daedal/queries/query_string_spec.rb
|
104
|
+
- spec/unit/daedal/queries/range_query_spec.rb
|
103
105
|
- spec/unit/daedal/queries/term_query_spec.rb
|
104
106
|
- spec/unit/daedal/queries/terms_query_spec.rb
|
105
107
|
homepage: https://github.com/cschuch/daedal
|