daedal 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67944926b6a5ef6c6eb5165191a03f089e784c89
4
- data.tar.gz: 0082ced2272905533bf4eae8912abb2bdb178ab6
3
+ metadata.gz: 27cd710adc4e066c10e7a70e93e7bcc021f39e97
4
+ data.tar.gz: adc66f8d210e1f33e56cc4d39dd9b9467a68546f
5
5
  SHA512:
6
- metadata.gz: f2a28d5bc4314a4827127eee9c300e14fefc2417c2fd25c7bd660d19f41a40bab560d051365c2449da4ee163a3c039e186ae5790b379022b13ad850a4128173e
7
- data.tar.gz: 80b821a4d5050ec57b8806548e1e2768a93b0b4af8df6b9299f11ba228950080aec796c201bb660d93585523fdccea9130e66c2954a5353d615fd095a6514f00
6
+ metadata.gz: 8b9509704bf2f5965b25dd09c8f6370bcca897bc62a7ffec635368b363f275261cba9b39ddb99dfedb54b4314cc33d71b44ca5e0fa4375c64c46be91a181ea5e
7
+ data.tar.gz: 4fb13110837bf95334b67fbc247f36ccff48a627948e40ea9a699632c3a68a4924aff8012a78744948e1d00dac46debf4f8af332bbb7c7f709aa3f30a6ffe646
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daedal (0.0.16)
4
+ daedal (0.0.17)
5
5
  virtus (>= 1.0.0)
6
6
 
7
7
  GEM
@@ -58,7 +58,7 @@ GEM
58
58
  rb-inotify (0.9.2)
59
59
  ffi (>= 0.5.0)
60
60
  rest-client (1.6.7)
61
- mime-types (>= 1.16)
61
+ mime-types (>= 1.17)
62
62
  rspec (2.14.1)
63
63
  rspec-core (~> 2.14.0)
64
64
  rspec-expectations (~> 2.14.0)
data/README.md CHANGED
@@ -102,6 +102,7 @@ Currently, the following queries have been implemented:
102
102
  * [nested query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html)
103
103
  * [prefix query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html)
104
104
  * [query string query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)
105
+ * [simple query string query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html)
105
106
  * [range query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-range-query.html)
106
107
  * [term query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-query.html)
107
108
  * [terms query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html)
@@ -140,6 +141,7 @@ Currently, the following filters have been implemented:
140
141
  * [terms filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html)
141
142
  * [nested filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html)
142
143
  * [exists filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html)
144
+ * [type filter](http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-filter.html)
143
145
 
144
146
  ### Type checking and attribute coercion
145
147
 
@@ -20,6 +20,8 @@ require 'daedal/attributes/field'
20
20
  require 'daedal/attributes/query_value'
21
21
  require 'daedal/attributes/boost'
22
22
  require 'daedal/attributes/score_function_array'
23
+ require 'daedal/attributes/type_value'
24
+ require 'daedal/attributes/flag'
23
25
 
24
26
  # filters
25
27
  require 'daedal/filters/exists_filter'
@@ -32,6 +34,7 @@ require 'daedal/filters/and_filter'
32
34
  require 'daedal/filters/or_filter'
33
35
  require 'daedal/filters/bool_filter'
34
36
  require 'daedal/filters/nested_filter'
37
+ require 'daedal/filters/type_filter'
35
38
 
36
39
  # queries
37
40
  require 'daedal/queries/match_all_query'
@@ -49,5 +52,6 @@ require 'daedal/queries/term_query'
49
52
  require 'daedal/queries/terms_query'
50
53
  require 'daedal/queries/range_query'
51
54
  require 'daedal/queries/function_score_query'
55
+ require 'daedal/queries/simple_query_string_query'
52
56
 
