daedal 0.0.17 → 0.0.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27cd710adc4e066c10e7a70e93e7bcc021f39e97
4
- data.tar.gz: adc66f8d210e1f33e56cc4d39dd9b9467a68546f
3
+ metadata.gz: 42810c58167abc4ba533fc0eafac07fcaba97116
4
+ data.tar.gz: 08005b8084eb8ebb7e61215016f6ca9be1f77805
5
5
  SHA512:
6
- metadata.gz: 8b9509704bf2f5965b25dd09c8f6370bcca897bc62a7ffec635368b363f275261cba9b39ddb99dfedb54b4314cc33d71b44ca5e0fa4375c64c46be91a181ea5e
7
- data.tar.gz: 4fb13110837bf95334b67fbc247f36ccff48a627948e40ea9a699632c3a68a4924aff8012a78744948e1d00dac46debf4f8af332bbb7c7f709aa3f30a6ffe646
6
+ metadata.gz: 32f890e3ba820bcb6a034628cd661e20eb2012a130b198ad897287d9b9f2233fdbf1c7e7b2c7c906f2c85a96b561d15b1cf5c9620711d9c6e205905826d13abc
7
+ data.tar.gz: b51239c437c8f164ca8b5bb0d6f48ffb0b8c401ea93e1b0278965be940f7225e5a17db84e01f2b63c00c337b4af95852ba4fe4686d1fdb422519607e7fde0cc6
data/.travis.yml CHANGED
@@ -1,6 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
+ - 2.1.9
5
+ - 2.2.6
6
+ - 2.3.3
7
+ - 2.4.0
4
8
  notifications:
5
9
  email:
6
10
  - cas13091@gmail.com
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daedal (0.0.17)
4
+ daedal (0.0.18)
5
5
  virtus (>= 1.0.0)
6
6
 
7
7
  GEM
@@ -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.11.1)
44
+ ice_nine (0.11.2)
45
45
  listen (2.4.0)
46
46
  celluloid (>= 0.15.2)
47
47
  rb-fsevent (>= 0.9.3)
@@ -77,14 +77,14 @@ GEM
77
77
  term-ansicolor (1.2.2)
78
78
  tins (~> 0.8)
79
79
  thor (0.18.1)
80
- thread_safe (0.3.5)
80
+ thread_safe (0.3.6)
81
81
  timers (1.1.0)
82
82
  tins (0.13.1)
83
- virtus (1.0.2)
83
+ virtus (1.0.5)
84
84
  axiom-types (~> 0.1)
85
85
  coercible (~> 1.0)
86
- descendants_tracker (~> 0.0.3)
87
- equalizer (~> 0.0.9)
86
+ descendants_tracker (~> 0.0, >= 0.0.3)
87
+ equalizer (~> 0.0, >= 0.0.9)
88
88
 
89
89
  PLATFORMS
90
90
  ruby
@@ -96,3 +96,6 @@ DEPENDENCIES
96
96
  guard
97
97
  guard-rspec
98
98
  rspec
99
+
100
+ BUNDLED WITH
101
+ 1.13.6
data/README.md CHANGED
@@ -132,6 +132,7 @@ term_filter.to_json # => "{\"term\":{\"characters\":\"Pozzo\"}}"
132
132
 
133
133
  Currently, the following filters have been implemented:
134
134
  * [and filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-and-filter.html)
135
+ * [not filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-not-filter.html)
135
136
  * [bool filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html)
136
137
  * [geo distance filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-filter.html)
