123456789_123456789_123456789_123456789_123456789_

Class: Redis::Commands::Search::TextMatchPredicate

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Predicate
Instance Chain:
self, Predicate
Inherits: Redis::Commands::Search::Predicate
Defined in: lib/redis/commands/modules/search/query.rb

Overview

A text-match predicate rendering (@field:(pattern)).

Constant Summary

Predicate - Inherited

TAG_ESCAPE_PATTERN, TAG_SPECIAL_CHARACTERS, TEXT_ESCAPE_PATTERN, TEXT_SPECIAL_CHARACTERS

Class Method Summary

Instance Attribute Summary

Predicate - Inherited

Instance Method Summary

Predicate - Inherited

#to_s,
#escape_tag

Escape query metacharacters in a literal tag value, including whitespace.

#escape_text

Escape query metacharacters in a literal text value, keeping spaces as term separators.

Constructor Details

.new(field, pattern, raw: false) ⇒ TextMatchPredicate

Parameters:

  • field (String)

    the text field name

  • pattern (String)

    the text pattern to match

  • raw (Boolean)

    when true the pattern is interpolated verbatim so RediSearch operators (wildcards, {|} OR, ...) apply; when false (default) metacharacters are escaped and the pattern is matched literally

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/query.rb', line 675

def initialize(field, pattern, raw: false)
  super(field)
  @pattern = pattern
  @raw = raw
end

Instance Method Details

#to_sString

Returns:

  • (String)

    the query-string fragment, e.g. (@title:(hello world))

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/query.rb', line 682

def to_s
  # Group the pattern: RediSearch scopes "@field:" only to the term immediately after it,
  # so a bare "@title:hello world" would match "hello" on the field but "world" globally
  # (across all fields). Wrapping in parentheses scopes the whole pattern to the field;
  # it is a no-op for single-term patterns. Unless raw, escape metacharacters so a value
  # can't inject query syntax.
  pattern = @raw ? @pattern : escape_text(@pattern)
  "(@#{@field}:(#{pattern}))"
end