groonga-command 1.4.1 → 1.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 90745a99d72f93d9d719234502ba3647dcb1925c
4
- data.tar.gz: ae6c07674439ffecdccacb23a24522dc342859d5
2
+ SHA256:
3
+ metadata.gz: ce9859484daef364ba74d82aa2391c0f1adbf7c28370b3d8ca974cb7dd18c451
4
+ data.tar.gz: c59cf788e9ac27ec0eea8e7ae330d62a48b6a48af000ef72d2c284b730969c01
5
5
  SHA512:
6
- metadata.gz: bcc65e519bb8f64dfc51dd8b71d4070bcefd3a7a730c2bf96c161d953a9a7da5d5e05b475fbcc8dfca3c2a3f6ee1980455ebccb1aefd1e44d9c21bcb267c41c8
7
- data.tar.gz: fad54dfbfe207833888e7d7681c9fa9a2109c20aef29cbf602984b048b082e57ef4079e0add7c051755727cbb1165b3e26a4c9b7f77b4fe3d47c5e76fe537fbf
6
+ metadata.gz: 801903b0deea2eaccb58f175e3eca3557f3783c1e627986016c65ce82709a7bc3f3ddbe882fd0fed9146e94819d0e8fe68ee836f321b0b5c6a37c72dc216c615
7
+ data.tar.gz: 7fca220f7e886b28753a6610a228c4deffa2b2e18d0946d44c5179920a9452cc1dae9eed3101c481c61c659151c4f391fc979d3342a38313f0a1a2370d6bd556
data/doc/text/news.md CHANGED
@@ -1,12 +1,40 @@
1
1
  # News
2
2
 
