Class: Redis::Commands::Search::IndexDefinition
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/redis/commands/modules/search/index_definition.rb |
Overview
The definition portion of an FT.CREATE call: which keyspace the index
is built over and how documents are scored and filtered. Renders into a
token array exposed via #args.
Class Method Summary
-
.new(prefix: [], filter: nil, language_field: nil, language: nil, score_field: nil, score: 1.0, payload_field: nil, index_type: nil) ⇒ IndexDefinition
constructor
Build an index definition and pre-render its
FT.CREATEtokens.
Instance Attribute Summary
- #args ⇒ Array, ... readonly
- #index_type ⇒ Array, ... readonly
- #prefixes ⇒ Array, ... readonly
Instance Method Summary
- #append_filter(filter) private
- #append_index_type(index_type) private
- #append_language(language_field, language) private
- #append_payload(payload_field) private
- #append_prefix(prefix) private
- #append_score(score_field, score) private
Constructor Details
.new(prefix: [], filter: nil, language_field: nil, language: nil, score_field: nil, score: 1.0, payload_field: nil, index_type: nil) ⇒ IndexDefinition
Build an index definition and pre-render its FT.CREATE tokens.
# File 'lib/redis/commands/modules/search/index_definition.rb', line 37
def initialize( prefix: [], filter: nil, language_field: nil, language: nil, score_field: nil, score: 1.0, payload_field: nil, index_type: nil ) @args = [] @index_type = index_type # Array() makes the prefix handling nil-safe (nil -> []) and wraps a lone String prefix # into a one-element list, so PREFIX always emits the correct count. dup detaches us from # the caller's list (Array() returns it unchanged when it's already an Array) so later # external mutations can't alter this definition. @prefixes = Array(prefix).dup append_index_type(index_type) append_prefix(@prefixes) append_filter(filter) append_language(language_field, language) append_score(score_field, score) append_payload(payload_field) end
Instance Attribute Details
#args ⇒ Array, ... (readonly)
# File 'lib/redis/commands/modules/search/index_definition.rb', line 19
attr_reader :args, :prefixes, :index_type
#index_type ⇒ Array, ... (readonly)
#prefixes ⇒ Array, ... (readonly)
# File 'lib/redis/commands/modules/search/index_definition.rb', line 19
attr_reader :args, :prefixes, :index_type
Instance Method Details
#append_filter(filter) (private)
[ GitHub ]# File 'lib/redis/commands/modules/search/index_definition.rb', line 76
def append_filter(filter) if filter @args << "FILTER" @args << filter end end
#append_index_type(index_type) (private)
[ GitHub ]# File 'lib/redis/commands/modules/search/index_definition.rb', line 58
def append_index_type(index_type) if index_type == IndexType::HASH @args += ["ON", "HASH"] elsif index_type == IndexType::JSON @args += ["ON", "JSON"] elsif !index_type.nil? raise ArgumentError, "index_type must be IndexType::HASH or IndexType::JSON" end end
#append_language(language_field, language) (private)
[ GitHub ]# File 'lib/redis/commands/modules/search/index_definition.rb', line 83
def append_language(language_field, language) if language_field @args << "LANGUAGE_FIELD" @args << language_field end if language @args << "LANGUAGE" @args << language end end
#append_payload(payload_field) (private)
[ GitHub ]# File 'lib/redis/commands/modules/search/index_definition.rb', line 105
def append_payload(payload_field) if payload_field @args << "PAYLOAD_FIELD" @args << payload_field end end
#append_prefix(prefix) (private)
[ GitHub ]# File 'lib/redis/commands/modules/search/index_definition.rb', line 68
def append_prefix(prefix) unless prefix.empty? @args << "PREFIX" @args << prefix.length prefix.each { |p| @args << p } end end
#append_score(score_field, score) (private)
[ GitHub ]# File 'lib/redis/commands/modules/search/index_definition.rb', line 94
def append_score(score_field, score) if score_field @args << "SCORE_FIELD" @args << score_field end if score @args << "SCORE" @args << score end end