stretchy 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +260 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +12 -0
- data/Dockerfile +8 -0
- data/docker-compose.yml +13 -0
- data/lib/stretchy/and_collector.rb +22 -122
- data/lib/stretchy/api.rb +7 -29
- data/lib/stretchy/factory.rb +10 -19
- data/lib/stretchy/utils.rb +3 -1
- data/lib/stretchy/version.rb +1 -1
- data/solano.yml +3 -3
- data/stretchy.gemspec +1 -2
- metadata +9 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e36573d3774c867031bf443889b538d83cd97976
|
4
|
+
data.tar.gz: 90490ce53bb095a4d160b25dc4db38bca87ea92f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adcd1104eae7977fd773e29bfbaa1e28f56e5c79408c7c3b3d68533ed8afd7e53b9d12f8f12acbba2a33a27b8b9d97bdc32aebcb0a5ac004013fb084dfa4b51d
|
7
|
+
data.tar.gz: 6bc2768805817f20749aa6eb2f8ef615cc71b1b87a8ae5b3eca4cc5d85e2f08b702a4793bd1e5f11bc7cb1bc9c450f4c60af054ac23b4e300195dd153d62e25d
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-12-09 14:43:24 -0800 using RuboCop version 0.32.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 1
|
9
|
+
# Cop supports --auto-correct.
|
10
|
+
Lint/BlockAlignment:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
# Offense count: 3
|
14
|
+
# Cop supports --auto-correct.
|
15
|
+
# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
|
16
|
+
Lint/EndAlignment:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
# Offense count: 1
|
20
|
+
Lint/HandleExceptions:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
# Offense count: 3
|
24
|
+
# Cop supports --auto-correct.
|
25
|
+
Lint/UnusedBlockArgument:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
# Offense count: 2
|
29
|
+
Lint/UselessAssignment:
|
30
|
+
Enabled: true
|
31
|
+
|
32
|
+
# Offense count: 5
|
33
|
+
Metrics/AbcSize:
|
34
|
+
Max: 15
|
35
|
+
|
36
|
+
# Offense count: 2
|
37
|
+
# Configuration parameters: CountComments.
|
38
|
+
Metrics/ClassLength:
|
39
|
+
Max: 250
|
40
|
+
|
41
|
+
# Offense count: 1
|
42
|
+
Metrics/CyclomaticComplexity:
|
43
|
+
Max: 7
|
44
|
+
|
45
|
+
# Offense count: 3
|
46
|
+
# Configuration parameters: AllowURI, URISchemes.
|
47
|
+
Metrics/LineLength:
|
48
|
+
Max: 80
|
49
|
+
|
50
|
+
# Offense count: 8
|
51
|
+
# Configuration parameters: CountComments.
|
52
|
+
Metrics/MethodLength:
|
53
|
+
Max: 20
|
54
|
+
|
55
|
+
# Offense count: 2
|
56
|
+
# Configuration parameters: CountComments.
|
57
|
+
Metrics/ModuleLength:
|
58
|
+
Max: 250
|
59
|
+
|
60
|
+
# Offense count: 14
|
61
|
+
# Cop supports --auto-correct.
|
62
|
+
Style/Alias:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
# Offense count: 1
|
66
|
+
# Cop supports --auto-correct.
|
67
|
+
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
68
|
+
Style/AlignHash:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
# Offense count: 7
|
72
|
+
# Cop supports --auto-correct.
|
73
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
74
|
+
Style/BlockDelimiters:
|
75
|
+
Enabled: false
|
76
|
+
|
77
|
+
# Offense count: 3
|
78
|
+
# Cop supports --auto-correct.
|
79
|
+
Style/BlockEndNewline:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
# Offense count: 3
|
83
|
+
# Cop supports --auto-correct.
|
84
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
85
|
+
Style/BracesAroundHashParameters:
|
86
|
+
Enabled: false
|
87
|
+
|
88
|
+
# Offense count: 1
|
89
|
+
# Cop supports --auto-correct.
|
90
|
+
Style/ClosingParenthesisIndentation:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
# Offense count: 18
|
94
|
+
Style/Documentation:
|
95
|
+
Enabled: false
|
96
|
+
|
97
|
+
# Offense count: 3
|
98
|
+
Style/DoubleNegation:
|
99
|
+
Enabled: false
|
100
|
+
|
101
|
+
# Offense count: 5
|
102
|
+
# Cop supports --auto-correct.
|
103
|
+
Style/ElseAlignment:
|
104
|
+
Enabled: false
|
105
|
+
|
106
|
+
# Offense count: 16
|
107
|
+
# Cop supports --auto-correct.
|
108
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
109
|
+
Style/EmptyLinesAroundBlockBody:
|
110
|
+
Enabled: false
|
111
|
+
|
112
|
+
# Offense count: 6
|
113
|
+
# Cop supports --auto-correct.
|
114
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
115
|
+
Style/EmptyLinesAroundClassBody:
|
116
|
+
Enabled: false
|
117
|
+
|
118
|
+
# Offense count: 6
|
119
|
+
# Cop supports --auto-correct.
|
120
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
121
|
+
Style/EmptyLinesAroundModuleBody:
|
122
|
+
Enabled: false
|
123
|
+
|
124
|
+
# Offense count: 4
|
125
|
+
# Cop supports --auto-correct.
|
126
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
127
|
+
Style/FirstParameterIndentation:
|
128
|
+
Enabled: false
|
129
|
+
|
130
|
+
# Offense count: 1
|
131
|
+
# Cop supports --auto-correct.
|
132
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
|
133
|
+
Style/HashSyntax:
|
134
|
+
Enabled: false
|
135
|
+
|
136
|
+
# Offense count: 16
|
137
|
+
# Cop supports --auto-correct.
|
138
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
139
|
+
Style/IndentHash:
|
140
|
+
Enabled: false
|
141
|
+
|
142
|
+
# Offense count: 18
|
143
|
+
# Cop supports --auto-correct.
|
144
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
145
|
+
Style/IndentationConsistency:
|
146
|
+
Enabled: false
|
147
|
+
|
148
|
+
# Offense count: 3
|
149
|
+
# Cop supports --auto-correct.
|
150
|
+
# Configuration parameters: Width.
|
151
|
+
Style/IndentationWidth:
|
152
|
+
Enabled: false
|
153
|
+
|
154
|
+
# Offense count: 1
|
155
|
+
# Cop supports --auto-correct.
|
156
|
+
Style/LineEndConcatenation:
|
157
|
+
Enabled: false
|
158
|
+
|
159
|
+
# Offense count: 3
|
160
|
+
# Cop supports --auto-correct.
|
161
|
+
Style/MultilineBlockLayout:
|
162
|
+
Enabled: false
|
163
|
+
|
164
|
+
# Offense count: 10
|
165
|
+
# Cop supports --auto-correct.
|
166
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
167
|
+
Style/MultilineOperationIndentation:
|
168
|
+
Enabled: false
|
169
|
+
|
170
|
+
# Offense count: 2
|
171
|
+
# Cop supports --auto-correct.
|
172
|
+
# Configuration parameters: PreferredDelimiters.
|
173
|
+
Style/PercentLiteralDelimiters:
|
174
|
+
Enabled: false
|
175
|
+
|
176
|
+
# Offense count: 1
|
177
|
+
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
|
178
|
+
Style/PredicateName:
|
179
|
+
Enabled: false
|
180
|
+
|
181
|
+
# Offense count: 3
|
182
|
+
# Configuration parameters: SupportedStyles.
|
183
|
+
Style/RaiseArgs:
|
184
|
+
EnforcedStyle: compact
|
185
|
+
|
186
|
+
# Offense count: 1
|
187
|
+
# Cop supports --auto-correct.
|
188
|
+
Style/RedundantSelf:
|
189
|
+
Enabled: false
|
190
|
+
|
191
|
+
# Offense count: 4
|
192
|
+
# Cop supports --auto-correct.
|
193
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
194
|
+
Style/SignalException:
|
195
|
+
Enabled: false
|
196
|
+
|
197
|
+
# Offense count: 4
|
198
|
+
# Cop supports --auto-correct.
|
199
|
+
Style/SingleSpaceBeforeFirstArg:
|
200
|
+
Enabled: false
|
201
|
+
|
202
|
+
# Offense count: 9
|
203
|
+
# Cop supports --auto-correct.
|
204
|
+
Style/SpaceAfterComma:
|
205
|
+
Enabled: false
|
206
|
+
|
207
|
+
# Offense count: 6
|
208
|
+
# Cop supports --auto-correct.
|
209
|
+
# Configuration parameters: MultiSpaceAllowedForOperators.
|
210
|
+
Style/SpaceAroundOperators:
|
211
|
+
Enabled: false
|
212
|
+
|
213
|
+
# Offense count: 5
|
214
|
+
# Cop supports --auto-correct.
|
215
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
216
|
+
Style/SpaceBeforeBlockBraces:
|
217
|
+
Enabled: false
|
218
|
+
|
219
|
+
# Offense count: 1
|
220
|
+
# Cop supports --auto-correct.
|
221
|
+
Style/SpaceBeforeSemicolon:
|
222
|
+
Enabled: false
|
223
|
+
|
224
|
+
# Offense count: 25
|
225
|
+
# Cop supports --auto-correct.
|
226
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
227
|
+
Style/SpaceInsideBlockBraces:
|
228
|
+
Enabled: false
|
229
|
+
|
230
|
+
# Offense count: 145
|
231
|
+
# Cop supports --auto-correct.
|
232
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
233
|
+
Style/SpaceInsideHashLiteralBraces:
|
234
|
+
Enabled: false
|
235
|
+
|
236
|
+
# Offense count: 33
|
237
|
+
# Cop supports --auto-correct.
|
238
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
239
|
+
Style/StringLiterals:
|
240
|
+
Enabled: false
|
241
|
+
|
242
|
+
# Offense count: 1
|
243
|
+
# Cop supports --auto-correct.
|
244
|
+
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
|
245
|
+
Style/TrivialAccessors:
|
246
|
+
Enabled: false
|
247
|
+
|
248
|
+
# Offense count: 2
|
249
|
+
# Cop supports --auto-correct.
|
250
|
+
Style/UnneededPercentQ:
|
251
|
+
Enabled: false
|
252
|
+
|
253
|
+
# Align with the style guide.
|
254
|
+
Style/CollectionMethods:
|
255
|
+
PreferredMethods:
|
256
|
+
collect: 'map'
|
257
|
+
collect!: 'map!'
|
258
|
+
inject: 'reduce'
|
259
|
+
detect: 'find'
|
260
|
+
find_all: 'select'
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.3
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/), although
|
4
|
+
"minor" (0.x) changes will include breaking changes until a stable 1.0 release.
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
|
8
|
+
## [0.6.0] - 2015-12-15
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
* [FEATURE] compatible with [new query / filter contexts](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html) for Elasticsearch 2.0+
|
12
|
+
|
data/Dockerfile
ADDED
data/docker-compose.yml
ADDED
@@ -24,131 +24,54 @@ module Stretchy
|
|
24
24
|
def node
|
25
25
|
@node ||= if boost_nodes.any?
|
26
26
|
function_score_node
|
27
|
-
elsif filter_nodes.any?
|
28
|
-
filtered_query_node
|
29
27
|
elsif query_nodes.any?
|
30
|
-
|
28
|
+
query_node
|
31
29
|
else
|
32
30
|
Node.new({match_all: {}}, context)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
34
|
def query_nodes
|
37
|
-
@query_nodes ||=
|
38
|
-
n.context?(:query) &&
|
39
|
-
!n.context?(:boost) &&
|
40
|
-
!n.context?(:filter)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def filter_node
|
45
|
-
@filter_node ||= if query_nodes.any?
|
46
|
-
if boost_nodes.any?
|
47
|
-
Node.new({query: function_score_node.json}, context)
|
48
|
-
elsif filter_nodes.any?
|
49
|
-
Node.new({query: filtered_query_node.json}, context)
|
50
|
-
else
|
51
|
-
Node.new({query: single_query_node.json}, context)
|
52
|
-
end
|
53
|
-
else
|
54
|
-
Node.new(compile_nodes(filter_nodes).json, context)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def filter_json
|
59
|
-
filter_node.json
|
60
|
-
end
|
61
|
-
|
62
|
-
def filter_nodes
|
63
|
-
@filter_nodes ||= begin
|
64
|
-
node_arr = collect_nodes nodes do |n|
|
65
|
-
n.context?(:filter) &&
|
66
|
-
!n.context?(:query) &&
|
67
|
-
!n.context?(:boost)
|
68
|
-
end
|
69
|
-
node_arr += Array(compile_query_filter_node)
|
70
|
-
node_arr.compact
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def query_filter_nodes
|
75
|
-
@query_filter_nodes ||= collect_nodes nodes do |n|
|
76
|
-
n.context?(:filter) &&
|
77
|
-
n.context?(:query) &&
|
78
|
-
!n.context?(:boost)
|
79
|
-
end
|
35
|
+
@query_nodes ||= nodes.reject {|n| n.context? :boost }
|
80
36
|
end
|
81
37
|
|
82
38
|
def boost_nodes
|
83
|
-
@boost_nodes ||=
|
84
|
-
n.context?(:boost)
|
85
|
-
end
|
39
|
+
@boost_nodes ||= nodes.select {|n| n.context? :boost }
|
86
40
|
end
|
87
41
|
|
88
42
|
private
|
89
43
|
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
if n.respond_to? :node
|
96
|
-
coll << Node.new(n.node.json, n.context)
|
97
|
-
else
|
98
|
-
coll << n
|
99
|
-
end
|
44
|
+
def query_node
|
45
|
+
if query_nodes.size > 1 || multicontext?(query_nodes)
|
46
|
+
compile_bool query_nodes
|
47
|
+
else
|
48
|
+
query_nodes.first
|
100
49
|
end
|
101
|
-
coll.compact
|
102
50
|
end
|
103
51
|
|
104
|
-
def
|
105
|
-
|
106
|
-
node_arr.any?{|n| n.context?(:must_not) || n.context?(:should)}
|
107
|
-
|
108
|
-
compile_bool(node_arr)
|
109
|
-
else
|
110
|
-
node_arr.first
|
111
|
-
end
|
52
|
+
def multicontext?(node_arr)
|
53
|
+
Array(node_arr).any? {|n| n.context?(:must_not) || n.context?(:should) }
|
112
54
|
end
|
113
55
|
|
114
56
|
def compile_bool(bool_nodes)
|
115
57
|
split_nodes = split_nodes_for_bool(bool_nodes)
|
116
|
-
|
117
|
-
|
118
|
-
bool_json[:should] = [
|
119
|
-
{
|
120
|
-
bool: {
|
121
|
-
must: split_nodes[:should].map(&:as_json),
|
122
|
-
must_not: split_nodes[:should_not].map(&:as_json)
|
123
|
-
}
|
124
|
-
}
|
125
|
-
]
|
126
|
-
else
|
127
|
-
bool_json[:should] = split_nodes[:should].map(&:as_json)
|
58
|
+
refined = bool_ctx.each_with_object(split_nodes) do |k, hash|
|
59
|
+
hash[k] = Array(compile_bool(hash[k])) if multicontext? hash[k]
|
128
60
|
end
|
129
|
-
bool_json
|
130
|
-
bool_json[:must] = split_nodes[:must].map(&:as_json)
|
61
|
+
bool_json = Hash[refined.map{|k,v| [k, v.map(&:as_json)] }]
|
131
62
|
Node.new(bool: bool_json)
|
132
63
|
end
|
133
64
|
|
65
|
+
def bool_ctx
|
66
|
+
[:filter, :must_not, :should]
|
67
|
+
end
|
68
|
+
|
134
69
|
def split_nodes_for_bool(bool_nodes)
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
split_nodes[:should_not] << n
|
140
|
-
else
|
141
|
-
split_nodes[:should] << n
|
142
|
-
end
|
143
|
-
else
|
144
|
-
if n.context?(:must_not)
|
145
|
-
split_nodes[:must_not] << n
|
146
|
-
else
|
147
|
-
split_nodes[:must] << n
|
148
|
-
end
|
149
|
-
end
|
70
|
+
bool_nodes.each_with_object({}) do |n, hash|
|
71
|
+
key = bool_ctx.find{|c| n.context? c } || :must
|
72
|
+
hash[key] ||= []
|
73
|
+
hash[key] << Node.new(n.json, n.context.merge(key => nil))
|
150
74
|
end
|
151
|
-
split_nodes
|
152
75
|
end
|
153
76
|
|
154
77
|
def compile_boost_functions
|
@@ -164,36 +87,13 @@ module Stretchy
|
|
164
87
|
end
|
165
88
|
end
|
166
89
|
|
167
|
-
def compile_query_filter_node
|
168
|
-
compiled = compile_nodes(query_filter_nodes)
|
169
|
-
Node.new(query: compiled.json) if compiled
|
170
|
-
end
|
171
|
-
|
172
90
|
def function_score_node
|
173
91
|
function_score_json = compile_function_score_options
|
174
92
|
function_score_json[:functions] = compile_boost_functions
|
175
|
-
|
176
|
-
if query_nodes.any?
|
177
|
-
function_score_json[:query] = filtered_query_node.json
|
178
|
-
elsif filter_nodes.any?
|
179
|
-
function_score_json[:filter] = filter_node.json
|
180
|
-
end
|
93
|
+
function_score_json[:query] = query_node.json if query_nodes.any?
|
181
94
|
|
182
95
|
Node.new({function_score: function_score_json}, context)
|
183
96
|
end
|
184
97
|
|
185
|
-
def filtered_query_node
|
186
|
-
filtered_json = {}
|
187
|
-
q = compile_nodes(query_nodes)
|
188
|
-
f = compile_nodes(filter_nodes)
|
189
|
-
filtered_json[:query] = q.json if q
|
190
|
-
filtered_json[:filter] = f.json if f
|
191
|
-
Node.new({filtered: filtered_json}, context)
|
192
|
-
end
|
193
|
-
|
194
|
-
def single_query_node
|
195
|
-
Node.new(compile_nodes(query_nodes).json, context)
|
196
|
-
end
|
197
|
-
|
198
98
|
end
|
199
99
|
end
|
data/lib/stretchy/api.rb
CHANGED
@@ -11,19 +11,11 @@ module Stretchy
|
|
11
11
|
|
12
12
|
attr_reader :collector, :opts, :root, :body, :context
|
13
13
|
|
14
|
+
delegate [:with_context, :json, :as_json] => :collector
|
15
|
+
|
14
16
|
delegate [
|
15
|
-
:total,
|
16
|
-
:
|
17
|
-
:length,
|
18
|
-
:size,
|
19
|
-
:total_pages,
|
20
|
-
:results,
|
21
|
-
:hits,
|
22
|
-
:to_a,
|
23
|
-
:ids,
|
24
|
-
:scores,
|
25
|
-
:explanations,
|
26
|
-
:aggregations
|
17
|
+
:total, :total_count, :length, :size, :total_pages, :results, :hits,
|
18
|
+
:to_a, :ids, :scores, :explanations, :aggregations, :each
|
27
19
|
] => :results_obj
|
28
20
|
|
29
21
|
def initialize(opts = {})
|
@@ -130,20 +122,19 @@ module Stretchy
|
|
130
122
|
end
|
131
123
|
|
132
124
|
def range(params = {})
|
133
|
-
require_context!
|
134
125
|
add_params params, nil, :range_node
|
135
126
|
end
|
136
127
|
|
137
128
|
def geo_distance(params = {})
|
138
|
-
add_params params,
|
129
|
+
add_params params, nil, :geo_distance_node
|
139
130
|
end
|
140
131
|
|
141
132
|
def boost(params = {}, options = {})
|
142
|
-
return add_context(:boost)
|
133
|
+
return add_context(:boost) if Utils.is_empty? params
|
143
134
|
|
144
135
|
subcontext = context.merge(boost: true)
|
145
136
|
if params.is_a? self.class
|
146
|
-
boost_json = options.merge(filter: params.
|
137
|
+
boost_json = options.merge(filter: params.json)
|
147
138
|
add_nodes Node.new(boost_json, subcontext)
|
148
139
|
else
|
149
140
|
add_nodes Factory.raw_boost_node(params, subcontext)
|
@@ -184,21 +175,8 @@ module Stretchy
|
|
184
175
|
results_obj.ids.count
|
185
176
|
end
|
186
177
|
|
187
|
-
def method_missing(method, *args, &block)
|
188
|
-
if collector.respond_to?(method)
|
189
|
-
collector.send(method, *args, &block)
|
190
|
-
else
|
191
|
-
super
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
178
|
private
|
196
179
|
|
197
|
-
def require_context!
|
198
|
-
return true if context?(:query) || context?(:filter)
|
199
|
-
raise 'You must specify either query or filter context'
|
200
|
-
end
|
201
|
-
|
202
180
|
def args_to_context(*args)
|
203
181
|
args.reduce({}) do |ctx, item|
|
204
182
|
next ctx if item.nil?
|
data/lib/stretchy/factory.rb
CHANGED
@@ -58,12 +58,13 @@ module Stretchy
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def context_nodes(params, context = default_context)
|
61
|
+
# binding.pry
|
61
62
|
if context[:boost]
|
62
63
|
params_to_boost(params, context)
|
63
|
-
elsif context[:query]
|
64
|
-
params_to_queries(dotify_params(params, context), context)
|
65
|
-
else
|
64
|
+
elsif context[:filter] && !context[:query]
|
66
65
|
params_to_filters(dotify_params(params, context), context)
|
66
|
+
else
|
67
|
+
params_to_queries(dotify_params(params, context), context)
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
@@ -74,14 +75,7 @@ module Stretchy
|
|
74
75
|
nodes = context_nodes(params, subcontext)
|
75
76
|
collector = AndCollector.new(nodes, subcontext)
|
76
77
|
|
77
|
-
|
78
|
-
Node.new(boost_params.merge(filter: {query: collector.json}), context)
|
79
|
-
else
|
80
|
-
Node.new(
|
81
|
-
boost_params.merge(filter: collector.filter_node.json),
|
82
|
-
context
|
83
|
-
)
|
84
|
-
end
|
78
|
+
Node.new(boost_params.merge(filter: collector.json), context)
|
85
79
|
end
|
86
80
|
|
87
81
|
def params_to_queries(params, context = default_context)
|
@@ -119,19 +113,16 @@ module Stretchy
|
|
119
113
|
end
|
120
114
|
|
121
115
|
def nested(params, path, context = default_context)
|
122
|
-
|
123
|
-
|
124
|
-
json = AndCollector.new(nodes, context).json
|
125
|
-
[:query, json]
|
116
|
+
nodes = if context[:filter] && !context[:query]
|
117
|
+
params_to_filters(params, context)
|
126
118
|
else
|
127
|
-
|
128
|
-
json = AndCollector.new(nodes, context).filter_json
|
129
|
-
[:filter, json]
|
119
|
+
params_to_queries(params, context)
|
130
120
|
end
|
121
|
+
json = AndCollector.new(nodes, context).json
|
131
122
|
|
132
123
|
Node.new({nested: {
|
133
124
|
path: path,
|
134
|
-
|
125
|
+
query: json
|
135
126
|
}}, context)
|
136
127
|
end
|
137
128
|
|
data/lib/stretchy/utils.rb
CHANGED
@@ -5,7 +5,9 @@ module Stretchy
|
|
5
5
|
# detects empty string, empty array, empty hash, nil
|
6
6
|
def is_empty?(arg = nil)
|
7
7
|
return true if arg.nil?
|
8
|
-
if arg.respond_to?(:
|
8
|
+
if arg.respond_to?(:collector)
|
9
|
+
!arg.collector.any?
|
10
|
+
elsif arg.respond_to?(:any?)
|
9
11
|
!arg.any? {|a| !is_empty?(a) }
|
10
12
|
elsif arg.respond_to?(:empty?)
|
11
13
|
arg.empty?
|
data/lib/stretchy/version.rb
CHANGED
data/solano.yml
CHANGED
data/stretchy.gemspec
CHANGED
@@ -22,8 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency "elasticsearch", "~> 1.0"
|
23
23
|
spec.add_dependency "excon", "~> 0.45"
|
24
24
|
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
27
26
|
spec.add_development_dependency "rspec", "~> 3.2"
|
28
27
|
spec.add_development_dependency "fuubar", "~> 2.0"
|
29
28
|
spec.add_development_dependency "pry", "~> 0.10"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agius
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -38,34 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.45'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.8'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.8'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '10.
|
47
|
+
version: '10.4'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '10.
|
54
|
+
version: '10.4'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rspec
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,14 +131,18 @@ extra_rdoc_files: []
|
|
145
131
|
files:
|
146
132
|
- ".editorconfig"
|
147
133
|
- ".gitignore"
|
134
|
+
- ".rubocop.yml"
|
148
135
|
- ".ruby-version"
|
149
136
|
- ".yardopts"
|
137
|
+
- CHANGELOG.md
|
150
138
|
- CONTRIBUTING.md
|
139
|
+
- Dockerfile
|
151
140
|
- Gemfile
|
152
141
|
- README.md
|
153
142
|
- Rakefile
|
154
143
|
- bin/console
|
155
144
|
- bin/setup
|
145
|
+
- docker-compose.yml
|
156
146
|
- lib/stretchy.rb
|
157
147
|
- lib/stretchy/and_collector.rb
|
158
148
|
- lib/stretchy/api.rb
|
@@ -185,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
175
|
version: '0'
|
186
176
|
requirements: []
|
187
177
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.4.5
|
178
|
+
rubygems_version: 2.4.5.1
|
189
179
|
signing_key:
|
190
180
|
specification_version: 4
|
191
181
|
summary: Query builder for Elasticsearch
|