Class: Redis::Commands::Search::TextMatchPredicate
- Defined in:
- lib/redis/commands/modules/search/query.rb
Overview
A text-match predicate rendering (@field:(pattern)).
Constant Summary
Constants inherited from Predicate
Predicate::TAG_ESCAPE_PATTERN, Predicate::TAG_SPECIAL_CHARACTERS, Predicate::TEXT_ESCAPE_PATTERN, Predicate::TEXT_SPECIAL_CHARACTERS
Instance Attribute Summary
Attributes inherited from Predicate
Instance Method Summary collapse
-
#initialize(field, pattern, raw: false) ⇒ TextMatchPredicate
constructor
A new instance of TextMatchPredicate.
-
#to_s ⇒ String
The query-string fragment, e.g.
Constructor Details
#initialize(field, pattern, raw: false) ⇒ TextMatchPredicate
Returns a new instance of TextMatchPredicate.
675 676 677 678 679 |
# 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_s ⇒ String
Returns the query-string fragment, e.g. (@title:(hello world)).
682 683 684 685 686 687 688 689 690 |
# 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 |