Class: Redis::Commands::Search::SchemaDefinition
- Inherits:
-
Object
- Object
- Redis::Commands::Search::SchemaDefinition
- Defined in:
- lib/redis/commands/modules/search/schema.rb
Overview
The block DSL used by Redis::Commands::Search::Schema.build to declare fields. Each helper appends a Field subclass to #fields.
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
-
#geo_field(name, **options) ⇒ Array<Field>
Add a GeoField to the schema.
-
#geoshape_field(name, coord_system = nil, **options) ⇒ Array<Field>
Add a GeoShapeField to the schema.
-
#initialize ⇒ SchemaDefinition
constructor
A new instance of SchemaDefinition.
-
#numeric_field(name, **options) ⇒ Array<Field>
Add a NumericField to the schema.
-
#tag_field(name, **options) ⇒ Array<Field>
Add a TagField to the schema.
-
#text_field(name, **options) ⇒ Array<Field>
Add a TextField to the schema.
-
#vector_field(name, algorithm, **attributes) { ... } ⇒ Array<Field>
Add a VectorField to the schema.
Constructor Details
#initialize ⇒ SchemaDefinition
Returns a new instance of SchemaDefinition.
74 75 76 |
# File 'lib/redis/commands/modules/search/schema.rb', line 74 def initialize @fields = [] end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
72 73 74 |
# File 'lib/redis/commands/modules/search/schema.rb', line 72 def fields @fields end |
Instance Method Details
#geo_field(name, **options) ⇒ Array<Field>
Add a GeoField to the schema.
136 137 138 |
# File 'lib/redis/commands/modules/search/schema.rb', line 136 def geo_field(name, **) @fields << GeoField.new(name, **) end |
#geoshape_field(name, coord_system = nil, **options) ⇒ Array<Field>
Add a GeoShapeField to the schema.
146 147 148 |
# File 'lib/redis/commands/modules/search/schema.rb', line 146 def geoshape_field(name, coord_system = nil, **) @fields << GeoShapeField.new(name, coord_system, **) end |
#numeric_field(name, **options) ⇒ Array<Field>
Add a NumericField to the schema.
105 106 107 |
# File 'lib/redis/commands/modules/search/schema.rb', line 105 def numeric_field(name, **) @fields << NumericField.new(name, **) end |
#tag_field(name, **options) ⇒ Array<Field>
Add a TagField to the schema.
122 123 124 125 126 127 128 129 130 |
# File 'lib/redis/commands/modules/search/schema.rb', line 122 def tag_field(name, **) = %i[sortable no_index as separator case_sensitive index_empty index_missing withsuffixtrie] = .keys - if .any? raise ArgumentError, "Invalid options for tag field: #{.join(', ')}" end @fields << TagField.new(name, **) end |
#text_field(name, **options) ⇒ Array<Field>
Add a TextField to the schema.
91 92 93 94 95 96 97 98 99 |
# File 'lib/redis/commands/modules/search/schema.rb', line 91 def text_field(name, **) = %i[weight sortable no_index as phonetic no_stem index_empty index_missing withsuffixtrie] = .keys - if .any? raise ArgumentError, "Invalid options for text field: #{.join(', ')}" end @fields << TextField.new(name, **) end |
#vector_field(name, algorithm, **attributes) { ... } ⇒ Array<Field>
Add a VectorField to the schema.
Field-level options (+:as+, :sortable, :no_index) are extracted from
attributes; the remaining keys (e.g. type:, dim:, distance_metric:)
become vector attributes. An optional block is evaluated in a
VectorFieldDefinition for declaring attributes.
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/redis/commands/modules/search/schema.rb', line 165 def vector_field(name, algorithm, **attributes, &block) # Extract field-level options (as, sortable, no_index) from attributes = {} [:as] = attributes.delete(:as) if attributes.key?(:as) [:sortable] = attributes.delete(:sortable) if attributes.key?(:sortable) [:no_index] = attributes.delete(:no_index) if attributes.key?(:no_index) field = VectorField.new(name, algorithm, attributes, **) VectorFieldDefinition.new(field).instance_eval(&block) if block_given? @fields << field end |