53
- # facets
57
+ # facets
@@ -0,0 +1,33 @@
1
+ module Daedal
2
+ module Attributes
3
+ """Custom coercer for the flag attribute"""
4
+ class Flag < Virtus::Attribute
5
+ ALLOWED_FLAGS = [
6
+ :all,
7
+ :none,
8
+ :and,
9
+ :or,
10
+ :not,
11
+ :prefix,
12
+ :phrase,
13
+ :precedence,
14
+ :escape,
15
+ :whitespace,
16
+ :fuzzy,
17
+ :near,
18
+ :slop
19
+ ]
20
+
21
+ def coerce(value)
22
+ unless value.nil?
23
+ value = value.to_sym
24
+ unless ALLOWED_FLAGS.include? value
25
+ raise Virtus::CoercionError.new(value, 'Daedal::Attributes::Flag')
26
+ end
27
+ end
28
+ value
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,18 @@
1
+ module Daedal
2
+ module Attributes
3
+ """Custom coercer for the value of a type - can be a string or a symbol. If
4
+ it's none of those, raises a coercion error."""
5
+ class TypeValue < Virtus::Attribute
6
+ ALLOWED_QUERY_VALUE_CLASSES = [String, Symbol]
7
+ def coerce(q)
8
+ if !required? and q.nil?
9
+ return q
10
+ elsif ALLOWED_QUERY_VALUE_CLASSES.include? q.class
11
+ return q
12
+ else
13
+ raise Virtus::CoercionError.new(q, self.class)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module Daedal
2
+ module Filters
3
+ """Class for the type filter"""
4
+ class TypeFilter < Filter
5
+
6
+ # required attributes
7
+ attribute :type, Daedal::Attributes::TypeValue
8
+
9
+ def to_hash
10
+ {type: {:value => type}}
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ module Daedal
2
+ module Queries
3
+ """Class for the simple query string query"""
4
+ class SimpleQueryStringQuery < Query
5
+
6
+ # required attributes
7
+ attribute :query, String
8
+
9
+ # non required attributes
10
+ attribute :default_field, Daedal::Attributes::Field, required: false
11
+ attribute :fields, Array[Daedal::Attributes::Field], required: false
12
+ attribute :default_operator, String, required: false
13
+ attribute :analyzer, Symbol, required: false
14
+ attribute :lowercase_expanded_terms, Boolean, required: false
15
+ attribute :minimum_should_match, Integer, required: false
16
+ attribute :lenient, Boolean, required: false
17
+ attribute :flags, Array[Daedal::Attributes::Flag], required: false
18
+
19
+ def to_hash
20
+ parameters = present_attributes
21
+
22
+ if parameters[:flags]
23
+ parameters[:flags] = parameters[:flags].map(&:to_s).join('|')
24
+ end
25
+
26
+ { simple_query_string: parameters }
27
+ end
28
+
29
+ private
30
+
31
+ def present_attributes
32
+ attributes.select do |parameter, value|
33
+ case parameter
34
+ when :fields, :flags
35
+ !value.empty?
36
+ else
37
+ !value.nil?
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Daedal
2
- VERSION = '0.0.16'
2
+ VERSION = '0.0.17'
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Attributes::Flag do
4
+ class Whatever
5
+ include Virtus.model
6
+
7
+ attribute :flag, Daedal::Attributes::Flag
8
+ end
9
+
10
+ describe '#coerce' do
11
+ it 'coerces a coercible value' do
12
+ model = Whatever.new(flag: 'prefix')
13
+
14
+ expect(model.flag).to eq :prefix
15
+ end
16
+
17
+ it 'raises a coercion error if flag is not allowed' do
18
+ expect do
19
+ Whatever.new(flag: 'asdasdasdsa')
20
+ end.to raise_error Virtus::CoercionError
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Filters::TypeFilter do
4
+
5
+ subject do
6
+ Daedal::Filters::TypeFilter
7
+ end
8
+
9
+ let(:type) do
10
+ :bar
11
+ end
12
+
13
+ let(:hash_filter) do
14
+ {type: {:value => type}}
15
+ end
16
+
17
+ context 'without a type specified' do
18
+ it 'will raise an error' do
19
+ expect {subject.new}.to raise_error(Virtus::CoercionError)
20
+ end
21
+ end
22
+
23
+ context 'with a type specified' do
24
+ let(:filter) do
25
+ subject.new(type: type)
26
+ end
27
+ it 'will populate the type attribute appropriately' do
28
+ expect(filter.type).to eq type
29
+ end
30
+ it 'will have the correct hash representation' do
31
+ expect(filter.to_hash).to eq hash_filter
32
+ end
33
+ it 'will have the correct json representation' do
34
+ expect(filter.to_json).to eq hash_filter.to_json
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,168 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Queries::SimpleQueryStringQuery do
4
+
5
+ subject do
6
+ Daedal::Queries::SimpleQueryStringQuery
7
+ end
8
+
9
+ let(:hash_query) do
10
+ {simple_query_string: {query: 'foo'}}
11
+ end
12
+
13
+ context 'without a query string' do
14
+ it 'will raise an error' do
15
+ expect{subject.new}.to raise_error(Virtus::CoercionError)
16
+ end
17
+ end
18
+
19
+ context 'with a query that is not a string given' do
20
+ let(:query) do
21
+ subject.new query: :foo
22
+ end
23
+ it 'will convert to a string' do
24
+ expect(query.query).to eq 'foo'
25
+ end
26
+ end
27
+
28
+ context 'with a query' do
29
+ let(:query) do
30
+ subject.new query: 'foo'
31
+ end
32
+ it 'will create a query string with the correct value' do
33
+ expect(query.query).to eq 'foo'
34
+ end
35
+ it 'will have the correct hash and json representation' do
36
+ expect(query.to_hash).to eq hash_query
37
+ expect(query.to_json).to eq hash_query.to_json
38
+ end
39
+ end
40
+
41
+ context 'with a default_field' do
42
+ let(:query) do
43
+ subject.new query: 'foo', default_field: :bar
44
+ end
45
+ before do
46
+ hash_query[:simple_query_string][:default_field] = :bar
47
+ end
48
+ it 'will set the default_field' do
49
+ expect(query.default_field).to eq :bar
50
+ end
51
+ it 'will have the correct hash and json representations' do
52
+ expect(query.to_hash).to eq hash_query
53
+ expect(query.to_json).to eq hash_query.to_json
54
+ end
55
+ end
56
+
57
+ context 'with an array of fields' do
58
+ let(:query) do
59
+ subject.new query: 'foo', fields: [:bar]
60
+ end
61
+ before do
62
+ hash_query[:simple_query_string][:fields] = [:bar]
63
+ end
64
+ it 'will set the fields' do
65
+ expect(query.fields).to eq [:bar]
66
+ end
67
+ it 'will have the correct hash and json representations' do
68
+ expect(query.to_hash).to eq hash_query
69
+ expect(query.to_json).to eq hash_query.to_json
70
+ end
71
+ end
72
+
73
+ context 'with a default_operator' do
74
+ let(:query) do
75
+ subject.new query: 'foo', default_operator: 'OR'
76
+ end
77
+ before do
78
+ hash_query[:simple_query_string][:default_operator] = 'OR'
79
+ end
80
+ it 'will set the default_operator' do
81
+ expect(query.default_operator).to eq 'OR'
82
+ end
83
+ it 'will have the correct hash and json representations' do
84
+ expect(query.to_hash).to eq hash_query
85
+ expect(query.to_json).to eq hash_query.to_json
86
+ end
87
+ end
88
+
89
+ context 'with an analyzer' do
90
+ let(:query) do
91
+ subject.new query: 'foo', analyzer: :bar
92
+ end
93
+ before do
94
+ hash_query[:simple_query_string][:analyzer] = :bar
95
+ end
96
+ it 'will set the analyzer' do
97
+ expect(query.analyzer).to eq :bar
98
+ end
99
+ it 'will have the correct hash and json representations' do
100
+ expect(query.to_hash).to eq hash_query
101
+ expect(query.to_json).to eq hash_query.to_json
102
+ end
103
+ end
104
+
105
+ context 'with flags' do
106
+ let(:query) do
107
+ subject.new query: 'foo', flags: [:or, :and, :prefix]
108
+ end
109
+ before do
110
+ hash_query[:simple_query_string][:flags] = 'or|and|prefix'
111
+ end
112
+ it 'will set the flags' do
113
+ expect(query.flags).to eq [:or, :and, :prefix]
114
+ end
115
+ it 'will have the correct hash and json representations' do
116
+ expect(query.to_hash).to eq hash_query
117
+ expect(query.to_json).to eq hash_query.to_json
118
+ end
119
+ end
120
+
121
+ context 'with a lowercase_expanded_terms' do
122
+ let(:query) do
123
+ subject.new query: 'foo', lowercase_expanded_terms: true
124
+ end
125
+ before do
126
+ hash_query[:simple_query_string][:lowercase_expanded_terms] = true
127
+ end
128
+ it 'will set the lowercase_expanded_terms' do
129
+ expect(query.lowercase_expanded_terms).to eq true
130
+ end
131
+ it 'will have the correct hash and json representations' do
132
+ expect(query.to_hash).to eq hash_query
133
+ expect(query.to_json).to eq hash_query.to_json
134
+ end
135
+ end
136
+
137
+ context 'with a minimum_should_match' do
138
+ let(:query) do
139
+ subject.new query: 'foo', minimum_should_match: 2
140
+ end
141
+ before do
142
+ hash_query[:simple_query_string][:minimum_should_match] = 2
143
+ end
144
+ it 'will set the minimum_should_match' do
145
+ expect(query.minimum_should_match).to eq 2
146
+ end
147
+ it 'will have the correct hash and json representations' do
148
+ expect(query.to_hash).to eq hash_query
149
+ expect(query.to_json).to eq hash_query.to_json
150
+ end
151
+ end
152
+
153
+ context 'with a lenient' do
154
+ let(:query) do
155
+ subject.new query: 'foo', lenient: true
156
+ end
157
+ before do
158
+ hash_query[:simple_query_string][:lenient] = true
159
+ end
160
+ it 'will set the lenient' do
161
+ expect(query.lenient).to eq true
162
+ end
163
+ it 'will have the correct hash and json representations' do
164
+ expect(query.to_hash).to eq hash_query
165
+ expect(query.to_json).to eq hash_query.to_json
166
+ end
167
+ end
168
+ 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.16
4
+ version: 0.0.17
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-04-15 00:00:00.000000000 Z
11
+ date: 2015-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -46,6 +46,7 @@ files:
46
46
  - lib/daedal/attributes/field.rb
