Class: Redis::Commands::Search::Predicate
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Inherits: | Object |
| 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
-
TAG_ESCAPE_PATTERN =
# File 'lib/redis/commands/modules/search/query.rb', line 627Regexp.union(TAG_SPECIAL_CHARACTERS)
-
TAG_SPECIAL_CHARACTERS =
# File 'lib/redis/commands/modules/search/query.rb', line 625
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 =
# File 'lib/redis/commands/modules/search/query.rb', line 626Regexp.union(TEXT_SPECIAL_CHARACTERS)
-
TEXT_SPECIAL_CHARACTERS =
# File 'lib/redis/commands/modules/search/query.rb', line 619
RediSearch query operators/metacharacters. Escaped with a backslash so an interpolated value is matched literally instead of altering (or breaking) the query.
[ ',', '.', '<', '>', '{', '}', '[', ']', '"', "'", ':', ';', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '~', '|', '/', '\\' ].freeze
Class Method Summary
- .new(field) ⇒ Predicate constructor
Instance Attribute Summary
- #field ⇒ String readonly
Instance Method Summary
- #to_s ⇒ String
-
#escape_tag(value)
private
Escape query metacharacters in a literal tag value, including whitespace.
-
#escape_text(value)
private
Escape query metacharacters in a literal text value, keeping spaces as term separators.
Constructor Details
.new(field) ⇒ Predicate
Instance Attribute Details
#field ⇒ String (readonly)
# File 'lib/redis/commands/modules/search/query.rb', line 615
attr_reader :field
Instance Method Details
#escape_tag(value) (private)
Escape query metacharacters in a literal tag value, including whitespace.
# File 'lib/redis/commands/modules/search/query.rb', line 648
def escape_tag(value) value.to_s.gsub(TAG_ESCAPE_PATTERN) { |char| "\\#{char}" } end
#escape_text(value) (private)
Escape query metacharacters in a literal text value, keeping spaces as term separators.
# File 'lib/redis/commands/modules/search/query.rb', line 643
def escape_text(value) value.to_s.gsub(TEXT_ESCAPE_PATTERN) { |char| "\\#{char}" } end
#to_s ⇒ String
# File 'lib/redis/commands/modules/search/query.rb', line 636
def to_s raise NotImplementedError end