Class: Redis::Commands::Search::SchemaDefinition
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/redis/commands/modules/search/schema.rb |
Overview
The block DSL used by Schema.build to declare fields. Each helper
appends a Field subclass to #fields.
Class Method Summary
- .new ⇒ SchemaDefinition constructor
Instance Attribute Summary
- #fields readonly
Instance Method Summary
-
#geo_field(name, **options) ⇒ Array<Field>
Add a
GeoFieldto the schema. -
#geoshape_field(name, coord_system = nil, **options) ⇒ Array<Field>
Add a
GeoShapeFieldto the schema. -
#numeric_field(name, **options) ⇒ Array<Field>
Add a
NumericFieldto the schema. -
#tag_field(name, **options) ⇒ Array<Field>
Add a
TagFieldto the schema. -
#text_field(name, **options) ⇒ Array<Field>
Add a
TextFieldto the schema. -
#vector_field(name, algorithm, **attributes) { ... } ⇒ Array<Field>
Add a
VectorFieldto the schema.
Constructor Details
.new ⇒ SchemaDefinition
# File 'lib/redis/commands/modules/search/schema.rb', line 74
def initialize @fields = [] end
Instance Attribute Details
#fields (readonly)
[ GitHub ]# File 'lib/redis/commands/modules/search/schema.rb', line 72
attr_reader :fields
Instance Method Details
#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.
# 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.
# 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.
# 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.
# 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.
# 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