47
47
  - lib/daedal/attributes/filter.rb
48
48
  - lib/daedal/attributes/filter_array.rb
49
+ - lib/daedal/attributes/flag.rb
49
50
  - lib/daedal/attributes/lower_case_string.rb
50
51
  - lib/daedal/attributes/match_type.rb
51
52
  - lib/daedal/attributes/operator.rb
@@ -54,6 +55,7 @@ files:
54
55
  - lib/daedal/attributes/query_value.rb
55
56
  - lib/daedal/attributes/score_function_array.rb
56
57
  - lib/daedal/attributes/score_mode.rb
58
+ - lib/daedal/attributes/type_value.rb
57
59
  - lib/daedal/facets/facet.rb
58
60
  - lib/daedal/filters/and_filter.rb
59
61
  - lib/daedal/filters/bool_filter.rb
@@ -66,6 +68,7 @@ files:
66
68
  - lib/daedal/filters/range_filter.rb
67
69
  - lib/daedal/filters/term_filter.rb
68
70
  - lib/daedal/filters/terms_filter.rb
71
+ - lib/daedal/filters/type_filter.rb
69
72
  - lib/daedal/queries/bool_query.rb
70
73
  - lib/daedal/queries/constant_score_query.rb
71
74
  - lib/daedal/queries/dis_max_query.rb
