Class: Redis::Commands::Search::Predicate

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/commands/modules/search/query.rb

Overview

Abstract base for a single query-string predicate. Subclasses render themselves into a query-string fragment via #to_s.

Constant Summary collapse

TEXT_SPECIAL_CHARACTERS =

RediSearch query operators/metacharacters. Escaped with a backslash so an interpolated value is matched literally instead of altering (or breaking) the query.

[
  ',', '.', '<', '>', '{', '}', '[', ']', '"', "'", ':', ';', '!', '@',
  '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '~', '|', '/', '\\'
].freeze
TAG_SPECIAL_CHARACTERS =

TAG values are single literal tokens, so whitespace is significant and must be escaped too. TEXT queries keep spaces, which separate terms (a multi-word match is an AND).

(TEXT_SPECIAL_CHARACTERS + [' ']).freeze
TEXT_ESCAPE_PATTERN =
Regexp.union(TEXT_SPECIAL_CHARACTERS)
TAG_ESCAPE_PATTERN =
Regexp.union(TAG_SPECIAL_CHARACTERS)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ Predicate

Returns a new instance of Predicate.

Parameters:

  • field (String)

    the field name



630
631
632
# File 'lib/redis/commands/modules/search/query.rb', line 630

def initialize(field)
  @field = field
end

Instance Attribute Details

#fieldString (readonly)

Returns the field the predicate applies to.

Returns:

  • (String)

    the field the predicate applies to



615
616
617
# File 'lib/redis/commands/modules/search/query.rb', line 615

def field
  @field
end

Instance Method Details

#to_sString

Returns the query-string fragment.

Returns:

  • (String)

    the query-string fragment

Raises:

  • (NotImplementedError)

    always; subclasses must override



636
637
638
# File 'lib/redis/commands/modules/search/query.rb', line 636

def to_s
  raise NotImplementedError
end