Class: Groonga::Client::Request::Select
- Inherits:
-
Generic
- Object
- Generic
- Groonga::Client::Request::Select
show all
- Includes:
- Enumerable
- Defined in:
- lib/groonga/client/request/select.rb
Defined Under Namespace
Modules: ScriptSyntaxValueEscapable
Classes: BackwardCompatibleSortKeysParameter, DynamicColumn, DynamicColumnWindow, Filter, FilterExpressionParameter, FilterMerger, LabeledDrilldown, OutputColumnsParameter, QueryMerger, ScorerExpressionParameter, ScriptSyntaxExpressionParameter, SortKeysParameter
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Generic
#command_name, #extensions, #flags_parameter, #parameter, #response, #to_parameters, #values_parameter
Constructor Details
#initialize(table_or_parameters, extensions = []) ⇒ Select
Returns a new instance of Select.
31
32
33
34
35
36
37
38
39
|
# File 'lib/groonga/client/request/select.rb', line 31
def initialize(table_or_parameters, extensions=[])
if table_or_parameters.respond_to?(:to_parameters)
parameters = table_or_parameters
else
table_name = table_or_parameters
parameters = RequestParameter.new(:table, table_name)
end
super(parameters, extensions)
end
|
Class Method Details
.command_name ⇒ Object
24
25
26
|
# File 'lib/groonga/client/request/select.rb', line 24
def command_name
"select"
end
|
Instance Method Details
#columns(label) ⇒ Object
296
297
298
|
# File 'lib/groonga/client/request/select.rb', line 296
def columns(label)
DynamicColumn.new(self, label)
end
|
#drilldowns(label) ⇒ Object
292
293
294
|
# File 'lib/groonga/client/request/select.rb', line 292
def drilldowns(label)
LabeledDrilldown.new(self, label)
end
|
#each(&block) ⇒ Object
300
301
302
|
# File 'lib/groonga/client/request/select.rb', line 300
def each(&block)
response.records.each(&block)
end
|
Adds a script syntax condition. If the request already has
any filter condition, they are combined by AND.
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/groonga/client/request/select.rb', line 163
def filter(*args)
n_args = args.size
case n_args
when 0
Filter.new(self)
when 1, 2
expression_or_column_name, values_or_value = *args
if values_or_value.nil? or values_or_value.is_a?(::Hash)
expression = expression_or_column_name
values = values_or_value
else
expression = "%{column} == %{value}"
column_name = expression_or_column_name
column_name = Filter.column_namify(column_name,
"first",
"#{self.class}\##{__method__}")
values = {
column: column_name,
value: values_or_value,
}
end
parameter = FilterExpressionParameter.new(expression, values)
add_parameter(FilterMerger, parameter)
else
message =
"wrong number of arguments (given #{n_args}, expected 0..2)"
raise ArgumentError, message
end
end
|
#limit(value) ⇒ Object
274
275
276
|
# File 'lib/groonga/client/request/select.rb', line 274
def limit(value)
parameter(:limit, value)
end
|
#match_columns(values) ⇒ Object
41
42
43
|
# File 'lib/groonga/client/request/select.rb', line 41
def match_columns(values)
values_parameter([:match_columns], values)
end
|
#offset(value) ⇒ Object
270
271
272
|
# File 'lib/groonga/client/request/select.rb', line 270
def offset(value)
parameter(:offset, value)
end
|
#output_columns(value) ⇒ Object
#paginate(page, per_page: 10) ⇒ Object
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'lib/groonga/client/request/select.rb', line 278
def paginate(page, per_page: 10)
page ||= 1
page = page.to_i
per_page = per_page.to_i
per_page = 10 if per_page <= 0
if page <= 0
offset = 0
else
offset = per_page * (page - 1)
end
offset(offset).limit(per_page)
end
|
#query(value) ⇒ Object
45
46
47
48
|
# File 'lib/groonga/client/request/select.rb', line 45
def query(value)
add_parameter(QueryMerger,
RequestParameter.new(:query, value))
end
|
Sets flags to custom how to parse query.
94
95
96
|
# File 'lib/groonga/client/request/select.rb', line 94
def query_flags(value)
flags_parameter(:query_flags, value)
end
|
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'lib/groonga/client/request/select.rb', line 235
def scorer(expression_or_column_name, values=nil)
case expression_or_column_name
when Symbol
expression = "_score = %{column}"
column_name = expression_or_column_name
values = { column: column_name }
when String
expression = expression_or_column_name
case expression
when /\A\s*\z/
expression = nil
when /\A[_a-zA-Z\d]+\s*=/
else
expression = "_score = #{expression}"
end
else
expression = expression_or_column_name
end
add_parameter(OverwriteMerger,
ScorerExpressionParameter.new(expression, values))
end
|
#sort_keys(value) ⇒ Object
Also known as:
sortby, sort