@@ -80,10 +83,12 @@ files:
80
83
  - lib/daedal/queries/query.rb
81
84
  - lib/daedal/queries/query_string_query.rb
82
85
  - lib/daedal/queries/range_query.rb
86
+ - lib/daedal/queries/simple_query_string_query.rb
83
87
  - lib/daedal/queries/term_query.rb
84
88
  - lib/daedal/queries/terms_query.rb
85
89
  - lib/daedal/version.rb
86
90
  - spec/spec_helper.rb
91
+ - spec/unit/daedal/attributes/flag_spec.rb
87
92
  - spec/unit/daedal/filters/and_filter_spec.rb
88
93
  - spec/unit/daedal/filters/bool_filter_spec.rb
89
94
  - spec/unit/daedal/filters/exists_filter_spec.rb
@@ -94,6 +99,7 @@ files:
94
99
  - spec/unit/daedal/filters/range_filter_spec.rb
95
100
  - spec/unit/daedal/filters/term_filter_spec.rb
96
101
  - spec/unit/daedal/filters/terms_filter_spec.rb
102
+ - spec/unit/daedal/filters/type_filter_spec.rb
97
103
  - spec/unit/daedal/queries/bool_query_spec.rb
98
104
  - spec/unit/daedal/queries/constant_score_query_spec.rb
99
105
  - spec/unit/daedal/queries/dis_max_query_spec.rb
@@ -107,6 +113,7 @@ files:
107
113
  - spec/unit/daedal/queries/prefix_query_spec.rb
108
114
  - spec/unit/daedal/queries/query_string_spec.rb
109
115
  - spec/unit/daedal/queries/range_query_spec.rb
116
+ - spec/unit/daedal/queries/simple_query_string_spec.rb
110
117
  - spec/unit/daedal/queries/term_query_spec.rb
111
118
  - spec/unit/daedal/queries/terms_query_spec.rb
112
119
  homepage: https://github.com/cschuch/daedal