class Groonga::Client::Request::Select::Filter
Public Class Methods
@private
# File lib/groonga/client/request/select.rb, line 322 def column_namify(column_name, ith, signature) return column_name unless column_name.is_a?(String) message = "column name (the #{ith} argument) of #{signature} " message << "should be Symbol: #{column_name.inspect}: " message << caller(2, 1)[0] warn(message) column_name.to_sym end
# File lib/groonga/client/request/select.rb, line 333 def initialize(request) @request = request end
Public Instance Methods
Adds a ‘between` condition then returns a new `select` request object.
@see groonga.org/docs/reference/functions/between.html
between function in the Groonga document
@return [Groonga::Client::Request::Select]
The new request with the given condition.
@overload between(column_name, min, max, min_border: “include”, max_border: “include”)
@example Basic usage request. filter.between(:age, 19, 32) # -> --filter 'between(age, 19, "include", 32, "exclude")' @!macro [new] between_common @param column_name [Symbol] The target column name. @param min [Integer] The minimal value of the condition range. @param max [Integer] The maximum value of the condition range. @param min_border ["include", "exclude"] Whether `min` is included or not. If `"include"` is specified, `min` is included. If `"exclude"` is specified, `min` isn't included. @param max_border ["include", "exclude"] Whether `max` is included or not. If `"include"` is specified, `max` is included. If `"exclude"` is specified, `max` isn't included. @macro between_common @since 0.5.0
@overload between(column_name, min, min_border, max, max_border)
@example Basic usage request. filter.between(:age, 19, "include", 32, "exclude") # -> --filter 'between(age, 19, "include", 32, "exclude")' @macro between_common @since 0.4.4
# File lib/groonga/client/request/select.rb, line 505 def between(*args) n_args = args.size case n_args when 3 column_name, min, max = args min_border = "include" max_border = "include" when 4 column_name, min, max, options = args min_border = options[:min_border] || "include" max_border = options[:max_border] || "include" when 5 column_name, min, min_border, max, max_border = args else message = "wrong number of arguments (given #{n_args}, expected 3..5)" raise ArgumentError, message end # TODO: Accept not only column name but also literal as # the first argument. column_name = self.class.column_namify(column_name, "first", "#{self.class}\##{__method__}") expression = "between(%{column_name}" expression << ", %{min}" expression << ", %{min_border}" expression << ", %{max}" expression << ", %{max_border}" expression << ")" @request.filter(expression, column_name: column_name, min: min, min_border: min_border, max: max, max_border: max_border) end
Adds a ‘geo_in_circle` condition then returns a new `select` request object.
@see groonga.org/docs/reference/functions/geo_in_circle.html
geo_in_circle function in the Groonga document
@overload geo_in_circle
(column_name, center, radius, approximate_type=“rectangle”)
@example Basic usage request. filter.geo_in_circle(:location, "100x100", 300). # -> --filter 'geo_in_circle(location, "100x100", 300, "rectangle")' @param column_name [Symbol] The column name to be checked. @!macro [new] geo_in_circle_common @param center [String] The center point of the condition circle. `"#{LONGITUDE}x#{LATITUDE}"` is the point format. @param radius [Integer] The radius of the condition circle. @param approximate_type ["rectangle", "sphere", "ellipsoid"] ("rectangle") How to approximate geography to compute radius. The default is `"rectangle"`. @return [Groonga::Client::Request::Select] The new request with the given condition. @macro geo_in_circle_common
@overload geo_in_circle
(point, center, radius, approximate_type=“rectangle”)
@example Basic usage request. filter.geo_in_circle("0x0", "100x100", 300). # -> --filter 'geo_in_circle("0x0", "100x100", 300, "rectangle")' @param point [String] The point to be checked. `"#{LONGITUDE}x#{LATITUDE}"` is the point format. @macro geo_in_circle_common
@since 0.5.0
# File lib/groonga/client/request/select.rb, line 439 def geo_in_circle(column_name_or_point, center, radius_or_point, approximate_type="rectangle") expression = "geo_in_circle(%{column_name_or_point}" expression << ", %{center}" expression << ", %{radius_or_point}" expression << ", %{approximate_type}" expression << ")" @request.filter(expression, column_name_or_point: column_name_or_point, center: center, radius_or_point: radius_or_point, approximate_type: approximate_type) end
Adds a ‘geo_in_rectangle` condition then return a new `select` request object.
@see groonga.org/docs/reference/functions/geo_in_rectangle.html
geo_in_rectangle function in the Groonga document
@overload geo_in_rectangle
(column_name, top_left, bottom_right)
@example: Basic usage request. filter.geo_in_rectangle(:location, "0x100", "100x0"). # -> --filter 'geo_in_rectangle(location, "0x100", "100x0")' @param column_name [Symbol] The column name to be checked. @!macro [new] geo_in_rectangle @param top_left [String] The top left of the condition rectangle. `"#{LONGITUDE}x#{LATITUDE}"` is the point format. @param bottom_right [String] The bottom right of the condition rectangle. `"#{LONGITUDE}x#{LATITUDE}"` is the point format. @return [Groonga::Client::Request::Select] The new request with the given condition. @macro geo_in_rectangle
@overload geo_in_rectangle
(point, top_left, bottom_right)
@example Basic usage request. filter.geo_in_rectangle("50x50", "0x100", "100x0"). # -> --filter 'geo_in_rectangle("50x50", "0x100", "100x0")' @param point [String] The point to be checked. `"#{LONGITUDE}x#{LATITUDE}"` is the point format. @macro geo_in_rectangle
@since 0.5.0
# File lib/groonga/client/request/select.rb, line 378 def geo_in_rectangle(column_name_or_point, top_left, bottom_right) expression = "geo_in_rectangle(%{column_name_or_point}" expression << ", %{top_left}" expression << ", %{bottom_right}" expression << ")" @request.filter(expression, column_name_or_point: column_name_or_point, top_left: top_left, bottom_right: bottom_right) end
Adds a ‘in_values` condition then returns a new `select` request object.
@example Multiple conditions
request. filter.in_values(:tags, "tag1", "tag2"). # -> --filter 'in_values(tags, "tag1", "tag2")' filter("user", "alice") # -> --filter '(in_values(tags, "tag1", "tag2")) && (user == "alice")'
@example Ignore no values case
request. filter.in_values(:tags) # -> --filter ''
@see groonga.org/docs/reference/functions/in_values.html
`in_values` function in the Groonga document
@param column_name [Symbol] The target column name.
@param values [Object] The column values that cover target
column values.
@return [Groonga::Client::Request::Select]
The new request with the given condition.
@since 0.4.3
# File lib/groonga/client/request/select.rb, line 571 def in_values(column_name, *values) return @request if values.empty? # TODO: Accept not only column name but also literal as # the first argument. column_name = self.class.column_namify(column_name, "first", "#{self.class}\##{__method__}") expression_values = {column_name: column_name} expression = "in_values(%{column_name}" values.each_with_index do |value, i| expression << ", %{value#{i}}" expression_values[:"value#{i}"] = value end expression << ")" @request.filter(expression, expression_values) end