Class: Groonga::Client::Request::Select::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/client/request/select.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Filter

Returns a new instance of Filter.



333
334
335
# File 'lib/groonga/client/request/select.rb', line 333

def initialize(request)
  @request = request
end

Class Method Details

.column_namify(column_name, ith, signature) ⇒ Object



322
323
324
325
326
327
328
329
330
# 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

Instance Method Details

#between(column_name, min, max, min_border: "include", max_border: "include") ⇒ Groonga::Client::Request::Select #between(column_name, min, min_border, max, max_border) ⇒ Groonga::Client::Request::Select

Adds a between condition then returns a new select request object.

Overloads:

  • #between(column_name, min, max, min_border: "include", max_border: "include") ⇒ Groonga::Client::Request::Select

    Examples:

    Basic usage

    request.
      filter.between(:age, 19, 32)
        # -> --filter 'between(age, 19, "include", 32, "exclude")'

    Parameters:

    • column_name (Symbol)

      The target column name.

    • min (Integer)

      The minimal value of the condition range.

    • max (Integer)

      The maximum value of the condition range.

    • min_border ("include", "exclude") (defaults to: "include")

      Whether min is included or not. If "include" is specified, min is included. If "exclude" is specified, min isn't included.

    • max_border ("include", "exclude") (defaults to: "include")

      Whether max is included or not. If "include" is specified, max is included. If "exclude" is specified, max isn't included.

    Since:

    • 0.5.0

  • #between(column_name, min, min_border, max, max_border) ⇒ Groonga::Client::Request::Select

    Examples:

    Basic usage

    request.
      filter.between(:age, 19, "include", 32, "exclude")
        # -> --filter 'between(age, 19, "include", 32, "exclude")'

    Parameters:

    • column_name (Symbol)

      The target column name.

    • min (Integer)

      The minimal value of the condition range.

    • max (Integer)

      The maximum value of the condition range.

    • 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.

    • 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.

    Since:

    • 0.4.4

Returns:

See Also:



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# 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

#geo_in_circle(column_name, center, radius, approximate_type = "rectangle") ⇒ Groonga::Client::Request::Select #geo_in_circle(point, center, radius, approximate_type = "rectangle") ⇒ Groonga::Client::Request::Select

Adds a geo_in_circle condition then returns a new select request object.

Overloads:

  • #geo_in_circle(column_name, center, radius, approximate_type = "rectangle") ⇒ Groonga::Client::Request::Select

    Returns The new request with the given condition.

    Examples:

    Basic usage

    request.
      filter.geo_in_circle(:location, "100x100", 300).
        # -> --filter 'geo_in_circle(location, "100x100", 300, "rectangle")'

    Parameters:

    • column_name (Symbol)

      The column name to be checked.

    • center (String)

      The center point of the condition circle. "#{LONGITUDE}x#{LATITUDE}" is the point format.

    • radius (Integer)

      The radius of the condition circle.

    • approximate_type (defaults to: "rectangle")

      "rectangle", "sphere", "ellipsoid"

      How to approximate geography to compute radius.

      The default is "rectangle".

    Returns:

  • #geo_in_circle(point, center, radius, approximate_type = "rectangle") ⇒ Groonga::Client::Request::Select

    Returns The new request with the given condition.

    Examples:

    Basic usage

    request.
      filter.geo_in_circle("0x0", "100x100", 300).
        # -> --filter 'geo_in_circle("0x0", "100x100", 300, "rectangle")'

    Parameters:

    • point (String)

      The point to be checked. "#{LONGITUDE}x#{LATITUDE}" is the point format.

    • center (String)

      The center point of the condition circle. "#{LONGITUDE}x#{LATITUDE}" is the point format.

    • radius (Integer)

      The radius of the condition circle.

    • approximate_type (defaults to: "rectangle")

      "rectangle", "sphere", "ellipsoid"

      How to approximate geography to compute radius.

      The default is "rectangle".

    Returns:

See Also:

Since:

  • 0.5.0



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# 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

#geo_in_rectangle(column_name, top_left, bottom_right) ⇒ Groonga::Client::Request::Select #geo_in_rectangle(point, top_left, bottom_right) ⇒ Groonga::Client::Request::Select

Adds a geo_in_rectangle condition then return a new select request object.

Overloads:

  • #geo_in_rectangle(column_name, top_left, bottom_right) ⇒ Groonga::Client::Request::Select

    @example: Basic usage request. filter.geo_in_rectangle(:location, "0x100", "100x0"). # -> --filter 'geo_in_rectangle(location, "0x100", "100x0")'

    Parameters:

    • column_name (Symbol)

      The column name to be checked.

    • top_left (String)

      The top left of the condition rectangle. "#{LONGITUDE}x#{LATITUDE}" is the point format.

    • bottom_right (String)

      The bottom right of the condition rectangle. "#{LONGITUDE}x#{LATITUDE}" is the point format.

    Returns:

  • #geo_in_rectangle(point, top_left, bottom_right) ⇒ Groonga::Client::Request::Select

    Returns The new request with the given condition.

    Examples:

    Basic usage

    request.
      filter.geo_in_rectangle("50x50", "0x100", "100x0").
        # -> --filter 'geo_in_rectangle("50x50", "0x100", "100x0")'

    Parameters:

    • point (String)

      The point to be checked. "#{LONGITUDE}x#{LATITUDE}" is the point format.

    • top_left (String)

      The top left of the condition rectangle. "#{LONGITUDE}x#{LATITUDE}" is the point format.

    • bottom_right (String)

      The bottom right of the condition rectangle. "#{LONGITUDE}x#{LATITUDE}" is the point format.

    Returns:

See Also:

Since:

  • 0.5.0



378
379
380
381
382
383
384
385
386
387
388
# 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

#in_values(column_name, *values) ⇒ Groonga::Client::Request::Select

Adds a in_values condition then returns a new select request object.

Examples:

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")'

Ignore no values case

request.
  filter.in_values(:tags)
    # -> --filter ''

Parameters:

  • column_name (Symbol)

    The target column name.

  • values (Object)

    The column values that cover target column values.

Returns:

See Also:

Since:

  • 0.4.3



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
# 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