Class: Redis::Commands::Search::TextField
- Defined in:
- lib/redis/commands/modules/search/field.rb
Overview
A TEXT field, indexing full-text searchable content.
Instance Attribute Summary
Attributes inherited from Field
#alias_name, #name, #options, #query, #type
Instance Method Summary collapse
-
#initialize(name, query = nil, **options) ⇒ TextField
constructor
Build a
TEXTfield. -
#match(pattern, raw: false) ⇒ Query
Add a text-match predicate (+@field:(pattern)+) to the bound query.
-
#to_args ⇒ Array
Render this field as the array of
FT.CREATESCHEMAtokens.
Constructor Details
#initialize(name, query = nil, **options) ⇒ TextField
Build a TEXT field.
95 96 97 98 99 100 101 102 103 |
# File 'lib/redis/commands/modules/search/field.rb', line 95 def initialize(name, query = nil, **) super(name, :text, query, **) if [:phonetic] valid_matchers = ['dm:en', 'dm:fr', 'dm:pt', 'dm:es'] unless valid_matchers.include?([:phonetic]) raise ArgumentError, "Invalid phonetic matcher. Supported matchers are: #{valid_matchers.join(', ')}" end end end |
Instance Method Details
#match(pattern, raw: false) ⇒ Query
Add a text-match predicate (+@field:(pattern)+) to the bound query.
133 134 135 |
# File 'lib/redis/commands/modules/search/field.rb', line 133 def match(pattern, raw: false) query.add_predicate(TextMatchPredicate.new(@alias_name || name, pattern, raw: raw)) end |
#to_args ⇒ Array
Render this field as the array of FT.CREATE SCHEMA tokens.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/redis/commands/modules/search/field.rb', line 108 def to_args args = [@name] args << "AS" << @alias_name if @alias_name args << @type.to_s.upcase args << "NOSTEM" if @options[:no_stem] args << "WEIGHT" << @options[:weight].to_s if @options[:weight] args << "PHONETIC" << @options[:phonetic] if @options[:phonetic] # Add suffix options in specific order: no_index, index_missing, index_empty, sortable, withsuffixtrie args << "NOINDEX" if @options[:no_index] args << "INDEXMISSING" if @options[:index_missing] args << "INDEXEMPTY" if @options[:index_empty] args << "SORTABLE" if @options[:sortable] args << "WITHSUFFIXTRIE" if @options[:withsuffixtrie] args end |