groonga-client 0.3.7 → 0.3.8
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 +33 -9
- data/lib/groonga/client/request/select.rb +94 -33
- data/lib/groonga/client/version.rb +1 -1
- data/test/request/select/test-filter-equal-parameter.rb +82 -0
- data/test/request/select/{test-filter-parameter.rb → test-filter-expression-parameter.rb} +3 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfbb43c1be922a0d52d798e0a7e3a768e36eaea6
|
4
|
+
data.tar.gz: 3904d0176fa3c87eda914b6065b2dd81d0abf6bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47e683987f841ad1bb077876f73023e76f26197f2796387fbbbee717a8902d9df071e0f5d2b8c9715cca7c24ab39c5519d38ea00798b7fadb8f2b0327ba30850
|
7
|
+
data.tar.gz: 8f48a51fa09b821d7665ff90e109a571aac501e676f587ad11a2b80c93fac61a8c267f2a030e1b3ebabb3ea2c3901a1baa46d75dac1b2326a1161cbefb32a790
|
data/doc/text/news.md
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
# NEWS
|
2
2
|
|
3
|
+
## 0.3.8 - 2016-12-21
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* `Groonga::Client::Request::Select#filter`: Supported
|
8
|
+
`filter(column_name, value)` usage. It's a shortcut of
|
9
|
+
`filter("#{column_name} == %{value}", value: value)`.
|
10
|
+
|
3
11
|
## 0.3.7 - 2016-12-20
|
4
12
|
|
5
13
|
### Improvements
|
6
14
|
|
7
|
-
* `Groonga::Client::Test::GroongaServerRunner`: Supported
|
15
|
+
* `Groonga::Client::Test::GroongaServerRunner`: Supported
|
16
|
+
customizing Groonga server URL.
|
8
17
|
|
9
18
|
## 0.3.6 - 2016-12-20
|
10
19
|
|
@@ -16,40 +25,55 @@
|
|
16
25
|
|
17
26
|
* `Groonga::Client::Response::Schema#plugins`: Supported method access.
|
18
27
|
|
19
|
-
* `Groonga::Client::Test::GroongaServerRunner`: Supported restoring
|
28
|
+
* `Groonga::Client::Test::GroongaServerRunner`: Supported restoring
|
29
|
+
DB for existing server.
|
20
30
|
|
21
31
|
## 0.3.5 - 2016-12-19
|
22
32
|
|
23
33
|
### Improvements
|
24
34
|
|
25
|
-
* `Groonga::Client::Response::Schema::Column#value_type`: Made
|
35
|
+
* `Groonga::Client::Response::Schema::Column#value_type`: Made
|
36
|
+
`value_type` elements method accessable.
|
26
37
|
|
27
38
|
## 0.3.4 - 2016-12-13
|
28
39
|
|
29
40
|
### Improvements
|
30
41
|
|
31
42
|
* Added request interface from groonga-client-rails.
|
32
|
-
|
33
|
-
* Added
|
34
|
-
|
43
|
+
|
44
|
+
* Added
|
45
|
+
`Groonga::Client::Response::Schema::Index#full_text_searchable?`.
|
46
|
+
|
47
|
+
* Added
|
48
|
+
`Groonga::Client::Response::Schema::Column#have_full_text_search_index?`.
|
49
|
+
|
50
|
+
* Added
|
51
|
+
`Groonga::Client::Response::Schema::Table#have_full_text_search_index?`.
|
52
|
+
|
35
53
|
* Added `Groonga::Client::Response::Select#slices`.
|
54
|
+
|
36
55
|
* Added test helper from groonga-client-rails.
|
56
|
+
|
37
57
|
* Added `Groonga::Client::Response#size` for Kaminari.
|
58
|
+
|
38
59
|
* Added enumrable interface for `Groonga::Client::Response::Select`.
|
39
60
|
|
40
61
|
## 0.3.3 - 2016-12-07
|
41
62
|
|
42
63
|
### Improvements
|
43
64
|
|
44
|
-
* `Groonga::Load#loaded_ids`: Renamed from
|
65
|
+
* `Groonga::Load#loaded_ids`: Renamed from
|
66
|
+
`Groonga::Load#ids`. Because it's renamed in Groonga.
|
45
67
|
|
46
68
|
## 0.3.2 - 2016-12-06
|
47
69
|
|
48
70
|
### Improvements
|
49
71
|
|
50
|
-
* `Groonga::Load#n_loaded_records`: Added. It's a convenience method
|
72
|
+
* `Groonga::Load#n_loaded_records`: Added. It's a convenience method
|
73
|
+
to get the number of loaded records.
|
51
74
|
|
52
|
-
* `Groonga::Load#ids`: Added. It's for `load --output_ids yes
|
75
|
+
* `Groonga::Load#ids`: Added. It's for `load --output_ids yes
|
76
|
+
--command_version 3` that can be used with Groonga 6.1.2 or later.
|
53
77
|
|
54
78
|
## 0.3.1 - 2016-10-11
|
55
79
|
|
@@ -46,9 +46,49 @@ module Groonga
|
|
46
46
|
RequestParameter.new(:query, value))
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
# Adds a script syntax condition. If the request already has
|
50
|
+
# any filter condition, they are combined by AND.
|
51
|
+
#
|
52
|
+
# @example: Multiple filters
|
53
|
+
# request.
|
54
|
+
# filter("user", "alice").
|
55
|
+
# # -> --filter 'user == "alice"'
|
56
|
+
# filter("tags @ %{tag}", tag: "Ruby")
|
57
|
+
# # -> --filter '(user == "alice") && (tags @ "Ruby")'
|
58
|
+
#
|
59
|
+
# @return [Groonga::Client::Request::Select]
|
60
|
+
# The new request with the given condition.
|
61
|
+
#
|
62
|
+
# @overload filter(column_name, value)
|
63
|
+
# @param [String, Symbol] column_name The target column name.
|
64
|
+
# @param [Object] value The column value. It's escaped automatically.
|
65
|
+
#
|
66
|
+
# Adds a `#{column_name} == #{value}` condition.
|
67
|
+
#
|
68
|
+
# @overload filter(expression, values=nil)
|
69
|
+
# @param [String] expression The script syntax expression.
|
70
|
+
# It can includes `%{name}`s as placeholder. They are expanded
|
71
|
+
# by `String#%` with the given `values` argument.
|
72
|
+
# @param [nil, ::Hash] values The values to be expanded.
|
73
|
+
# If the given `expression` doesn't have placeholder, you
|
74
|
+
# should specify `nil`.
|
75
|
+
#
|
76
|
+
# Values are escaped automatically. Values passed from
|
77
|
+
# external should be escaped.
|
78
|
+
#
|
79
|
+
# Adds a `#{expression % values}` condition.
|
80
|
+
def filter(expression_or_column_name, values_or_value=nil)
|
81
|
+
if expression_or_column_name.is_a?(Symbol)
|
82
|
+
parameter = FilterEqualParameter.new(expression_or_column_name,
|
83
|
+
values_or_value)
|
84
|
+
elsif values_or_value.nil? or values_or_value.is_a?(::Hash)
|
85
|
+
parameter = FilterExpressionParameter.new(expression_or_column_name,
|
86
|
+
values_or_value)
|
87
|
+
else
|
88
|
+
parameter = FilterEqualParameter.new(expression_or_column_name,
|
89
|
+
values_or_value)
|
90
|
+
end
|
91
|
+
add_parameter(FilterMerger, parameter)
|
52
92
|
end
|
53
93
|
|
54
94
|
def output_columns(value)
|
@@ -190,36 +230,7 @@ module Groonga
|
|
190
230
|
end
|
191
231
|
|
192
232
|
# @private
|
193
|
-
|
194
|
-
def initialize(expression, values)
|
195
|
-
@expression = expression
|
196
|
-
@values = values
|
197
|
-
end
|
198
|
-
|
199
|
-
def to_parameters
|
200
|
-
case @expression
|
201
|
-
when String
|
202
|
-
return {} if /\A\s*\z/ === @expression
|
203
|
-
expression = @expression
|
204
|
-
when NilClass
|
205
|
-
return {}
|
206
|
-
else
|
207
|
-
expression = @expression
|
208
|
-
end
|
209
|
-
|
210
|
-
if @values.is_a?(::Hash) and not @values.empty?
|
211
|
-
escaped_values = {}
|
212
|
-
@values.each do |key, value|
|
213
|
-
escaped_values[key] = escape_filter_value(value)
|
214
|
-
end
|
215
|
-
expression = expression % escaped_values
|
216
|
-
end
|
217
|
-
|
218
|
-
{
|
219
|
-
filter: expression,
|
220
|
-
}
|
221
|
-
end
|
222
|
-
|
233
|
+
module FilterValueEscapable
|
223
234
|
private
|
224
235
|
def escape_filter_value(value)
|
225
236
|
case value
|
@@ -257,6 +268,56 @@ module Groonga
|
|
257
268
|
end
|
258
269
|
end
|
259
270
|
|
271
|
+
# @private
|
272
|
+
class FilterExpressionParameter
|
273
|
+
include FilterValueEscapable
|
274
|
+
|
275
|
+
def initialize(expression, values)
|
276
|
+
@expression = expression
|
277
|
+
@values = values
|
278
|
+
end
|
279
|
+
|
280
|
+
def to_parameters
|
281
|
+
case @expression
|
282
|
+
when String
|
283
|
+
return {} if /\A\s*\z/ === @expression
|
284
|
+
expression = @expression
|
285
|
+
when NilClass
|
286
|
+
return {}
|
287
|
+
else
|
288
|
+
expression = @expression
|
289
|
+
end
|
290
|
+
|
291
|
+
if @values.is_a?(::Hash) and not @values.empty?
|
292
|
+
escaped_values = {}
|
293
|
+
@values.each do |key, value|
|
294
|
+
escaped_values[key] = escape_filter_value(value)
|
295
|
+
end
|
296
|
+
expression = expression % escaped_values
|
297
|
+
end
|
298
|
+
|
299
|
+
{
|
300
|
+
filter: expression,
|
301
|
+
}
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
# @private
|
306
|
+
class FilterEqualParameter
|
307
|
+
include FilterValueEscapable
|
308
|
+
|
309
|
+
def initialize(column_name, value)
|
310
|
+
@column_name = column_name
|
311
|
+
@value = value
|
312
|
+
end
|
313
|
+
|
314
|
+
def to_parameters
|
315
|
+
{
|
316
|
+
filter: "#{@column_name} == #{escape_filter_value(@value)}",
|
317
|
+
}
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
260
321
|
# @private
|
261
322
|
class OutputColumnsParameter < ValuesParameter
|
262
323
|
def initialize(prefix, output_columns)
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRequestSelectFilterEqualParmater < Test::Unit::TestCase
|
18
|
+
def filter_parameter(column_name, value)
|
19
|
+
Groonga::Client::Request::Select::FilterEqualParameter.new(column_name,
|
20
|
+
value)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_parameters(column_name, value)
|
24
|
+
filter_parameter(column_name, value).to_parameters
|
25
|
+
end
|
26
|
+
|
27
|
+
sub_test_case("column name") do
|
28
|
+
def test_string
|
29
|
+
assert_equal({
|
30
|
+
:filter => "_key == 29",
|
31
|
+
},
|
32
|
+
to_parameters("_key", 29))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_symbol
|
36
|
+
assert_equal({
|
37
|
+
:filter => "_key == 29",
|
38
|
+
},
|
39
|
+
to_parameters(:_key, 29))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
sub_test_case("value") do
|
44
|
+
def test_string
|
45
|
+
filter = <<-'FILTER'.strip
|
46
|
+
title == "[\"He\\ llo\"]"
|
47
|
+
FILTER
|
48
|
+
assert_equal({
|
49
|
+
:filter => filter,
|
50
|
+
},
|
51
|
+
to_parameters("title", "[\"He\\ llo\"]"))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_symbol
|
55
|
+
assert_equal({
|
56
|
+
:filter => "title == \"Hello\"",
|
57
|
+
},
|
58
|
+
to_parameters("title", :Hello))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_number
|
62
|
+
assert_equal({
|
63
|
+
:filter => "age == 29",
|
64
|
+
},
|
65
|
+
to_parameters("age", 29))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_true
|
69
|
+
assert_equal({
|
70
|
+
:filter => "published == true",
|
71
|
+
},
|
72
|
+
to_parameters("published", true))
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_false
|
76
|
+
assert_equal({
|
77
|
+
:filter => "published == false",
|
78
|
+
},
|
79
|
+
to_parameters("published", false))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -14,9 +14,10 @@
|
|
14
14
|
# License along with this library; if not, write to the Free Software
|
15
15
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
16
|
|
17
|
-
class
|
17
|
+
class TestRequestSelectFilterExpressionParmater < Test::Unit::TestCase
|
18
18
|
def filter_parameter(expression, values=nil)
|
19
|
-
Groonga::Client::Request::Select::
|
19
|
+
Groonga::Client::Request::Select::FilterExpressionParameter.new(expression,
|
20
|
+
values)
|
20
21
|
end
|
21
22
|
|
22
23
|
def to_parameters(expression, values=nil)
|
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.3.
|
4
|
+
version: 0.3.8
|
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: 2016-12-
|
13
|
+
date: 2016-12-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gqtp
|
@@ -223,7 +223,8 @@ files:
|
|
223
223
|
- lib/groonga/client/version.rb
|
224
224
|
- test/protocol/test-gqtp.rb
|
225
225
|
- test/protocol/test-http.rb
|
226
|
-
- test/request/select/test-filter-parameter.rb
|
226
|
+
- test/request/select/test-filter-equal-parameter.rb
|
227
|
+
- test/request/select/test-filter-expression-parameter.rb
|
227
228
|
- test/request/select/test-output-columns-parameter.rb
|
228
229
|
- test/request/select/test-sort-keys-columns-parameter.rb
|
229
230
|
- test/request/select/test-values-parameter.rb
|
@@ -275,9 +276,10 @@ summary: Groonga-client is a client for Groonga (http://groonga.org/) implemente
|
|
275
276
|
test_files:
|
276
277
|
- test/test-client.rb
|
277
278
|
- test/test-script-syntax.rb
|
278
|
-
- test/request/select/test-filter-parameter.rb
|
279
|
+
- test/request/select/test-filter-expression-parameter.rb
|
279
280
|
- test/request/select/test-output-columns-parameter.rb
|
280
281
|
- test/request/select/test-values-parameter.rb
|
282
|
+
- test/request/select/test-filter-equal-parameter.rb
|
281
283
|
- test/request/select/test-sort-keys-columns-parameter.rb
|
282
284
|
- test/request/test-base.rb
|
283
285
|
- test/request/test-select.rb
|