3
+ ## 1.4.4: 2019-09-02
4
+
5
+ ### Improvements
6
+
7
+ * {Groonga::Command::LogicalSelect}: Added support for slices.
8
+
9
+ * {Groonga::Command::LogicalSelect}: Added support for labeled drilldowns.
10
+
11
+ ## 1.4.3: 2019-09-02
12
+
13
+ ### Improvements
14
+
15
+ * {Groonga::Command::LogicalRangeFilter#use_range_index}: Added.
16
+
17
+ * {Groonga::Command::LogicalRangeFilter#post_filter}: Added.
18
+
19
+ * {Groonga::Command::LogicalRangeFilter#sort_keys}: Added.
20
+
21
+ ## 1.4.2: 2019-08-21
22
+
23
+ ### Improvements
24
+
25
+ * {Groonga::Command::LogicalSelect#sort_keys}: Added.
26
+
27
+ ### Fixes
28
+
29
+ * Fixed a bug that Command::Base#== uses name instead of command_name [GitHub#13][Reported by yagisumi]
30
+
3
31
  ## 1.4.1: 2019-03-26
4
32
 
5
33
  ### Fixes
6
34
 
7
35
  * Fixed a bug that result of conversion to the Elasticsearch
8
36
  format result is wrong
9
-
37
+
10
38
  ## 1.4.0: 2019-03-20
11
39
 
12
40
  ### Improvements
@@ -14,7 +42,7 @@
14
42
  * {Groonga::Command::Format::Elasticsearch}: Added.
15
43
 
16
44
  * {Groonga::Command::Base#to_elasticsearch_format}: Added.
17
-
45
+
18
46
  ## 1.3.9: 2019-03-19
19
47
 
20
48
  ### Improvements
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012-2017 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2012-2019 Sutou Kouhei <kou@clear-code.com>
2
2
  # Copyright (C) 2019 Yasuhiro Horimoto <horimoto@clear-code.com>
3
3
  #
4
4
  # This library is free software; you can redistribute it and/or
@@ -123,7 +123,7 @@ module Groonga
123
123
 
124
124
  def ==(other)
125
125
  other.is_a?(self.class) and
126
- @command_name == other.name and
126
+ @command_name == other.command_name and
127
127
  @arguments == other.arguments
128
128
  end
129
129
 
@@ -232,15 +232,22 @@ module Groonga
232
232
  value.strip.split(/\s*[| ]\s*/)
233
233
  end
234
234
 
235
- def boolean_value(name, default_value)
236
- parse_boolean_value(self[name], default_value)
235
+ def boolean_value(name, **keyword_args)
236
+ parse_boolean_value(self[name], **keyword_args)
237
237
  end
238
238
 
239
- def parse_boolean_value(value, default_value)
240
- return default_value if value.nil?
239
+ def parse_boolean_value(value, default:, invalid:)
240
+ return default if value.nil?
241
241
  value = value.strip
242
- return default_value if value.empty?
243
- value == "yes"
242
+ return default if value.empty?
243
+ case value
244
+ when "yes"
245
+ true
246
+ when "no"
247
+ false
248
+ else
249
+ invalid
250
+ end
244
251
  end
245
252
  end
246
253
  end
@@ -0,0 +1,150 @@
1
+ # Copyright (C) 2019 Sutou Kouhei <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
+ module Groonga
18
+ module Command
19
+ module Drilldownable
20
+ # @return [String] `drilldown` parameter value.
21
+ #
22
+ # @since 1.1.3
23
+ def drilldown
24
+ self[:drilldown]
25
+ end
26
+
27
+ def drilldowns
28
+ @drilldowns ||= array_value(:drilldown)
29
+ end
30
+
31
+ # @return [String, nil] The filter for the drilled down result.
32
+ #
33
+ # @since 1.3.3
34
+ def drilldown_filter
35
+ self[:drilldown_filter]
36
+ end
37
+
38
+ # @return [String] `drilldown_sortby` parameter value.
39
+ #
40
+ # @since 1.1.3
41
+ #
42
+ # @deprecated since 1.4.4. Use `drilldown_sort_keys` instead.
43
+ def drilldown_sortby
44
+ self[:drilldown_sortby]
45
+ end
46
+
47
+ # @return [::Array<String>] The sort keys for drilldowns.
48
+ #
49
+ # @since 1.2.8
50
+ def drilldown_sort_keys
51
+ value = self[:drilldown_sort_keys] || self[:drilldown_sortby] || ""
52
+ parse_array_value(value)
53
+ end
54
+
55
+ # @return [String] `drilldown_output_columns` parameter value.
56
+ #
57
+ # @since 1.1.3
58
+ def drilldown_output_columns
59
+ self[:drilldown_output_columns]
60
+ end
61
+
62
+ # @return [String] `drilldown_offset` parameter value.
63
+ #
64
+ # @since 1.1.3
65
+ def drilldown_offset
66
+ integer_value(:drilldown_offset)
67
+ end
68
+
69
+ # @return [String] `drilldown_limit` parameter value.
70
+ #
71
+ # @since 1.1.3
72
+ def drilldown_limit
73
+ integer_value(:drilldown_limit)
74
+ end
75
+
76
+ # @return [String] `drilldown_calc_types` parameter value.
77
+ #
78
+ # @since 1.1.3
79
+ def drilldown_calc_types
80
+ self[:drilldown_calc_types]
81
+ end
82
+
83
+ # @return [String] `drilldown_calc_target` parameter value.
84
+ #
85
+ # @since 1.1.3
86
+ def drilldown_calc_target
87
+ self[:drilldown_calc_target]
88
+ end
89
+
90
+ # @return [::Hash<String, Drilldown>] The labeled drilldowns.
91
+ #
92
+ # @since 1.2.8
93
+ def labeled_drilldowns
94
+ @labeled_drilldowns ||= parse_labeled_drilldowns
95
+ end
96
+
97
+ private
98
+ def parse_labeled_drilldowns
99
+ raw_labeled_drilldowns = {}
100
+ @arguments.each do |name, value|
101
+ case name.to_s
102
+ when /\Adrilldowns?\[(.+?)\]\.(.+?)\z/
103
+ label = $1
104
+ parameter_name = $2
105
+ raw_labeled_drilldowns[label] ||= {}
106
+ raw_labeled_drilldowns[label][parameter_name] = value
107
+ end
108
+ end
109
+ build_labeled_drilldowns(raw_labeled_drilldowns)
110
+ end
111
+
112
+ def build_labeled_drilldowns(raw_labeled_drilldowns)
113
+ labeled_drilldowns = {}
114
+ raw_labeled_drilldowns.each do |label, raw_drilldown|
115
+ keys = parse_array_value(raw_drilldown["keys"])
116
+ sort_keys = raw_drilldown["sort_keys"] || raw_drilldown["sortby"]
117
+ sort_keys = parse_array_value(sort_keys)
118
+ output_columns = parse_array_value(raw_drilldown["output_columns"])
119
+ offset = parse_integer_value(raw_drilldown["offset"])
120
+ limit = parse_integer_value(raw_drilldown["limit"])
121
+ calc_types = parse_array_value(raw_drilldown["calc_types"])
122
+ calc_target = raw_drilldown["calc_target"]
123
+ filter = raw_drilldown["filter"]
124
+ drilldown = Drilldown.new(keys,
125
+ sort_keys,
126
+ output_columns,
127
+ offset,
128
+ limit,
129
+ calc_types,
130
+ calc_target,
131
+ filter,
132
+ label)
133
+ labeled_drilldowns[label] = drilldown
134
+ end
135
+ labeled_drilldowns
136
+ end
137
+
138
+ class Drilldown < Struct.new(:keys,
139
+ :sort_keys,
140
+ :output_columns,
141
+ :offset,
142
+ :limit,
143
+ :calc_types,
144
+ :calc_target,
145
+ :filter,
146
+ :label)
147
+ end
148
+ end
149
+ end
150
+ end
@@ -47,7 +47,9 @@ module Groonga
47
47
  #
48
48
  # @since 1.3.4
49
49
  def sort_hash_table?
50
- boolean_value(:sort_hash_table, false)
50
+ boolean_value(:sort_hash_table,
51
+ default: false,
52
+ invalid: false)
51
53
  end
52
54
  end
53
55
  end
@@ -70,7 +70,9 @@ module Groonga
70
70
  #
71
71
  # @since 1.3.0
72
72
  def output_ids?
73
- boolean_value(:output_ids, false)
73
+ boolean_value(:output_ids,
74
+ default: false,
75
+ invalid: false)
74
76
  end
75
77
 
76
78
  private
@@ -1,5 +1,6 @@
1
1
  # Copyright (C) 2015 Hiroshi Hatake <hatake@clear-code.com>
2
- # Copyright (C) 2018 Kouhei Sutou <kou@clear-code.com>
2
+ # Copyright (C) 2018-2019 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2019 Yasuhiro Horimoto <horimoto@clear-code.com>
3
4
  #
4
5
  # This library is free software; you can redistribute it and/or
5
6
  # modify it under the terms of the GNU Lesser General Public
@@ -44,6 +45,9 @@ module Groonga
44
45
  :limit,
45
46
  :filter,
46
47
  :output_columns,
48
+ :use_range_index,
49
+ :post_filter,
50
+ :sort_keys,
47
51
  ]
48
52
  end
49
53
  end
@@ -130,6 +134,30 @@ module Groonga
130
134
  def output_columns
131
135
  self[:output_columns]
132
136
  end
137
+
138
+ # @return [Boolean, nil] Whether force to use or not use range index.
139
+ # `nil` means that decided whether use range index automatically.
140
+ #
141
+ # @since 1.4.3
142
+ def use_range_index
143
+ boolean_value(:use_range_index,
144
+ default: nil,
145
+ invalid: nil)
146
+ end
147
+
148
+ # @return [String] `post_filter` parameter value.
149
+ #
150
+ # @since 1.4.3
151
+ def post_filter
152
+ self[:post_filter]
153
+ end
154
+
155
+ # @return [::Array<String>] The sort keys.
156
+ #
157
+ # @since 1.4.3
158
+ def sort_keys
159
+ parse_array_value(self[:sort_keys] || "")
160
+ end
133
161
  end
134
162
  end
135
163
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015-2018 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2015-2019 Sutou Kouhei <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -15,7 +15,9 @@
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
  require "groonga/command/base"
18
+ require "groonga/command/drilldownable"
18
19
  require "groonga/command/searchable"
20
+ require "groonga/command/sliceable"
19
21
 
20
22
  module Groonga
21
23
  module Command
@@ -23,7 +25,9 @@ module Groonga
23
25
  #
24
26
  # @since 1.1.3
25
27
  class LogicalSelect < Base
28
+ include Drilldownable
26
29
  include Searchable
30
+ include Sliceable
27
31
 
28
32
  class << self
29
33
  def command_name
@@ -50,6 +54,14 @@ module Groonga
50
54
  :drilldown_limit,
51
55
  :drilldown_calc_types,
52
56
  :drilldown_calc_target,
57
+ :sort_keys,
58
+ :drilldown_sort_keys,
59
+ :match_columns,
60
+ :query,
61
+ :drilldown_filter,
62
+ :load_table,
63
+ :load_columns,
64
+ :load_values,
53
65
  ]
54
66
  end
55
67
  end
@@ -133,60 +145,11 @@ module Groonga
133
145
  integer_value(:limit)
134
146
  end
135
147
 
136
- # @return [String] `drilldown` parameter value.
148
+ # @return [::Array<String>] The sort keys.
137
149
  #
138
- # @since 1.1.3
139
- def drilldown
140
- self[:drilldown]
141
- end
142
-
143
- # @return [Array<String>] drilldown keys.
144
- #
145
- # @since 1.1.3
146
- def drilldowns
147
- @drilldowns ||= array_value(:drilldown)
148
- end
149
-
150
- # @return [String] `drilldown_sortby` parameter value.
151
- #
152
- # @since 1.1.3
153
- def drilldown_sortby
154
- self[:drilldown_sortby]
155
- end
156
-
157
- # @return [String] `drilldown_output_columns` parameter value.
158
- #
159
- # @since 1.1.3
160
- def drilldown_output_columns
161
- self[:drilldown_output_columns]
162
- end
163
-
164
- # @return [String] `drilldown_offset` parameter value.
165
- #
166
- # @since 1.1.3
167
- def drilldown_offset
168
- integer_value(:drilldown_offset)
169
- end
170
-
171
- # @return [String] `drilldown_limit` parameter value.
172
- #
173
- # @since 1.1.3
174
- def drilldown_limit
175
- integer_value(:drilldown_limit)
176
- end
177
-
178
- # @return [String] `drilldown_calc_types` parameter value.
179
- #
180
- # @since 1.1.3
181
- def drilldown_calc_types
182
- self[:drilldown_calc_types]
183
- end
184
-
185
- # @return [String] `drilldown_calc_target` parameter value.
186
- #
187
- # @since 1.1.3
188
- def drilldown_calc_target
189
- self[:drilldown_calc_target]
150
+ # @since 1.4.2
151
+ def sort_keys
152
+ parse_array_value(self[:sort_keys] || self[:sortby] || "")
190
153
  end
191
154
  end
192
155
  end
@@ -48,7 +48,9 @@ module Groonga
48
48
  #
49
49
  # @since 1.1.7
50
50
  def force?
51
- boolean_value(:force, false)
51
+ boolean_value(:force,
52
+ default: false,
53
+ invalid: false)
52
54
  end
53
55
  end
54
56
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012-2018 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2012-2019 Sutou Kouhei <kou@clear-code.com>
2
2
  # Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
3
3
  #
4
4
  # This library is free software; you can redistribute it and/or
@@ -16,12 +16,16 @@
16
16
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
  require "groonga/command/base"
19
+ require "groonga/command/drilldownable"
19
20
  require "groonga/command/searchable"
21
+ require "groonga/command/sliceable"
20
22
 
21
23
  module Groonga
22
24
  module Command
23
25
  class Select < Base
26
+ include Drilldownable
24
27
  include Searchable
28
+ include Sliceable
25
29
 
26
30
  class << self
27
31
  def command_name
@@ -88,150 +92,12 @@ module Groonga
88
92
  self[:filter]
89
93
  end
90
94
 
91
- def drilldowns
92
- @drilldowns ||= array_value(:drilldown)
93
- end
94
-
95
- # @return [String, nil] The filter for the drilled down result.
96
- #
97
- # @since 1.3.3
98
- def drilldown_filter
99
- self[:drilldown_filter]
100
- end
101
-
102
- # @return [::Array<String>] The sort keys for drilldowns.
103
- #
104
- # @since 1.2.8
105
- def drilldown_sort_keys
106
- value = self[:drilldown_sort_keys] || self[:drilldown_sortby] || ""
107
- parse_array_value(value)
108
- end
109
-
110
- # @return [::Hash<String, Drilldown>] The labeled drilldowns.
111
- #
112
- # @since 1.2.8
113
- def labeled_drilldowns
114
- @labeled_drilldowns ||= parse_labeled_drilldowns
115
- end
116
-
117
- # @return [::Hash<String, Slice>] The slices.
118
- #
119
- # @since 1.3.0
120
- def slices
121
- @slices ||= parse_slices
122
- end
123
-
124
95
  # TODO: We should return `::Array` instead of raw
125
96
  # `output_columns` value. But it breaks backward
126
97
  # compatibility...
127
98
  def output_columns
128
99
  self[:output_columns]
129
100
  end
130
-
131
- private
132
- def parse_labeled_drilldowns
133
- raw_labeled_drilldowns = {}
134
- @arguments.each do |name, value|
135
- case name.to_s
136
- when /\Adrilldowns?\[(.+?)\]\.(.+?)\z/
137
- label = $1
138
- parameter_name = $2
139
- raw_labeled_drilldowns[label] ||= {}
140
- raw_labeled_drilldowns[label][parameter_name] = value
141
- end
142
- end
143
- build_labeled_drilldowns(raw_labeled_drilldowns)
144
- end
145
-
146
- def build_labeled_drilldowns(raw_labeled_drilldowns)
147
- labeled_drilldowns = {}
148
- raw_labeled_drilldowns.each do |label, raw_drilldown|
149
- keys = parse_array_value(raw_drilldown["keys"])
150
- sort_keys = raw_drilldown["sort_keys"] || raw_drilldown["sortby"]
151
- sort_keys = parse_array_value(sort_keys)
152
- output_columns = parse_array_value(raw_drilldown["output_columns"])
153
- offset = parse_integer_value(raw_drilldown["offset"])
154
- limit = parse_integer_value(raw_drilldown["limit"])
155
- calc_types = parse_array_value(raw_drilldown["calc_types"])
156
- calc_target = raw_drilldown["calc_target"]
157
- filter = raw_drilldown["filter"]
158
- drilldown = Drilldown.new(keys,
159
- sort_keys,
160
- output_columns,
161
- offset,
162
- limit,
163
- calc_types,
164
- calc_target,
165
- filter,
166
- label)
167
- labeled_drilldowns[label] = drilldown
168
- end
169
- labeled_drilldowns
170
- end
171
-
172
- def parse_slices
173
- raw_slices = {}
174
- @arguments.each do |name, value|
175
- case name.to_s
176
- when /\Aslices?\[(.+?)\]\.(.+?)\z/
177
- label = $1
178
- parameter_name = $2
179
- raw_slices[label] ||= {}
180
- raw_slices[label][parameter_name] = value
181
- end
182
- end
183
- build_slices(raw_slices)
184
- end
185
-
186
- def build_slices(raw_slices)
187
- slices = {}
188
- raw_slices.each do |label, raw_slice|
189
- match_columns = raw_slice["match_columns"]
190
- query = raw_slice["query"]
191
- query_expander = raw_slice["query_expander"]
192
- query_flags = parse_flags_value(raw_slice["query_flags"])
193
- filter = raw_slice["filter"]
194
- sort_keys = parse_array_value(raw_slice["sort_keys"])
195
- output_columns = parse_array_value(raw_slice["output_columns"])
196
- offset = parse_integer_value(raw_slice["offset"])
197
- limit = parse_integer_value(raw_slice["limit"])
198
- slices[label] = Slice.new(label,
199
- match_columns,
200
- query,
201
- query_expander,
202
- query_flags,
203
- filter,
204
- sort_keys,
205
- output_columns,
206
- offset,
207
- limit)
208
- end
209
- slices
210
- end
211
-
212
- class Drilldown < Struct.new(:keys,
213
- :sort_keys,
214
- :output_columns,
215
- :offset,
216
- :limit,
217
- :calc_types,
218
- :calc_target,
219
- :filter,
220
- :label)
221
- end
222
-
223
- # @since 1.3.1
224
- class Slice < Struct.new(:label,
225
- :match_columns,
226
- :query,
227
- :query_expander,
228
- :query_flags,
229
- :filter,
230
- :sort_keys,
231
- :output_columns,
232
- :offset,
233
- :limit)
234
- end
235
101
  end
236
102
  end
237
103
  end
@@ -0,0 +1,82 @@
1
+ # Copyright (C) 2019 Sutou Kouhei <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
+ module Groonga
18
+ module Command
19
+ module Sliceable
20
+ # @return [::Hash<String, Slice>] The slices.
21
+ #
22
+ # @since 1.3.0
23
+ def slices
24
+ @slices ||= parse_slices
25
+ end
26
+
27
+ private
28
+ def parse_slices
29
+ raw_slices = {}
30
+ @arguments.each do |name, value|
31
+ case name.to_s
32
+ when /\Aslices?\[(.+?)\]\.(.+?)\z/
33
+ label = $1
34
+ parameter_name = $2
35
+ raw_slices[label] ||= {}
36
+ raw_slices[label][parameter_name] = value
37
+ end
38
+ end
39
+ build_slices(raw_slices)
40
+ end
41
+
42
+ def build_slices(raw_slices)
43
+ slices = {}
44
+ raw_slices.each do |label, raw_slice|
45
+ match_columns = raw_slice["match_columns"]
46
+ query = raw_slice["query"]
47
+ query_expander = raw_slice["query_expander"]
48
+ query_flags = parse_flags_value(raw_slice["query_flags"])
49
+ filter = raw_slice["filter"]
50
+ sort_keys = parse_array_value(raw_slice["sort_keys"])
51
+ output_columns = parse_array_value(raw_slice["output_columns"])
52
+ offset = parse_integer_value(raw_slice["offset"])
53
+ limit = parse_integer_value(raw_slice["limit"])
54
+ slices[label] = Slice.new(label,
55
+ match_columns,
56
+ query,
57
+ query_expander,
58
+ query_flags,
59
+ filter,
60
+ sort_keys,
61
+ output_columns,
62
+ offset,
63
+ limit)
64
+ end
65
+ slices
66
+ end
67
+
68
+ # @since 1.3.1
69
+ class Slice < Struct.new(:label,
70
+ :match_columns,
71
+ :query,
72
+ :query_expander,
73
+ :query_flags,
74
+ :filter,
75
+ :sort_keys,
76
+ :output_columns,
77
+ :offset,
78
+ :limit)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Groonga
18
18
  module Command
19
- VERSION = "1.4.1"
19
+ VERSION = "1.4.4"
20
20
  end
21
21
  end
@@ -1,4 +1,6 @@
1
1
  # Copyright (C) 2015 Hiroshi Hatake <hatake@clear-code.com>
2
+ # Copyright (C) 2019 Yasuhiro Horimoto <horimoto@clear-code.com>
3
+ # Copyright (C) 2019 Sutou Kouhei <kou@clear-code.com>
2
4
  #
3
5
  # This library is free software; you can redistribute it and/or
4
6
  # modify it under the terms of the GNU Lesser General Public
@@ -23,17 +25,20 @@ class LogicalRangeFilterCommandTest < Test::Unit::TestCase
23
25
 
24
26
  class ConstructorTest < self
25
27
  def test_ordered_arguments
26
- logical_table = "Logs"
27
- shard_key = "timestamp",
28
- min = "2015-02-12 00:00:00"
29
- min_border = "include"
30
- max = "2015-02-13 00:00:00"
31
- max_border = "exclude"
32
- order = "ascending"
33
- offset = "10"
34
- limit = "20"
35
- filter = "value == 10"
36
- output_columns = "_key, timestamp"
28
+ logical_table = "Logs"
29
+ shard_key = "timestamp",
30
+ min = "2015-02-12 00:00:00"
31
+ min_border = "include"
32
+ max = "2015-02-13 00:00:00"
33
+ max_border = "exclude"
34
+ order = "ascending"
35
+ offset = "10"
36
+ limit = "20"
37
+ filter = "value == 10"
38
+ output_columns = "_key, timestamp"
39
+ use_range_index = "yes"
40
+ post_filter = "_score > 10"
41
+ sort_keys = "timestamp, -_score"
37
42
 
38
43
  ordered_arguments = [
39
44
  logical_table,
@@ -47,20 +52,26 @@ class LogicalRangeFilterCommandTest < Test::Unit::TestCase
47
52
  limit,
48
53
  filter,
49
54
  output_columns,
55
+ use_range_index,
56
+ post_filter,
57
+ sort_keys,
50
58
  ]
51
59
  command = logical_range_filter_command({}, ordered_arguments)
52
60
  assert_equal({
53
- :logical_table => logical_table,
54
- :shard_key => shard_key,
55
- :min => min,
56
- :min_border => min_border,
57
- :max => max,
58
- :max_border => max_border,
59
- :order => order,
60
- :offset => offset,
61
- :limit => limit,
62
- :filter => filter,
63
- :output_columns => output_columns,
61
+ :logical_table => logical_table,
62
+ :shard_key => shard_key,
63
+ :min => min,
64
+ :min_border => min_border,
65
+ :max => max,
66
+ :max_border => max_border,
67
+ :order => order,
68
+ :offset => offset,
69
+ :limit => limit,
70
+ :filter => filter,
71
+ :output_columns => output_columns,
72
+ :use_range_index => use_range_index,
73
+ :post_filter => post_filter,
74
+ :sort_keys => sort_keys,
64
75
  },
65
76
  command.arguments)
66
77
  end
@@ -135,4 +146,40 @@ class LogicalRangeFilterCommandTest < Test::Unit::TestCase
135
146
  assert_equal("_key, timestamp", command.output_columns)
136
147
  end
137
148
  end
149
+
150
+ class UseRangeIndexTest < self
151
+ def test_yes
152
+ command = logical_range_filter_command(:use_range_index => "yes")
153
+ assert_true(command.use_range_index)
154
+ end
155
+
156
+ def test_no
157
+ command = logical_range_filter_command(:use_range_index => "no")
158
+ assert_false(command.use_range_index)
159
+ end
160
+
161
+ def test_default
162
+ command = logical_range_filter_command
163
+ assert_nil(command.use_range_index)
164
+ end
165
+
166
+ def test_invalid
167
+ command = logical_range_filter_command(:use_range_index => "invalid")
168
+ assert_nil(command.use_range_index)
169
+ end
170
+ end
171
+
172
+ class PostFilterTest < self
173
+ def test_reader
174
+ command = logical_range_filter_command(:post_filter => "_score > 10")
175
+ assert_equal("_score > 10", command.post_filter)
176
+ end
177
+ end
178
+
179
+ class SortKeysTest < self
180
+ def test_reader
181
+ command = logical_range_filter_command(:sort_keys => "timestamp, -_score")
182
+ assert_equal(["timestamp", "-_score"], command.sort_keys)
183
+ end
184
+ end
138
185
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2015-2019 Sutou Kouhei <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -41,6 +41,7 @@ class LogicalSelectCommandTest < Test::Unit::TestCase
41
41
  drilldown_limit = "10"
42
42
  drilldown_calc_types = "MIN,AVG"
43
43
  drilldown_calc_target = "n_occurred"
44
+ sort_keys = "-_score"
44
45
 
45
46
  ordered_arguments = [
46
47
  logical_table,
@@ -61,6 +62,7 @@ class LogicalSelectCommandTest < Test::Unit::TestCase
61
62
  drilldown_limit,
62
63
  drilldown_calc_types,
63
64
  drilldown_calc_target,
65
+ sort_keys,
64
66
  ]
65
67
  command = logical_select_command({}, ordered_arguments)
66
68
  assert_equal({
@@ -82,6 +84,7 @@ class LogicalSelectCommandTest < Test::Unit::TestCase
82
84
  :drilldown_limit => drilldown_limit,
83
85
  :drilldown_calc_types => drilldown_calc_types,
84
86
  :drilldown_calc_target => drilldown_calc_target,
87
+ :sort_keys => sort_keys,
85
88
  },
86
89
  command.arguments)
87
90
  end
@@ -157,6 +160,13 @@ class LogicalSelectCommandTest < Test::Unit::TestCase
157
160
  end
158
161
  end
159
162
 
163
+ class SortKeysTest < self
164
+ def test_reader
165
+ command = logical_select_command(:sort_keys => "-_score, _key")
166
+ assert_equal(["-_score", "_key"], command.sort_keys)
167
+ end
168
+ end
169
+
160
170
  class DrilldownTest < self
161
171
  def test_reader
162
172
  command = logical_select_command(:drilldown => "name")
@@ -205,4 +215,139 @@ class LogicalSelectCommandTest < Test::Unit::TestCase
205
215
  assert_equal("n_occurred", command.drilldown_calc_target)
206
216
  end
207
217
  end
218
+
219
+ class DrilldownFilterTest < self
220
+ def test_reader
221
+ command = logical_select_command(:drilldown_filter => "_nsubrecs > 1")
222
+ assert_equal("_nsubrecs > 1",
223
+ command.drilldown_filter)
224
+ end
225
+ end
226
+
227
+ class DrilldownSortKeysTest < self
228
+ def test_reader
229
+ command = logical_select_command(:drilldown_sort_keys => "-_nsubrecs,_key")
230
+ assert_equal(["-_nsubrecs", "_key"],
231
+ command.drilldown_sort_keys)
232
+ end
233
+
234
+ def test_sortby
235
+ command = logical_select_command(:drilldown_sortby => "-_nsubrecs,_key")
236
+ assert_equal(["-_nsubrecs", "_key"],
237
+ command.drilldown_sort_keys)
238
+ end
239
+ end
240
+
241
+ class LabeledDrilldownsTest < self
242
+ def test_multiple
243
+ parameters = {
244
+ "drilldowns[tag].keys" => "tag",
245
+ "drilldowns[tag].sort_keys" => "-_nsubrecs,_key",
246
+ "drilldowns[tag].output_columns" => "_key,_nsubrecs,_min,_max",
247
+ "drilldowns[tag].offset" => "1",
248
+ "drilldowns[tag].limit" => "10",
249
+ "drilldowns[tag].calc_types" => "MIN,MAX",
250
+ "drilldowns[tag].calc_target" => "_nsubrecs",
251
+ "drilldowns[tag].filter" => "_nsubrecs > 1",
252
+
253
+ "drilldowns[author_tag].keys" => "author,tag",
254
+ "drilldowns[author_tag].sort_keys" => "_value.author",
255
+ "drilldowns[author_tag].output_columns" => "_value.author,_nsubrecs",
256
+ }
257
+ command = logical_select_command(parameters)
258
+ drilldowns = {
259
+ "author_tag" => drilldown(:label => "author_tag",
260
+ :keys => ["author", "tag"],
261
+ :sort_keys => ["_value.author"],
262
+ :output_columns => [
263
+ "_value.author",
264
+ "_nsubrecs",
265
+ ]),
266
+ "tag" => drilldown(:label => "tag",
267
+ :keys => ["tag"],
268
+ :sort_keys => ["-_nsubrecs", "_key"],
269
+ :output_columns => [
270
+ "_key",
271
+ "_nsubrecs",
272
+ "_min",
273
+ "_max",
274
+ ],
275
+ :offset => 1,
276
+ :limit => 10,
277
+ :calc_types => ["MIN", "MAX"],
278
+ :calc_target => "_nsubrecs",
279
+ :filter => "_nsubrecs > 1"),
280
+ }
281
+ assert_equal(drilldowns,
282
+ command.labeled_drilldowns)
283
+ end
284
+
285
+ def drilldown(parameters)
286
+ drilldown = Groonga::Command::LogicalSelect::Drilldown.new
287
+ parameters.each do |key, value|
288
+ drilldown[key] = value
289
+ end
290
+ drilldown
291
+ end
292
+ end
293
+
294
+ class SlicesTest < self
295
+ def test_full
296
+ parameters = {
297
+ "slices[book_alice].match_columns" => "tag",
298
+ "slices[book_alice].query" => "Book",
299
+ "slices[book_alice].query_expander" => "Synonyms.tag",
300
+ "slices[book_alice].query_flags" => "ALLOW_COLUMN|ALLOW_LEADING_NOT",
301
+ "slices[book_alice].filter" => "user == \"alice\"",
302
+ "slices[book_alice].sort_keys" => "_score, user",
303
+ "slices[book_alice].offset" => "10",
304
+ "slices[book_alice].limit" => "25",
305
+ }
306
+ command = logical_select_command(parameters)
307
+
308
+ slices = {
309
+ "book_alice" => slice(:label => "book_alice",
310
+ :match_columns => "tag",
311
+ :query => "Book",
312
+ :query_expander => "Synonyms.tag",
313
+ :query_flags => [
314
+ "ALLOW_COLUMN",
315
+ "ALLOW_LEADING_NOT",
316
+ ],
317
+ :filter => "user == \"alice\"",
318
+ :sort_keys => ["_score", "user"],
319
+ :offset => 10,
320
+ :limit => 25),
321
+ }
322
+ assert_equal(slices, command.slices)
323
+ end
324
+
325
+ def test_multiple
326
+ parameters = {
327
+ "slices[groonga].query" => "tag:Groonga",
328
+ "slices[rroonga].filter" => "tag == Rroonga",
329
+ "slices[rroonga].sort_keys" => "date",
330
+ "slices[rroonga].output_columns" => "_key, date",
331
+ }
332
+ command = logical_select_command(parameters)
333
+
334
+ slices = {
335
+ "groonga" => slice(:label => "groonga",
336
+ :query => "tag:Groonga"),
337
+ "rroonga" => slice(:label => "rroonga",
338
+ :filter => "tag == Rroonga",
339
+ :sort_keys => ["date"],
340
+ :output_columns => ["_key", "date"]),
341
+ }
342
+ assert_equal(slices, command.slices)
343
+ end
344
+
345
+ def slice(parameters)
346
+ slice = Groonga::Command::LogicalSelect::Slice.new
347
+ parameters.each do |key, value|
348
+ slice[key] = value
349
+ end
350
+ slice
351
+ end
352
+ end
208
353
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2015-2019 Sutou Kouhei <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -42,4 +42,22 @@ class PluginUnregisterCommandTest < Test::Unit::TestCase
42
42
  assert_equal("query_expanders/tsv", command.name)
43
43
  end
44
44
  end
45
+
46
+ class EqualTest < self
47
+ def test_equal
48
+ command1 = plugin_unregister_command(:name => "query_expanders/tsv")
49
+ command2 = plugin_unregister_command(:name => "query_expanders/tsv")
50
+ assert do
51
+ command1 == command2
52
+ end
53
+ end
54
+
55
+ def test_not_equal
56
+ command1 = plugin_unregister_command(:name => "query_expanders/tsv")
57
+ command2 = plugin_unregister_command(:name => "functions/vector")
58
+ assert do
59
+ command1 != command2
60
+ end
61
+ end
62
+ end
45
63
  end
@@ -158,6 +158,55 @@ class SelectCommandTest < Test::Unit::TestCase
158
158
  end
159
159
  end
160
160
 
161
+ class DrilldownTest < self
162
+ def test_reader
163
+ command = select_command(:drilldown => "name")
164
+ assert_equal("name", command.drilldown)
165
+ end
166
+ end
167
+
168
+ class DrilldownSortbyTest < self
169
+ def test_reader
170
+ command = select_command(:drilldown_sortby => "_nsubrecs")
171
+ assert_equal("_nsubrecs", command.drilldown_sortby)
172
+ end
173
+ end
174
+
175
+ class DrilldownOutputColumnsTest < self
176
+ def test_reader
177
+ command = select_command(:drilldown_output_columns => "name, _nsubrecs")
178
+ assert_equal("name, _nsubrecs", command.drilldown_output_columns)
179
+ end
180
+ end
181
+
182
+ class DrilldownOffsetTest < self
183
+ def test_reader
184
+ command = select_command(:drilldown_offset => "5")
185
+ assert_equal(5, command.drilldown_offset)
186
+ end
187
+ end
188
+
189
+ class DrilldownLimitTest < self
190
+ def test_reader
191
+ command = select_command(:drilldown_limit => "10")
192
+ assert_equal(10, command.drilldown_limit)
193
+ end
194
+ end
195
+
196
+ class DrilldownCalcTypesTest < self
197
+ def test_reader
198
+ command = select_command(:drilldown_calc_types => "MIN,AVG")
199
+ assert_equal("MIN,AVG", command.drilldown_calc_types)
200
+ end
201
+ end
202
+
203
+ class DrilldownCalcTargetTest < self
204
+ def test_reader
205
+ command = select_command(:drilldown_calc_target => "n_occurred")
206
+ assert_equal("n_occurred", command.drilldown_calc_target)
207
+ end
208
+ end
209
+
161
210
  class DrilldownFilterTest < self
162
211
  def test_reader
163
212
  command = select_command(:drilldown_filter => "_nsubrecs > 1")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-26 00:00:00.000000000 Z
11
+ date: 2019-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -147,6 +147,7 @@ files:
147
147
  - lib/groonga/command/config-get.rb
148
148
  - lib/groonga/command/config-set.rb
149
149
  - lib/groonga/command/delete.rb
150
+ - lib/groonga/command/drilldownable.rb
150
151
  - lib/groonga/command/dump.rb
151
152
  - lib/groonga/command/error.rb
152
153
  - lib/groonga/command/format/command.rb
@@ -184,6 +185,7 @@ files:
184
185
  - lib/groonga/command/searchable.rb
185
186
  - lib/groonga/command/select.rb
186
187
  - lib/groonga/command/shutdown.rb
188
+ - lib/groonga/command/sliceable.rb
187
189
  - lib/groonga/command/status.rb
188
190
  - lib/groonga/command/suggest.rb
189
191
  - lib/groonga/command/table-copy.rb
@@ -272,65 +274,65 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
274
  version: '0'
273
275
  requirements: []
274
276
  rubyforge_project:
275
- rubygems_version: 2.5.2.1
277
+ rubygems_version: 2.7.6.2
276
278
  signing_key:
277
279
  specification_version: 4
278
280
  summary: Groonga-command is a library that represents [Groonga](http://groonga.org/)'s
279
281
  command. You can write a program that handle Groonga's command by using groonga-command.
280
282
  test_files:
281
283
  - test/run-test.rb
282
- - test/groonga-command-test-utils.rb
283
- - test/command/test-query-log-flags-add.rb
284
- - test/command/test-log-put.rb
285
- - test/command/test-column-create.rb
284
+ - test/command/test-range-filter.rb
285
+ - test/command/test-column-rename.rb
286
+ - test/command/test-object-exist.rb
286
287
  - test/command/test-config-get.rb
287
- - test/command/test-logical-select.rb
288
- - test/command/test-plugin-register.rb
289
- - test/command/test-io-flush.rb
290
- - test/command/test-column-remove.rb
291
- - test/command/test-query-expand.rb
292
- - test/command/test-logical-count.rb
293
- - test/command/test-log-level.rb
294
- - test/command/test-shutdown.rb
295
- - test/command/test-column-copy.rb
296
- - test/command/test-suggest.rb
297
- - test/command/test-get.rb
298
- - test/command/test-index-column-diff.rb
299
- - test/command/test-logical-shard-list.rb
300
288
  - test/command/test-table-create.rb
301
- - test/command/test-logical-table-remove.rb
289
+ - test/command/test-plugin-register.rb
290
+ - test/command/test-query-log-flags-remove.rb
291
+ - test/command/format/test-command.rb
292
+ - test/command/test-table-rename.rb
293
+ - test/command/test-truncate.rb
294
+ - test/command/test-log-put.rb
302
295
  - test/command/test-query-log-flags-get.rb
303
296
  - test/command/test-query-log-flags-set.rb
304
- - test/command/test-plugin-unregister.rb
305
- - test/command/test-delete.rb
306
- - test/command/test-status.rb
307
297
  - test/command/test-logical-range-filter.rb
308
298
  - test/command/test-column-list.rb
299
+ - test/command/test-ruby-load.rb
300
+ - test/command/test-query-log-flags-add.rb
301
+ - test/command/test-table-copy.rb
309
302
  - test/command/test-config-delete.rb
310
- - test/command/test-dump.rb
311
- - test/command/format/test-command.rb
303
+ - test/command/test-logical-select.rb
312
304
  - test/command/test-tokenize.rb
313
305
  - test/command/test-table-tokenize.rb
314
- - test/command/test-table-rename.rb
315
- - test/command/test-object-remove.rb
316
- - test/command/test-range-filter.rb
317
- - test/command/test-table-copy.rb
318
- - test/command/test-query-log-flags-remove.rb
319
- - test/command/test-column-rename.rb
320
- - test/command/test-config-set.rb
321
- - test/command/test-thread-limit.rb
322
- - test/command/test-select.rb
323
- - test/command/test-reindex.rb
324
- - test/command/test-schema.rb
325
- - test/command/test-truncate.rb
326
- - test/command/test-ruby-eval.rb
327
- - test/command/test-ruby-load.rb
328
306
  - test/command/test-request-cancel.rb
329
- - test/command/test-table-list.rb
307
+ - test/command/test-column-copy.rb
308
+ - test/command/test-suggest.rb
309
+ - test/command/test-column-remove.rb
310
+ - test/command/test-object-remove.rb
311
+ - test/command/test-logical-shard-list.rb
312
+ - test/command/test-column-create.rb
313
+ - test/command/test-get.rb
330
314
  - test/command/test-load.rb
331
- - test/command/test-object-inspect.rb
315
+ - test/command/test-reindex.rb
316
+ - test/command/test-plugin-unregister.rb
317
+ - test/command/test-io-flush.rb
318
+ - test/command/test-logical-table-remove.rb
319
+ - test/command/test-index-column-diff.rb
332
320
  - test/command/test-register.rb
333
- - test/command/test-base.rb
334
- - test/command/test-object-exist.rb
321
+ - test/command/test-object-inspect.rb
322
+ - test/command/test-delete.rb
323
+ - test/command/test-query-expand.rb
324
+ - test/command/test-table-list.rb
325
+ - test/command/test-status.rb
326
+ - test/command/test-thread-limit.rb
327
+ - test/command/test-config-set.rb
328
+ - test/command/test-log-level.rb
329
+ - test/command/test-shutdown.rb
330
+ - test/command/test-ruby-eval.rb
331
+ - test/command/test-schema.rb
335
332
  - test/command/test-normalize.rb
333
+ - test/command/test-dump.rb
334
+ - test/command/test-base.rb
335
+ - test/command/test-logical-count.rb
336
336
  - test/command/test-table-remove.rb
337
+ - test/command/test-select.rb
338
+ - test/groonga-command-test-utils.rb