groonga-client 0.5.0 → 0.5.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/doc/text/news.md +12 -0
- data/lib/groonga/client/request/select.rb +118 -0
- data/lib/groonga/client/version.rb +1 -1
- data/test/request/select/test-scorer.rb +112 -0
- data/test/request/test-select.rb +22 -0
- metadata +25 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8a5665848bb07469199965c91102537be1de8ba
|
4
|
+
data.tar.gz: b199fc33a43d039152d4ba068c415259bc4da524
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9206ea5d72f485a6a47b02bcd4518efe6e1893cc1f462432ac9d9afd67cfb88b3faee72c574e516bad9c76485d94a6efddb9246049773230864c414144a0444c
|
7
|
+
data.tar.gz: 39403cfa11da317eb5e17754a7f637234f2c250b2dd62922f501dcc2c0888afa3c74bf849573e61da0d3d14acb1f5b76b7ea7b230fa389b378a2d033017a8aa4
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# NEWS
|
2
2
|
|
3
|
+
## 0.5.1 - 2017-08-21
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* `Groonga::Client::Request::Select#scorer`: Added a convenience
|
8
|
+
method to set scorer. You can use this method by
|
9
|
+
`scorer("2 * %{column}", column: :rate)`.
|
10
|
+
|
11
|
+
* `Groonga::Client::Request::Select#query_flags`: Added a
|
12
|
+
convenience method to set query flags. You can use this method by
|
13
|
+
`query_flags(["ALLOW_COLUMN", "QUERY_NO_SYNTAX_ERROR"])`.
|
14
|
+
|
3
15
|
## 0.5.0 - 2017-05-08
|
4
16
|
|
5
17
|
### Improvements
|
@@ -47,6 +47,54 @@ module Groonga
|
|
47
47
|
RequestParameter.new(:query, value))
|
48
48
|
end
|
49
49
|
|
50
|
+
# Sets flags to custom how to parse query.
|
51
|
+
#
|
52
|
+
# @example One flag
|
53
|
+
# request.
|
54
|
+
# # Support "COLUMN_NAME:..." syntax
|
55
|
+
# query_flags("ALLOW_COLUMN").
|
56
|
+
# # -> --query_flags 'ALLOW_COLUMN'
|
57
|
+
# query("title:@Groonga")
|
58
|
+
# # -> --query_flags 'ALLOW_COLUMN'
|
59
|
+
# # --query 'title:@Groonga'
|
60
|
+
#
|
61
|
+
# @example Multiple flags
|
62
|
+
# request.
|
63
|
+
# # Support "COLUMN_NAME:..." syntax
|
64
|
+
# # Fallback syntax error query to searchable query
|
65
|
+
# query_flags(["ALLOW_COLUMN", "QUERY_NO_SYNTAX_ERROR"]).
|
66
|
+
# # -> --query_flags 'ALLOW_COLUMN'
|
67
|
+
# query("nonexistent:@Groonga")
|
68
|
+
# # -> --query_flags 'ALLOW_COLUMN'
|
69
|
+
# # --query 'nonexistent:@Groonga'
|
70
|
+
# # Normally, "nonexistent:@Groonga" is syntax error
|
71
|
+
# # but it's parsed as
|
72
|
+
# # "search by one keyword: 'nonexistent:@Groonga'"
|
73
|
+
# # because QUERY_NO_SYNTAX_ERROR flag is used
|
74
|
+
#
|
75
|
+
# @return [Groonga::Client::Request::Select]
|
76
|
+
#
|
77
|
+
# The new request with the given flag.
|
78
|
+
#
|
79
|
+
# @overload query_flags(flag)
|
80
|
+
#
|
81
|
+
# Sets a `#{flag}` flag.
|
82
|
+
#
|
83
|
+
# @param flag [String] The flag to be used.
|
84
|
+
#
|
85
|
+
# @since 0.5.1
|
86
|
+
#
|
87
|
+
# @overload query_flags(flags)
|
88
|
+
#
|
89
|
+
# Sets `#{flag1}|#{flag2}|...` flags.
|
90
|
+
#
|
91
|
+
# @param flags [::Array<String>] The flags to be used.
|
92
|
+
#
|
93
|
+
# @since 0.5.1
|
94
|
+
def query_flags(value)
|
95
|
+
flags_parameter(:query_flags, value)
|
96
|
+
end
|
97
|
+
|
50
98
|
# Adds a script syntax condition. If the request already has
|
51
99
|
# any filter condition, they are combined by AND.
|
52
100
|
#
|
@@ -143,6 +191,70 @@ module Groonga
|
|
143
191
|
end
|
144
192
|
end
|
145
193
|
|
194
|
+
# Sets scorer.
|
195
|
+
#
|
196
|
+
# @return [Groonga::Client::Request::Select]
|
197
|
+
# The new request with the given scorer.
|
198
|
+
#
|
199
|
+
# @since 0.5.1
|
200
|
+
#
|
201
|
+
# @overload scorer(column_name)
|
202
|
+
#
|
203
|
+
# Sets `_score = #{column_name}` scorer.
|
204
|
+
#
|
205
|
+
# @example Use column value as score
|
206
|
+
# request.scorer(:rate)
|
207
|
+
# # -> --scorer '_score = rate'
|
208
|
+
#
|
209
|
+
# @param column_name [Symbol] The column name to be used as score.
|
210
|
+
#
|
211
|
+
# @overload scorer(expression, values=nil)
|
212
|
+
#
|
213
|
+
# Adds a `_score = #{expression % values}` scorer. If
|
214
|
+
# `expression` is already assignment form such as `_score =
|
215
|
+
# %{column}`, `_score = ` isn't prepended automatically.
|
216
|
+
#
|
217
|
+
# @example Compute score by expression
|
218
|
+
# request.scorer("2 * rate")
|
219
|
+
# # -> --scorer '_score = 2 * rate'
|
220
|
+
#
|
221
|
+
# @example Expand values
|
222
|
+
# request.scorer("2 * %{column}", column: :rate)
|
223
|
+
# # -> --scorer '_score = 2 * rate'
|
224
|
+
#
|
225
|
+
# @param expression [String] The script syntax expression.
|
226
|
+
# It can includes `%{name}`s as placeholder. They are expanded
|
227
|
+
# by `String#%` with the given `values` argument.
|
228
|
+
#
|
229
|
+
# @param values [nil, ::Hash] The values to be expanded.
|
230
|
+
# If the given `expression` doesn't have placeholder, you
|
231
|
+
# should specify `nil`.
|
232
|
+
#
|
233
|
+
# Values are escaped automatically. Values passed from
|
234
|
+
# external should be escaped.
|
235
|
+
def scorer(expression_or_column_name, values=nil)
|
236
|
+
case expression_or_column_name
|
237
|
+
when Symbol
|
238
|
+
expression = "_score = %{column}"
|
239
|
+
column_name = expression_or_column_name
|
240
|
+
values = { column: column_name }
|
241
|
+
when String
|
242
|
+
expression = expression_or_column_name
|
243
|
+
case expression
|
244
|
+
when /\A\s*\z/
|
245
|
+
expression = nil
|
246
|
+
when /\A[_a-zA-Z\d]+\s*=/
|
247
|
+
# have assignment such as "_score = "
|
248
|
+
else
|
249
|
+
expression = "_score = #{expression}"
|
250
|
+
end
|
251
|
+
else
|
252
|
+
expression = expression_or_column_name
|
253
|
+
end
|
254
|
+
add_parameter(OverwriteMerger,
|
255
|
+
ScorerExpressionParameter.new(expression, values))
|
256
|
+
end
|
257
|
+
|
146
258
|
def output_columns(value)
|
147
259
|
add_parameter(OverwriteMerger,
|
148
260
|
OutputColumnsParameter.new("", value))
|
@@ -729,6 +841,12 @@ module Groonga
|
|
729
841
|
end
|
730
842
|
end
|
731
843
|
|
844
|
+
class ScorerExpressionParameter < ScriptSyntaxExpressionParameter
|
845
|
+
def initialize(expression, values)
|
846
|
+
super(:scorer, expression, values)
|
847
|
+
end
|
848
|
+
end
|
849
|
+
|
732
850
|
# @private
|
733
851
|
class OutputColumnsParameter < ValuesParameter
|
734
852
|
def initialize(prefix, output_columns)
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# Copyright (C) 2017 Yasuhiro Horimoto <horimoto@clear-code.com>
|
2
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
+
|
18
|
+
class TestRequestSelectScorer < Test::Unit::TestCase
|
19
|
+
setup do
|
20
|
+
@request = Groonga::Client::Request::Select.new("posts")
|
21
|
+
end
|
22
|
+
|
23
|
+
def scorer(*args)
|
24
|
+
@request.scorer(*args).to_parameters
|
25
|
+
end
|
26
|
+
|
27
|
+
sub_test_case("expression") do
|
28
|
+
def test_nil
|
29
|
+
assert_equal({
|
30
|
+
:table => "posts",
|
31
|
+
},
|
32
|
+
scorer(nil))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_string
|
36
|
+
assert_equal({
|
37
|
+
:table => "posts",
|
38
|
+
:scorer => "_score = age",
|
39
|
+
},
|
40
|
+
scorer("_score = age"))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_empty_string
|
44
|
+
assert_equal({
|
45
|
+
:table => "posts",
|
46
|
+
},
|
47
|
+
scorer(""))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_space_only_string
|
51
|
+
assert_equal({
|
52
|
+
:table => "posts",
|
53
|
+
},
|
54
|
+
scorer(" \t\r\n"))
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_have_assignment
|
58
|
+
assert_equal({
|
59
|
+
:table => "posts",
|
60
|
+
:scorer => "persistent_score = _score",
|
61
|
+
},
|
62
|
+
scorer("persistent_score = %{score}", score: :_score))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_symbol
|
66
|
+
assert_equal({
|
67
|
+
:table => "posts",
|
68
|
+
:scorer => "_score = age",
|
69
|
+
},
|
70
|
+
scorer(:age))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
sub_test_case("values") do
|
75
|
+
test("Symbol") do
|
76
|
+
assert_equal({
|
77
|
+
:table => "posts",
|
78
|
+
:scorer => "_score = age",
|
79
|
+
},
|
80
|
+
scorer("_score = %{column}", :column => :age))
|
81
|
+
end
|
82
|
+
|
83
|
+
test("Symbols") do
|
84
|
+
assert_equal({
|
85
|
+
:table => "posts",
|
86
|
+
:scorer => "_score = -geo_distance(location, \"35.68138194x139.766083888889\")",
|
87
|
+
},
|
88
|
+
scorer("-geo_distance(%{column}, %{point})",
|
89
|
+
column: :location, point: "35.68138194x139.766083888889"))
|
90
|
+
end
|
91
|
+
|
92
|
+
test("Numeric") do
|
93
|
+
assert_equal({
|
94
|
+
:table => "posts",
|
95
|
+
:scorer => "_score = 29",
|
96
|
+
},
|
97
|
+
scorer("_score = %{value}",
|
98
|
+
:value => 29))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_multiple
|
103
|
+
assert_equal({
|
104
|
+
:table => "posts",
|
105
|
+
:scorer => "_score = age",
|
106
|
+
},
|
107
|
+
@request.
|
108
|
+
scorer("_score = %{value}", :value => 29).
|
109
|
+
scorer(:age).
|
110
|
+
to_parameters)
|
111
|
+
end
|
112
|
+
end
|
data/test/request/test-select.rb
CHANGED
@@ -311,4 +311,26 @@ class TestRequestSelect < Test::Unit::TestCase
|
|
311
311
|
end
|
312
312
|
end
|
313
313
|
end
|
314
|
+
|
315
|
+
sub_test_case("#query_flags") do
|
316
|
+
def query_flags(*args)
|
317
|
+
@request.query_flags(*args).to_parameters
|
318
|
+
end
|
319
|
+
|
320
|
+
test("one") do
|
321
|
+
assert_equal({
|
322
|
+
:table => "posts",
|
323
|
+
:query_flags => "ALLOW_COLUMN",
|
324
|
+
},
|
325
|
+
query_flags("ALLOW_COLUMN"))
|
326
|
+
end
|
327
|
+
|
328
|
+
test("multiple") do
|
329
|
+
assert_equal({
|
330
|
+
:table => "posts",
|
331
|
+
:query_flags => "ALLOW_COLUMN|QUERY_NO_SYNTAX_ERROR",
|
332
|
+
},
|
333
|
+
query_flags(["ALLOW_COLUMN", "QUERY_NO_SYNTAX_ERROR"]))
|
334
|
+
end
|
335
|
+
end
|
314
336
|
end
|
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.5.
|
4
|
+
version: 0.5.1
|
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-08-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gqtp
|
@@ -226,6 +226,7 @@ files:
|
|
226
226
|
- test/request/select/test-backward-compatible-sort-keys-parameter.rb
|
227
227
|
- test/request/select/test-filter.rb
|
228
228
|
- test/request/select/test-output-columns-parameter.rb
|
229
|
+
- test/request/select/test-scorer.rb
|
229
230
|
- test/request/select/test-sort-keys-parameter.rb
|
230
231
|
- test/request/select/test-values-parameter.rb
|
231
232
|
- test/request/test-generic.rb
|
@@ -269,37 +270,38 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
270
|
version: '0'
|
270
271
|
requirements: []
|
271
272
|
rubyforge_project:
|
272
|
-
rubygems_version: 2.
|
273
|
+
rubygems_version: 2.5.2
|
273
274
|
signing_key:
|
274
275
|
specification_version: 4
|
275
276
|
summary: Groonga-client is a client for Groonga (http://groonga.org/) implemented
|
276
277
|
with pure Ruby. You can use it without Groonga.
|
277
278
|
test_files:
|
279
|
+
- test/test-client.rb
|
280
|
+
- test/test-script-syntax.rb
|
281
|
+
- test/request/select/test-backward-compatible-sort-keys-parameter.rb
|
282
|
+
- test/request/select/test-filter.rb
|
283
|
+
- test/request/select/test-sort-keys-parameter.rb
|
284
|
+
- test/request/select/test-output-columns-parameter.rb
|
285
|
+
- test/request/select/test-values-parameter.rb
|
286
|
+
- test/request/select/test-scorer.rb
|
287
|
+
- test/request/test-merger.rb
|
288
|
+
- test/request/test-generic.rb
|
289
|
+
- test/request/test-select.rb
|
290
|
+
- test/test-command.rb
|
291
|
+
- test/protocol/test-gqtp.rb
|
292
|
+
- test/protocol/test-http.rb
|
278
293
|
- test/run-test.rb
|
294
|
+
- test/response/test-base.rb
|
295
|
+
- test/response/test-load.rb
|
296
|
+
- test/response/test-column-list.rb
|
297
|
+
- test/response/helper.rb
|
279
298
|
- test/response/test-error.rb
|
299
|
+
- test/response/test-table-list.rb
|
300
|
+
- test/response/test-status.rb
|
301
|
+
- test/response/test-schema.rb
|
280
302
|
- test/response/test-select-command-version3.rb
|
281
303
|
- test/response/test-select-command-version1.rb
|
282
304
|
- test/response/test-table-create.rb
|
283
|
-
- test/response/helper.rb
|
284
|
-
- test/response/test-status.rb
|
285
|
-
- test/response/test-column-list.rb
|
286
|
-
- test/response/test-schema.rb
|
287
|
-
- test/response/test-table-list.rb
|
288
|
-
- test/response/test-load.rb
|
289
|
-
- test/response/test-base.rb
|
290
305
|
- test/response/test-table-remove.rb
|
291
|
-
- test/test-script-syntax.rb
|
292
|
-
- test/protocol/test-http.rb
|
293
|
-
- test/protocol/test-gqtp.rb
|
294
306
|
- test/results/test-column-list.rb
|
295
307
|
- test/results/test-table-list.rb
|
296
|
-
- test/test-command.rb
|
297
|
-
- test/request/select/test-values-parameter.rb
|
298
|
-
- test/request/select/test-filter.rb
|
299
|
-
- test/request/select/test-output-columns-parameter.rb
|
300
|
-
- test/request/select/test-sort-keys-parameter.rb
|
301
|
-
- test/request/select/test-backward-compatible-sort-keys-parameter.rb
|
302
|
-
- test/request/test-merger.rb
|
303
|
-
- test/request/test-generic.rb
|
304
|
-
- test/request/test-select.rb
|
305
|
-
- test/test-client.rb
|