Class: Redis::Commands::Search::IndexDefinition

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(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.

Examples:

Redis::Commands::Search::IndexDefinition.new(prefix: ["doc:"], index_type: IndexType::JSON).args
  # => ["ON", "JSON", "PREFIX", 1, "doc:", "SCORE", 1.0]

Parameters:

  • prefix (Array<String>, String, nil) (defaults to: [])

    key prefix(es) the index applies to (+PREFIX+); a single String is wrapped into a one-element list and nil means "no prefix"

  • filter (String, nil) (defaults to: nil)

    a filter expression (+FILTER+)

  • language_field (String, nil) (defaults to: nil)

    the field holding each document's language (+LANGUAGE_FIELD+)

  • language (String, nil) (defaults to: nil)

    the default document language (+LANGUAGE+)

  • score_field (String, nil) (defaults to: nil)

    the field holding each document's score (+SCORE_FIELD+)

  • score (Numeric) (defaults to: 1.0)

    the default document score (+SCORE+)

  • payload_field (String, nil) (defaults to: nil)

    the field holding each document's payload (+PAYLOAD_FIELD+)

  • index_type (String, nil) (defaults to: nil)

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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

#argsArray, ... (readonly)

Returns:



19
20
21
# File 'lib/redis/commands/modules/search/index_definition.rb', line 19

def args
  @args
end

#index_typeArray, ... (readonly)

Returns:



19
20
21
# File 'lib/redis/commands/modules/search/index_definition.rb', line 19

def index_type
  @index_type
end

#prefixesArray, ... (readonly)

Returns:



19
20
21
# File 'lib/redis/commands/modules/search/index_definition.rb', line 19

def prefixes
  @prefixes
end