daedal-sl 0.0.0 → 0.0.1
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/.gitignore +2 -1
- data/.rspec +1 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +5 -8
- data/Guardfile +1 -0
- data/README.md +236 -1
- data/daedal-sl.gemspec +3 -1
- data/lib/daedal-sl.rb +26 -0
- data/lib/daedal-sl/and_filter.rb +16 -0
- data/lib/daedal-sl/block_query.rb +26 -0
- data/lib/daedal-sl/bool_filter.rb +28 -0
- data/lib/daedal-sl/bool_query.rb +28 -0
- data/lib/daedal-sl/builder.rb +58 -0
- data/lib/daedal-sl/dis_max_query.rb +16 -0
- data/lib/daedal-sl/nested_bool_filter.rb +28 -0
- data/lib/daedal-sl/nested_bool_query.rb +28 -0
- data/lib/daedal-sl/nested_dis_max_query.rb +16 -0
- data/lib/daedal-sl/or_filter.rb +16 -0
- data/lib/daedal-sl/query_helpers.rb +91 -0
- data/lib/daedal-sl/version.rb +3 -0
- data/spec/acceptance/daedal-sl_spec.rb +201 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/unit/daedal-sl/and_filter_spec.rb +20 -0
- data/spec/unit/daedal-sl/block_query_spec.rb +43 -0
- data/spec/unit/daedal-sl/bool_filter_spec.rb +34 -0
- data/spec/unit/daedal-sl/bool_query_spec.rb +34 -0
- data/spec/unit/daedal-sl/builder_spec.rb +95 -0
- data/spec/unit/daedal-sl/dis_max_query_spec.rb +20 -0
- data/spec/unit/daedal-sl/nested_bool_filter_spec.rb +34 -0
- data/spec/unit/daedal-sl/nested_bool_query_spec.rb +34 -0
- data/spec/unit/daedal-sl/nested_dis_max_query_spec.rb +20 -0
- data/spec/unit/daedal-sl/or_filter_spec.rb +20 -0
- data/spec/unit/daedal-sl/query_helpers_spec.rb +219 -0
- data/spec/unit/daedal-sl_spec.rb +17 -0
- metadata +29 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f26d4a2e191d62a43e1b00016e65d533e7b2dfb0
|
4
|
+
data.tar.gz: 97176f5bfd0afb0b991deaeb5532c4fb34579e5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17da84c79606730755ae04e7e3098e3089516a3221c07314610a1901afa3b706bb8d78b98f1627125d9a852244d949ab541a3d948324352325e9ab1c1a47a859
|
7
|
+
data.tar.gz: 38369049a33a9d04f7d8777bda25e18d53b4cb87e9f12656cfc997db2e6e0aec7e0309192079ab4843a49c3bdfdf31f3e11f653e3db88b5496c5b74900225e5d
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
5
|
-
daedal (
|
4
|
+
daedal-sl (0.0.0)
|
5
|
+
daedal (>= 0.0.12)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -24,9 +24,6 @@ GEM
|
|
24
24
|
equalizer (0.0.9)
|
25
25
|
ffi (1.9.3)
|
26
26
|
formatador (0.2.5)
|
27
|
-
fuubar (1.3.3)
|
28
|
-
rspec (>= 2.14.0, < 3.1.0)
|
29
|
-
ruby-progressbar (~> 1.4)
|
30
27
|
guard (2.6.1)
|
31
28
|
formatador (>= 0.2.4)
|
32
29
|
listen (~> 2.7)
|
@@ -36,6 +33,7 @@ GEM
|
|
36
33
|
guard-rspec (4.2.10)
|
37
34
|
guard (~> 2.1)
|
38
35
|
rspec (>= 2.14, < 4.0)
|
36
|
+
hashie (1.2.0)
|
39
37
|
ice_nine (0.11.0)
|
40
38
|
listen (2.7.9)
|
41
39
|
celluloid (>= 0.15.2)
|
@@ -62,7 +60,6 @@ GEM
|
|
62
60
|
rspec-mocks (3.0.2)
|
63
61
|
rspec-support (~> 3.0.0)
|
64
62
|
rspec-support (3.0.1)
|
65
|
-
ruby-progressbar (1.5.1)
|
66
63
|
slop (3.5.0)
|
67
64
|
thor (0.19.1)
|
68
65
|
thread_safe (0.3.4)
|
@@ -77,8 +74,8 @@ PLATFORMS
|
|
77
74
|
ruby
|
78
75
|
|
79
76
|
DEPENDENCIES
|
80
|
-
|
81
|
-
fuubar
|
77
|
+
daedal-sl!
|
82
78
|
guard
|
83
79
|
guard-rspec
|
80
|
+
hashie
|
84
81
|
rspec
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,242 @@
|
|
1
1
|
DaedalSL
|
2
2
|
=======================
|
3
|
+
[](http://badge.fury.io/rb/daedal-sl)
|
3
4
|
|
4
|
-
Ruby block DSL for writing ElasticSearch queries built on Daedal
|
5
|
+
Ruby block DSL for writing ElasticSearch queries built on [Daedal](https://github.com/cschuch/daedal)
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
From the terminal:
|
11
|
+
``` terminal
|
12
|
+
$ gem install daedal-sl
|
13
|
+
```
|
14
|
+
|
15
|
+
or in your `Gemfile`:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
gem 'daedal-sl'
|
19
|
+
```
|
20
|
+
|
21
|
+
Then, it's as simple as including the line:
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
require 'daedal-sl'
|
25
|
+
```
|
26
|
+
|
27
|
+
Usage
|
28
|
+
--------
|
29
|
+
Coming soon... but here's an example. Note: Anything you pass into the optional parameter on `DaedalSL`'s `#build` method is accessible within the block via `data`.
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
some_data = Hashie::Mash.new({
|
33
|
+
foo: 'foofoo',
|
34
|
+
bar: 'barbar'
|
35
|
+
})
|
36
|
+
|
37
|
+
query = DaedalSL.build(some_data) do
|
38
|
+
query do
|
39
|
+
bool_query boost: 100 do
|
40
|
+
must do
|
41
|
+
nested_bool_query path: 'path' do
|
42
|
+
must { match field: data.foo, query: data.bar }
|
43
|
+
should { match field: data.foo, query: data.bar }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
must do
|
47
|
+
nested_dis_max_query path: 'path' do
|
48
|
+
query { match field: data.foo, query: data.bar }
|
49
|
+
query { match field: data.foo, query: data.bar }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
should { fuzzy field: data.foo, query: data.bar }
|
53
|
+
should { multi_match fields: ['field1', 'field2'], query: data.bar }
|
54
|
+
must_not { match field: data.foo, query: data.bar }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
filter do
|
58
|
+
bool_filter do
|
59
|
+
must do
|
60
|
+
nested_bool_filter path: 'path' do
|
61
|
+
must { term_filter field: data.foo, term: data.bar }
|
62
|
+
should { term_filter field: data.foo, term: data.bar }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
should do
|
66
|
+
and_filter do
|
67
|
+
filter { term_filter field: data.foo, term: data.bar }
|
68
|
+
filter { terms_filter field: data.foo, terms: ['term1', 'term2'] }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
must_not { range_filter field: data.foo, gt: 1, lt: 2 }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
fields :foo, :bar
|
75
|
+
paginate page: 1, per_page: 10
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
`query` now yields:
|
80
|
+
|
81
|
+
``` ruby
|
82
|
+
{
|
83
|
+
query: {
|
84
|
+
bool: {
|
85
|
+
should: [
|
86
|
+
{
|
87
|
+
fuzzy: {
|
88
|
+
foofoo: {
|
89
|
+
value: "barbar"
|
90
|
+
}
|
91
|
+
}
|
92
|
+
},
|
93
|
+
{
|
94
|
+
multi_match: {
|
95
|
+
query: "barbar",
|
96
|
+
fields: [:field1, :field2]
|
97
|
+
}
|
98
|
+
}
|
99
|
+
],
|
100
|
+
must: [
|
101
|
+
{
|
102
|
+
nested: {
|
103
|
+
path: :path,
|
104
|
+
query: {
|
105
|
+
bool: {
|
106
|
+
should: [
|
107
|
+
{
|
108
|
+
match: {
|
109
|
+
foofoo: {
|
110
|
+
query: "barbar"
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
],
|
115
|
+
must: [
|
116
|
+
{
|
117
|
+
match: {
|
118
|
+
foofoo: {
|
119
|
+
query: "barbar"
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
],
|
124
|
+
must_not: []
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
},
|
129
|
+
{
|
130
|
+
nested: {
|
131
|
+
path: :path,
|
132
|
+
query: {
|
133
|
+
dis_max: {
|
134
|
+
queries: [
|
135
|
+
{
|
136
|
+
match: {
|
137
|
+
foofoo: {
|
138
|
+
query: "barbar"
|
139
|
+
}
|
140
|
+
}
|
141
|
+
},
|
142
|
+
{
|
143
|
+
match: {
|
144
|
+
foofoo: {
|
145
|
+
query: "barbar"
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
]
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
],
|
155
|
+
must_not: [
|
156
|
+
{
|
157
|
+
match: {
|
158
|
+
foofoo: {
|
159
|
+
query: "barbar"
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}
|
163
|
+
],
|
164
|
+
boost: 100.0
|
165
|
+
}
|
166
|
+
},
|
167
|
+
filter: {
|
168
|
+
bool: {
|
169
|
+
should: [
|
170
|
+
{
|
171
|
+
and: [
|
172
|
+
{
|
173
|
+
term: {
|
174
|
+
foofoo: "barbar"
|
175
|
+
}
|
176
|
+
},
|
177
|
+
{
|
178
|
+
terms: {
|
179
|
+
foofoo: ["term1", "term2"]
|
180
|
+
}
|
181
|
+
}
|
182
|
+
]
|
183
|
+
}
|
184
|
+
],
|
185
|
+
must: [
|
186
|
+
{
|
187
|
+
nested: {
|
188
|
+
path: :path,
|
189
|
+
filter: {
|
190
|
+
bool: {
|
191
|
+
should: [
|
192
|
+
{
|
193
|
+
term: {
|
194
|
+
foofoo: "barbar"
|
195
|
+
}
|
196
|
+
}
|
197
|
+
],
|
198
|
+
must: [
|
199
|
+
{
|
200
|
+
term: {
|
201
|
+
foofoo: "barbar"
|
202
|
+
}
|
203
|
+
}
|
204
|
+
],
|
205
|
+
must_not: []
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
}
|
210
|
+
],
|
211
|
+
must_not: [
|
212
|
+
{
|
213
|
+
range: {
|
214
|
+
foofoo: {
|
215
|
+
lt: 2,
|
216
|
+
gt: 1
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
]
|
221
|
+
}
|
222
|
+
},
|
223
|
+
fields: [:foo, :bar],
|
224
|
+
:from=>0,
|
225
|
+
:size=>10
|
226
|
+
}
|
227
|
+
```
|
228
|
+
|
229
|
+
Contributing
|
230
|
+
-------------
|
231
|
+
|
232
|
+
Feel free to contribute! We just ask that you:
|
233
|
+
|
234
|
+
* Fork the project
|
235
|
+
* Make your changes or additions
|
236
|
+
* Add tests! Our goal is to keep DaedalSL a thoroughly tested project
|
237
|
+
* Send a pull request
|
238
|
+
|
239
|
+
Feedback or suggestions are also always welcome!
|
5
240
|
|
6
241
|
License
|
7
242
|
-------
|
data/daedal-sl.gemspec
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require File.expand_path('../lib/daedal-sl/version', __FILE__)
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.name = 'daedal-sl'
|
3
|
-
s.version =
|
5
|
+
s.version = DaedalSL::VERSION
|
4
6
|
s.summary = "Ruby block DSL for writing ElasticSearch queries"
|
5
7
|
s.description = "Ruby block DSL for writing ElasticSearch queries"
|
6
8
|
s.authors = ["Christopher Schuch"]
|
data/lib/daedal-sl.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'daedal'
|
2
|
+
|
3
|
+
require 'daedal-sl/version'
|
4
|
+
require 'daedal-sl/block_query'
|
5
|
+
require 'daedal-sl/bool_query'
|
6
|
+
require 'daedal-sl/dis_max_query'
|
7
|
+
require 'daedal-sl/bool_filter'
|
8
|
+
require 'daedal-sl/nested_bool_query'
|
9
|
+
require 'daedal-sl/nested_bool_filter'
|
10
|
+
require 'daedal-sl/nested_dis_max_query'
|
11
|
+
require 'daedal-sl/and_filter'
|
12
|
+
require 'daedal-sl/or_filter'
|
13
|
+
require 'daedal-sl/query_helpers'
|
14
|
+
require 'daedal-sl/builder'
|
15
|
+
|
16
|
+
module DaedalSL
|
17
|
+
class << self
|
18
|
+
def build(data=nil, &block)
|
19
|
+
result = DaedalSL::Builder.new(data)
|
20
|
+
if block
|
21
|
+
result.instance_eval(&block)
|
22
|
+
end
|
23
|
+
result.to_hash
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module DaedalSL
|
2
|
+
class BlockQuery
|
3
|
+
attr_reader :parent
|
4
|
+
attr_reader :base
|
5
|
+
|
6
|
+
def initialize(parent, options)
|
7
|
+
@parent = parent
|
8
|
+
@base = @query_type.new(options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(method, *args, &block)
|
12
|
+
@parent.send(method, *args, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def build(parent, options, &block)
|
17
|
+
result = new(parent, options)
|
18
|
+
if block
|
19
|
+
result.instance_eval(&block)
|
20
|
+
end
|
21
|
+
result.base
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module DaedalSL
|
2
|
+
class BoolFilter < BlockQuery
|
3
|
+
|
4
|
+
def initialize(parent, options)
|
5
|
+
@query_type = Daedal::Filters::BoolFilter
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def must
|
10
|
+
if (result = yield)
|
11
|
+
@base.must << result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def should
|
16
|
+
if (result = yield)
|
17
|
+
@base.should << result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def must_not
|
22
|
+
if (result = yield)
|
23
|
+
@base.must_not << result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module DaedalSL
|
2
|
+
class BoolQuery < BlockQuery
|
3
|
+
|
4
|
+
def initialize(parent, options)
|
5
|
+
@query_type = Daedal::Queries::BoolQuery
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def must
|
10
|
+
if (result = yield)
|
11
|
+
@base.must << result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def should
|
16
|
+
if (result = yield)
|
17
|
+
@base.should << result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def must_not
|
22
|
+
if (result = yield)
|
23
|
+
@base.must_not << result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|