groonga-client 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +8 -0
- data/lib/groonga/client.rb +2 -2
- data/lib/groonga/client/request/select.rb +90 -8
- data/lib/groonga/client/response/base.rb +5 -3
- data/lib/groonga/client/version.rb +1 -1
- data/test/request/test-select.rb +29 -0
- metadata +24 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dd4add841527a3ebe6c5e9a0e9cc83bb618a973
|
4
|
+
data.tar.gz: 3946ccfce7f6e1aa7e3105760fa0a305885ca629
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a131ca1ab2cb04af14a5bb43e83dbac2f793e040c777354125bad17399453cdf26ef17390e931ce60b241b3cb3806131589cdd2fe836ec683ebb696ccf1ebe9
|
7
|
+
data.tar.gz: '080dec40f5d1b28a4b55c3d6e30e7c48261a6f0db3bffccdd7c55b755f2e59ac77bdb8dd909d4f1a53f901cf4d0f36c5eb1d0278c3d2872902a1cda7c7daa182'
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# NEWS
|
2
2
|
|
3
|
+
## 0.4.3 - 2017-04-21
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* `Groonga::Client::Request::Select::Filter#in_values`: Added a
|
8
|
+
convenience method to add a popular filter condition. You can
|
9
|
+
use this method by `filter.in_values("tags", "tag1", "tag2")`.
|
10
|
+
|
3
11
|
## 0.4.2 - 2016-03-09
|
4
12
|
|
5
13
|
### Improvements
|
data/lib/groonga/client.rb
CHANGED
@@ -37,7 +37,7 @@ module Groonga
|
|
37
37
|
@@deafult_options
|
38
38
|
end
|
39
39
|
|
40
|
-
# @param [Hash]
|
40
|
+
# @param options [Hash] The new default options for
|
41
41
|
# {Groonga::Client.new}.
|
42
42
|
#
|
43
43
|
# @since 0.2.0
|
@@ -46,7 +46,7 @@ module Groonga
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# @!macro [new] initialize_options
|
49
|
-
# @param [Hash]
|
49
|
+
# @param options [Hash] The options.
|
50
50
|
# @option options [String, URI::Generic, URI::HTTP, URI::HTTPS]
|
51
51
|
# :url The URL of Groonga server.
|
52
52
|
# @option options [:gqtp, :http, :https] :protocol The
|
@@ -61,24 +61,47 @@ module Groonga
|
|
61
61
|
# The new request with the given condition.
|
62
62
|
#
|
63
63
|
# @overload filter(column_name, value)
|
64
|
-
# @param [String, Symbol] column_name The target column name.
|
65
|
-
# @param [Object] value The column value. It's escaped automatically.
|
66
|
-
#
|
67
64
|
# Adds a `#{column_name} == #{value}` condition.
|
68
65
|
#
|
66
|
+
# @param column_name [String, Symbol] The target column name.
|
67
|
+
#
|
68
|
+
# @param value [Object] The column value. It's escaped
|
69
|
+
# automatically.
|
70
|
+
#
|
69
71
|
# @overload filter(expression, values=nil)
|
70
|
-
#
|
72
|
+
#
|
73
|
+
# Adds a `#{expression % values}` condition.
|
74
|
+
#
|
75
|
+
# @param expression [String] The script syntax expression.
|
71
76
|
# It can includes `%{name}`s as placeholder. They are expanded
|
72
77
|
# by `String#%` with the given `values` argument.
|
73
|
-
#
|
78
|
+
#
|
79
|
+
# @param values [nil, ::Hash] The values to be expanded.
|
74
80
|
# If the given `expression` doesn't have placeholder, you
|
75
81
|
# should specify `nil`.
|
76
82
|
#
|
77
83
|
# Values are escaped automatically. Values passed from
|
78
84
|
# external should be escaped.
|
79
85
|
#
|
80
|
-
#
|
81
|
-
|
86
|
+
# @overload filter
|
87
|
+
#
|
88
|
+
# Returns a request object for filter condition. It provides
|
89
|
+
# convenient methods to add a popular filter condition.
|
90
|
+
#
|
91
|
+
# @example: Use in_values function
|
92
|
+
# request.
|
93
|
+
# filter.in_values("tags", "tag1", "tag2")
|
94
|
+
# # -> --filter 'in_values(tags, "tag1", "tag2")'
|
95
|
+
#
|
96
|
+
# @return [Groonga::Client::Request::Select::Filter]
|
97
|
+
# The new request object for setting a filter condition.
|
98
|
+
#
|
99
|
+
# @since 0.4.3
|
100
|
+
def filter(expression_or_column_name=nil, values_or_value=nil)
|
101
|
+
if expression_or_column_name.nil? and values_or_value.nil?
|
102
|
+
return Filter.new(self)
|
103
|
+
end
|
104
|
+
|
82
105
|
if expression_or_column_name.is_a?(Symbol)
|
83
106
|
parameter = FilterEqualParameter.new(expression_or_column_name,
|
84
107
|
values_or_value)
|
@@ -153,6 +176,45 @@ module Groonga
|
|
153
176
|
parameters.key?(:offset) and parameters.key?(:limit)
|
154
177
|
end
|
155
178
|
|
179
|
+
# @since 0.4.3
|
180
|
+
class Filter
|
181
|
+
def initialize(request)
|
182
|
+
@request = request
|
183
|
+
end
|
184
|
+
|
185
|
+
# Adds a `in_values` condition then return a new `select`
|
186
|
+
# request object.
|
187
|
+
#
|
188
|
+
# @example: Multiple conditions
|
189
|
+
# request.
|
190
|
+
# filter.in_values("tags", "tag1", "tag2").
|
191
|
+
# # -> --filter 'in_values(tags, "tag1", "tag2")'
|
192
|
+
# filter("user", "alice")
|
193
|
+
# # -> --filter '(in_values(tags, "tag1", "tag2")) && (user == "alice")'
|
194
|
+
#
|
195
|
+
# @example: Ignore no values case
|
196
|
+
# request.
|
197
|
+
# filter.in_values("tags")
|
198
|
+
# # -> --filter ''
|
199
|
+
#
|
200
|
+
# @param column_name [String, Symbol] The target column name.
|
201
|
+
#
|
202
|
+
# @param values [Object] The column values that cover target
|
203
|
+
# column values.
|
204
|
+
#
|
205
|
+
# @return [Groonga::Client::Request::Select]
|
206
|
+
# The new request with the given condition.
|
207
|
+
def in_values(column_name, *values)
|
208
|
+
parameter = FilterInValuesParameter.new(column_name, *values)
|
209
|
+
add_parameter(FilterMerger, parameter)
|
210
|
+
end
|
211
|
+
|
212
|
+
private
|
213
|
+
def add_parameter(merger, parameter)
|
214
|
+
@request.__send__(:add_parameter, merger, parameter)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
156
218
|
class LabeledDrilldown
|
157
219
|
def initialize(request, label)
|
158
220
|
@request = request
|
@@ -302,7 +364,7 @@ module Groonga
|
|
302
364
|
filter2 = params2[:filter]
|
303
365
|
if filter1 and filter2
|
304
366
|
params[:filter] = "(#{filter1}) && (#{filter2})"
|
305
|
-
|
367
|
+
elsif filter1 or filter2
|
306
368
|
params[:filter] = (filter1 || filter2)
|
307
369
|
end
|
308
370
|
params
|
@@ -396,6 +458,26 @@ module Groonga
|
|
396
458
|
end
|
397
459
|
|
398
460
|
# @private
|
461
|
+
class FilterInValuesParameter
|
462
|
+
include ScriptSyntaxValueEscapable
|
463
|
+
|
464
|
+
def initialize(column_name, *values)
|
465
|
+
@column_name = column_name
|
466
|
+
@values = values
|
467
|
+
end
|
468
|
+
|
469
|
+
def to_parameters
|
470
|
+
return {} if @values.empty?
|
471
|
+
|
472
|
+
escaped_values = @values.collect do |value|
|
473
|
+
escape_script_syntax_value(value)
|
474
|
+
end
|
475
|
+
{
|
476
|
+
filter: "in_values(#{@column_name}, #{escaped_values.join(", ")})",
|
477
|
+
}
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
399
481
|
class FilterEqualParameter
|
400
482
|
include ScriptSyntaxValueEscapable
|
401
483
|
|
@@ -38,9 +38,11 @@ module Groonga
|
|
38
38
|
# Parses the response for the request of the command and returns
|
39
39
|
# response object.
|
40
40
|
#
|
41
|
-
# @param [Groonga::Command::Base] The command of the request.
|
42
|
-
#
|
43
|
-
#
|
41
|
+
# @param command [Groonga::Command::Base] The command of the request.
|
42
|
+
#
|
43
|
+
# @param raw_response [String] The raw (not parsed) response
|
44
|
+
# returned by Groonga server.
|
45
|
+
#
|
44
46
|
# @return [Base]
|
45
47
|
def parse(command, raw_response)
|
46
48
|
klass = find(command.command_name)
|
data/test/request/test-select.rb
CHANGED
@@ -91,6 +91,35 @@ class TestRequestSelect < Test::Unit::TestCase
|
|
91
91
|
"number" => 29
|
92
92
|
}))
|
93
93
|
end
|
94
|
+
|
95
|
+
sub_test_case("#in_values") do
|
96
|
+
def in_values(column_name, *values)
|
97
|
+
@request.filter.in_values(column_name, *values).to_parameters
|
98
|
+
end
|
99
|
+
|
100
|
+
test("numbers") do
|
101
|
+
assert_equal({
|
102
|
+
:table => "posts",
|
103
|
+
:filter => "in_values(ages, 2, 29)",
|
104
|
+
},
|
105
|
+
in_values("ages", 2, 29))
|
106
|
+
end
|
107
|
+
|
108
|
+
test("strings") do
|
109
|
+
assert_equal({
|
110
|
+
:table => "posts",
|
111
|
+
:filter => "in_values(tags, \"groonga\", \"have \\\"double\\\" quote\")",
|
112
|
+
},
|
113
|
+
in_values("tags", "groonga", "have \"double\" quote"))
|
114
|
+
end
|
115
|
+
|
116
|
+
test("no values") do
|
117
|
+
assert_equal({
|
118
|
+
:table => "posts",
|
119
|
+
},
|
120
|
+
in_values("tags"))
|
121
|
+
end
|
122
|
+
end
|
94
123
|
end
|
95
124
|
|
96
125
|
sub_test_case("#drilldowns") do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Haruka Yoshihara
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-04-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gqtp
|
@@ -270,38 +270,38 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
270
|
version: '0'
|
271
271
|
requirements: []
|
272
272
|
rubyforge_project:
|
273
|
-
rubygems_version: 2.
|
273
|
+
rubygems_version: 2.6.11
|
274
274
|
signing_key:
|
275
275
|
specification_version: 4
|
276
276
|
summary: Groonga-client is a client for Groonga (http://groonga.org/) implemented
|
277
277
|
with pure Ruby. You can use it without Groonga.
|
278
278
|
test_files:
|
279
|
-
- test/test-
|
280
|
-
- test/test-
|
281
|
-
- test/request/
|
279
|
+
- test/results/test-table-list.rb
|
280
|
+
- test/results/test-column-list.rb
|
281
|
+
- test/request/test-generic.rb
|
282
|
+
- test/request/test-merger.rb
|
283
|
+
- test/request/test-select.rb
|
284
|
+
- test/request/select/test-values-parameter.rb
|
282
285
|
- test/request/select/test-backward-compatible-sort-keys-parameter.rb
|
283
|
-
- test/request/select/test-sort-keys-parameter.rb
|
284
286
|
- test/request/select/test-output-columns-parameter.rb
|
285
|
-
- test/request/select/test-values-parameter.rb
|
286
287
|
- test/request/select/test-filter-equal-parameter.rb
|
287
|
-
- test/request/test-
|
288
|
-
- test/request/test-
|
289
|
-
- test/
|
290
|
-
- test/test-
|
291
|
-
- test/protocol/test-gqtp.rb
|
292
|
-
- test/protocol/test-http.rb
|
293
|
-
- test/run-test.rb
|
294
|
-
- test/response/test-base.rb
|
288
|
+
- test/request/select/test-sort-keys-parameter.rb
|
289
|
+
- test/request/select/test-filter-expression-parameter.rb
|
290
|
+
- test/response/test-status.rb
|
291
|
+
- test/response/test-error.rb
|
295
292
|
- test/response/test-load.rb
|
296
|
-
- test/response/test-
|
293
|
+
- test/response/test-table-create.rb
|
297
294
|
- test/response/helper.rb
|
298
|
-
- test/response/test-error.rb
|
299
295
|
- test/response/test-table-list.rb
|
300
|
-
- test/response/test-
|
301
|
-
- test/response/test-
|
296
|
+
- test/response/test-base.rb
|
297
|
+
- test/response/test-table-remove.rb
|
302
298
|
- test/response/test-select-command-version3.rb
|
299
|
+
- test/response/test-column-list.rb
|
303
300
|
- test/response/test-select-command-version1.rb
|
304
|
-
- test/response/test-
|
305
|
-
- test/
|
306
|
-
- test/
|
307
|
-
- test/
|
301
|
+
- test/response/test-schema.rb
|
302
|
+
- test/run-test.rb
|
303
|
+
- test/test-script-syntax.rb
|
304
|
+
- test/protocol/test-gqtp.rb
|
305
|
+
- test/protocol/test-http.rb
|
306
|
+
- test/test-command.rb
|
307
|
+
- test/test-client.rb
|