daedal-sl 0.0.0 → 0.0.1

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: ce4181876f3602d4ab2600db1faeb19888385b3d
4
- data.tar.gz: 3273091061f48352851334a89c4a28d2aac69ba0
3
+ metadata.gz: f26d4a2e191d62a43e1b00016e65d533e7b2dfb0
4
+ data.tar.gz: 97176f5bfd0afb0b991deaeb5532c4fb34579e5c
5
5
  SHA512:
6
- metadata.gz: 3e5d2db067987c89929ae15d01e6341367c1a63bdeb563b3b228a888cc401b0e84c151eaad3f158a05dab589df8a7c50ce9db7775209b12cacb744c9e55fb855
7
- data.tar.gz: 7074427eda68059d5e6e8d9ecd91bde69542797a7f17d5ebad9b76d38ad652d935fcfcac6a247794580a22d0b6a422400fac0d8444558d209f32d517c869afe2
6
+ metadata.gz: 17da84c79606730755ae04e7e3098e3089516a3221c07314610a1901afa3b706bb8d78b98f1627125d9a852244d949ab541a3d948324352325e9ab1c1a47a859
7
+ data.tar.gz: 38369049a33a9d04f7d8777bda25e18d53b4cb87e9f12656cfc997db2e6e0aec7e0309192079ab4843a49c3bdfdf31f3e11f653e3db88b5496c5b74900225e5d
data/.gitignore CHANGED
@@ -5,4 +5,5 @@
5
5
  # git config --global core.excludesfile '~/.gitignore_global'
6
6
 
7
7
  # Ignore gem builds
8
- *.gem
8
+ *.gem
9
+ /tmp
data/.rspec CHANGED
@@ -1,3 +1 @@
1
- --profile
2
- --color
3
- --format Fuubar
1
+ --color
data/Gemfile CHANGED
@@ -6,5 +6,5 @@ group :development, :test do
6
6
  gem 'rspec'
7
7
  gem 'guard'
8
8
  gem 'guard-rspec'
9
- gem 'fuubar'
9
+ gem 'hashie'
10
10
  end
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elasticsearch-query-dsl (0.0.0)
5
- daedal (~> 0.0.12)
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
- elasticsearch-query-dsl!
81
- fuubar
77
+ daedal-sl!
82
78
  guard
83
79
  guard-rspec
80
+ hashie
84
81
  rspec
data/Guardfile CHANGED
@@ -1,4 +1,5 @@
1
1
  guard :rspec do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/acceptance/#{m[1]}_spec.rb" }
4
5
  end
data/README.md CHANGED
@@ -1,7 +1,242 @@
1
1
  DaedalSL
2
2
  =======================
3
+ [![Gem Version](https://badge.fury.io/rb/daedal-sl.svg)](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
  -------
@@ -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 = '0.0.0'
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"]
@@ -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,16 @@
1
+ module DaedalSL
2
+ class AndFilter < BlockQuery
3
+
4
+ def initialize(parent, options)
5
+ @query_type = Daedal::Filters::AndFilter
6
+ super
7
+ end
8
+
9
+ def filter
10
+ if (result = yield)
11
+ @base.filters << result
12
+ end
13
+ end
14
+
15
+ end
16
+ 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