137
138
  * [geo distance range filter](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/geo-distance.html#geo-distance-range)
@@ -155,7 +156,7 @@ constant_score_query = {'constant_score' => {'boost' => 'foo', 'query' => {'matc
155
156
 
156
157
  would yield a server error, since the `boost` parameter must be a number.
157
158
 
158
- Daedal uses [Virtus](https://github.com/solnic/virtus) to perform data-type coercions.
159
+ Daedal uses [Virtus](https://github.com/solnic/virtus) to perform data-type coercions.
159
160
  Invalid query parameters are surfaced at runtime, making debugging much easier.
160
161
  The previous example in Daedal would raise an error:
161
162
 
@@ -192,7 +193,7 @@ Here are some guidelines:
192
193
  Example of a custom query:
193
194
  ``` ruby
194
195
  class PlayQuery < Daedal::Queries::Query
195
-
196
+
196
197
  # define the parameters that you want in your query
197
198
  # if the field is optional, make sure to set required to false
198
199
  attribute :author, String
@@ -212,7 +213,7 @@ class PlayQuery < Daedal::Queries::Query
212
213
  full_query
213
214
  end
214
215
 
215
- # define the to_hash method to convert for use in ElasticSearch
216
+ # define the to_hash method to convert for use in ElasticSearch
216
217
  def to_hash
217
218
  construct_query.to_hash
218
219
  end
data/lib/daedal.rb CHANGED
@@ -31,10 +31,12 @@ require 'daedal/filters/range_filter'
31
31
  require 'daedal/filters/geo_distance_filter'
32
32
  require 'daedal/filters/geo_distance_range_filter'
33
33
  require 'daedal/filters/and_filter'
34
+ require 'daedal/filters/not_filter'
34
35
  require 'daedal/filters/or_filter'
35
36
  require 'daedal/filters/bool_filter'
36
37
  require 'daedal/filters/nested_filter'
37
38
  require 'daedal/filters/type_filter'
39
+ require 'daedal/filters/regexp_filter'
38
40
 
39
41
  # queries
40
42
  require 'daedal/queries/match_all_query'
@@ -53,5 +55,5 @@ require 'daedal/queries/terms_query'
53
55
  require 'daedal/queries/range_query'
54
56
  require 'daedal/queries/function_score_query'
55
57
  require 'daedal/queries/simple_query_string_query'
56
-
58
+ require 'daedal/queries/regexp_query'
57
59
  # facets
@@ -4,7 +4,7 @@ module Daedal
4
4
  a string, a symbol, a float, or an integer. If it's none
5
5
  of those, raises a coercion error."""
6
6
  class QueryValue < Virtus::Attribute
7
- ALLOWED_QUERY_VALUE_CLASSES = [String, Symbol, Float, Fixnum, Boolean, TrueClass, FalseClass]
7
+ ALLOWED_QUERY_VALUE_CLASSES = [String, Symbol, Float, 0.class, Boolean, TrueClass, FalseClass]
8
8
  def coerce(q)
9
9
  if !required? and q.nil?
10
10
  return q
@@ -0,0 +1,13 @@
1
+ module Daedal
2
+ module Filters
3
+ class NotFilter < Filter
4
+
5
+ # required attributes
6
+ attribute :filter, Daedal::Attributes::Filter
7
+
8
+ def to_hash
9
+ {:not => filter.to_hash}
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module Daedal
2
+ module Filters
3
+ """Class for the regexp filter"""
4
+ class RegexpFilter < Filter
5
+
6
+ # required attributes
7
+ attribute :field, Daedal::Attributes::Field
8
+ attribute :query, Daedal::Attributes::LowerCaseString
9
+
10
+ # non required attributes
11
+ attribute :flags, Array[Daedal::Attributes::Flag], required: false
12
+
13
+ def to_hash
14
+ result = {regexp: {field => {value: query}}}
15
+ options = set_options
16
+ result[:regexp][field].merge!(options)
17
+
18
+ result
19
+ end
20
+
21
+ private
22
+
23
+ def set_options
24
+ { flags: parse_flags(flags) }.select {|k,v| !v.nil?}
25
+ end
26
+
27
+ def parse_flags(flags)
28
+ flags.map(&:to_s).join('|') unless flags.empty?
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ module Daedal
2
+ module Queries
3
+ """Class for the regexp query"""
4
+ class RegexpQuery < Query
5
+
6
+ # required attributes
7
+ attribute :field, Daedal::Attributes::Field
8
+ attribute :query, Daedal::Attributes::LowerCaseString
9
+
10
+ # non required attributes
11
+ attribute :boost, Daedal::Attributes::Boost, required: false
12
+ attribute :flags, Array[Daedal::Attributes::Flag], required: false
13
+ attribute :max_determinized_states, Integer, required: false
14
+
15
+ def to_hash
16
+ result = {regexp: {field => {value: query}}}
17
+ options = set_options
18
+ result[:regexp][field].merge!(options)
19
+
20
+ result
21
+ end
22
+
23
+ private
24
+
25
+ def set_options
26
+ {
27
+ boost: boost,
28
+ flags: parse_flags(flags),
29
+ max_determinized_states: max_determinized_states,
30
+ }.select {|k,v| !v.nil?}
31
+ end
32
+
33
+ def parse_flags(flags)
34
+ flags.map(&:to_s).join('|') unless flags.empty?
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module Daedal
2
- VERSION = '0.0.17'
2
+ VERSION = '0.0.18'
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Filters::NotFilter do
4
+
5
+ context 'without filter specified' do
6
+ it 'will raise an error' do
7
+ expect { described_class.new }.to raise_error(Virtus::CoercionError)
8
+ end
9
+ end
10
+
11
+ context 'with filter specified' do
12
+ subject { described_class.new(filter: term_filter) }
13
+
14
+ let(:term_filter) { Daedal::Filters::TermFilter.new(field: :foo, term: :bar) }
15
+ let(:hash_filter) { { :not => term_filter.to_hash } }
16
+
17
+ it 'will populate the field and term attributes appropriately' do
18
+ expect(subject.filter).to eq term_filter
19
+ end
20
+ it 'will have the correct hash representation' do
21
+ expect(subject.to_hash).to eq hash_filter
22
+ end
23
+ it 'will have the correct json representation' do
24
+ expect(subject.to_json).to eq hash_filter.to_json
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe Daedal::Filters::RegexpFilter do
4
+ subject { Daedal::Filters::RegexpFilter }
5
+
6
+ context "without a field" do
7
+ it { expect{subject.new(filter: :foo)}.to raise_error(Virtus::CoercionError) }
8
+ end
9
+
10
+ context "without a query" do
11
+ it { expect{subject.new(fied: :foo)}.to raise_error(Virtus::CoercionError) }
12
+ end
13
+
14
+ context "with a field and a query" do
15
+ let(:filter) { subject.new(field: :foo, query: :bar) }
16
+ let(:hash_filter) { {regexp: {foo: {value: 'bar'}}} }
17
+
18
+ it "will create a regexp query with the correct values" do
19
+ expect(filter.field).to eq :foo
20
+ expect(filter.query).to eq "bar"
21
+ end
22
+
23
+ it "will have the correct hash and json representations" do
24
+ expect(filter.to_hash).to eq hash_filter
25
+ expect(filter.to_json).to eq hash_filter.to_json
26
+ end
27
+ end
28
+
29
+ context "with a field and an upper cased query" do
30
+ let(:filter) { subject.new(field: :foo, query: "BAR") }
31
+ let(:hash_filter) { {regexp: {foo: {value: 'bar'}}} }
32
+
33
+ it "will create a regexp query with the correct values" do
34
+ expect(filter.field).to eq :foo
35
+ expect(filter.query).to eq "bar"
36
+ end
37
+
38
+ it "will have the correct hash and json representations" do
39
+ expect(filter.to_hash).to eq hash_filter
40
+ expect(filter.to_json).to eq hash_filter.to_json
41
+ end
42
+ end
43
+
44
+ context "with flags" do
45
+ let(:filter) { subject.new(field: :foo, query: :bar, flags: [:intersection, :complement]) }
46
+ let(:hash_filter) { {regexp: {foo: {value: 'bar', flags: "intersection|complement"}}} }
47
+
48
+ it { expect(filter.flags).to eq [:intersection, :complement] }
49
+
50
+ it "will have the correct hash and json representation" do
51
+ expect(filter.to_hash).to eq hash_filter
52
+ expect(filter.to_json).to eq hash_filter.to_json
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Queries::RegexpQuery do
4
+ subject { Daedal::Queries::RegexpQuery }
5
+
6
+ context "without a field" do
7
+ it { expect{subject.new(query: :foo)}.to raise_error(Virtus::CoercionError) }
8
+ end
9
+
10
+ context "without a query" do
11
+ it { expect{subject.new(fied: :foo)}.to raise_error(Virtus::CoercionError) }
12
+ end
13
+
14
+ context "with a field and a query" do
15
+ let(:query) { subject.new(field: :foo, query: :bar) }
16
+ let(:hash_query) { {regexp: {foo: {value: 'bar'}}} }
17
+
18
+ it "will create a regexp query with the correct values" do
19
+ expect(query.field).to eq :foo
20
+ expect(query.query).to eq "bar"
21
+ end
22
+
23
+ it "will have the correct hash and json representations" do
24
+ expect(query.to_hash).to eq hash_query
25
+ expect(query.to_json).to eq hash_query.to_json
26
+ end
27
+ end
28
+
29
+ context "with a field and an upper cased query" do
30
+ let(:query) { subject.new(field: :foo, query: "BAR") }
31
+ let(:hash_query) { {regexp: {foo: {value: 'bar'}}} }
32
+
33
+ it "will create a regexp query with the correct values" do
34
+ expect(query.field).to eq :foo
35
+ expect(query.query).to eq "bar"
36
+ end
37
+
38
+ it "will have the correct hash and json representations" do
39
+ expect(query.to_hash).to eq hash_query
40
+ expect(query.to_json).to eq hash_query.to_json
41
+ end
42
+ end
43
+
44
+ context "with a boost" do
45
+ let(:query) { subject.new(field: :foo, query: :bar, boost: 1.2) }
46
+ let(:hash_query) { {regexp: {foo: {value: 'bar', boost: 1.2}}} }
47
+
48
+ it { expect(query.boost).to eq 1.2 }
49
+
50
+ it "will have the correct hash and json representation" do
51
+ expect(query.to_hash).to eq hash_query
52
+ expect(query.to_json).to eq hash_query.to_json
53
+ end
54
+ end
55
+
56
+ context "with flags" do
57
+ let(:query) { subject.new(field: :foo, query: :bar, flags: [:intersection, :complement]) }
58
+ let(:hash_query) { {regexp: {foo: {value: 'bar', flags: "intersection|complement"}}} }
59
+
60
+ it { expect(query.flags).to eq [:intersection, :complement] }
61
+
62
+ it "will have the correct hash and json representation" do
63
+ expect(query.to_hash).to eq hash_query
64
+ expect(query.to_json).to eq hash_query.to_json
65
+ end
66
+ end
67
+
68
+ context "with max determinized states" do
69
+ let(:query) { subject.new(field: :foo, query: :bar, max_determinized_states: 20000) }
70
+ let(:hash_query) { {regexp: {foo: {value: 'bar', max_determinized_states: 20000}}} }
71
+
72
+ it { expect(query.max_determinized_states).to eq 20000 }
73
+
74
+ it "will have the correct hash and json representation" do
75
+ expect(query.to_hash).to eq hash_query
76
+ expect(query.to_json).to eq hash_query.to_json
77
+ end
78
+ end
79
+ 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.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Schuch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-23 00:00:00.000000000 Z
11
+ date: 2017-03-07 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
- - .gitignore
34
- - .rspec
35
- - .travis.yml
33
+ - ".gitignore"
34
+ - ".rspec"
35
+ - ".travis.yml"
36
36
  - Gemfile
37
37
  - Gemfile.lock
38
38
  - Guardfile
@@ -64,8 +64,10 @@ files:
64
64
  - lib/daedal/filters/geo_distance_filter.rb
65
65
  - lib/daedal/filters/geo_distance_range_filter.rb
66
66
  - lib/daedal/filters/nested_filter.rb
67
+ - lib/daedal/filters/not_filter.rb
67
68
  - lib/daedal/filters/or_filter.rb
68
69
  - lib/daedal/filters/range_filter.rb
70
+ - lib/daedal/filters/regexp_filter.rb
69
71
  - lib/daedal/filters/term_filter.rb
70
72
  - lib/daedal/filters/terms_filter.rb
71
73
  - lib/daedal/filters/type_filter.rb
@@ -83,6 +85,7 @@ files:
83
85
  - lib/daedal/queries/query.rb
84
86
  - lib/daedal/queries/query_string_query.rb
85
87
  - lib/daedal/queries/range_query.rb
88
+ - lib/daedal/queries/regexp_query.rb
86
89
  - lib/daedal/queries/simple_query_string_query.rb
87
90
  - lib/daedal/queries/term_query.rb
88
91
  - lib/daedal/queries/terms_query.rb
@@ -95,8 +98,10 @@ files:
95
98
  - spec/unit/daedal/filters/geo_distance_filter_spec.rb
96
99
  - spec/unit/daedal/filters/geo_distance_range_filter_spec.rb
97
100
  - spec/unit/daedal/filters/nested_filter_spec.rb
101
+ - spec/unit/daedal/filters/not_filter_spec.rb
98
102
  - spec/unit/daedal/filters/or_filter_spec.rb
99
103
  - spec/unit/daedal/filters/range_filter_spec.rb
104
+ - spec/unit/daedal/filters/regexp_filter_spec.rb
100
105
  - spec/unit/daedal/filters/term_filter_spec.rb
101
106
  - spec/unit/daedal/filters/terms_filter_spec.rb
102
107
  - spec/unit/daedal/filters/type_filter_spec.rb
@@ -113,6 +118,7 @@ files:
113
118
  - spec/unit/daedal/queries/prefix_query_spec.rb
114
119
  - spec/unit/daedal/queries/query_string_spec.rb
115
120
  - spec/unit/daedal/queries/range_query_spec.rb
121
+ - spec/unit/daedal/queries/regexp_query_spec.rb
116
122
  - spec/unit/daedal/queries/simple_query_string_spec.rb
117
123
  - spec/unit/daedal/queries/term_query_spec.rb
118
124
  - spec/unit/daedal/queries/terms_query_spec.rb
@@ -126,17 +132,17 @@ require_paths:
126
132
  - lib
127
133
  required_ruby_version: !ruby/object:Gem::Requirement
128
134
  requirements:
129
- - - '>='
135
+ - - ">="
130
136
  - !ruby/object:Gem::Version
131
137
  version: '0'
132
138
  required_rubygems_version: !ruby/object:Gem::Requirement
133
139
  requirements:
134
- - - '>='
140
+ - - ">="
135
141
  - !ruby/object:Gem::Version
136
142
  version: '0'
137
143
  requirements: []
138
144
  rubyforge_project:
139
- rubygems_version: 2.0.6
145
+ rubygems_version: 2.5.1
140
146
  signing_key:
141
147
  specification_version: 4
142
148
  summary: ElasticSearch Query DSL Builders