Class: Redis::Commands::Search::GeoShapeField

Inherits:
Field
  • Object
show all
Defined in:
lib/redis/commands/modules/search/field.rb

Overview

A GEOSHAPE field, indexing geometric shapes under a coordinate system.

Constant Summary collapse

FLAT =
"FLAT"
SPHERICAL =
"SPHERICAL"

Instance Attribute Summary

Attributes inherited from Field

#alias_name, #name, #options, #query, #type

Instance Method Summary collapse

Constructor Details

#initialize(name, coord_system = nil, **options) ⇒ GeoShapeField

Build a GEOSHAPE field.

Parameters:

  • name (String, Symbol)

    the document attribute the field indexes

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

    the coordinate system, FLAT or SPHERICAL; nil (the default) omits the token so the server default (SPHERICAL) applies

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :no_index (Boolean)

    do not index the field (+NOINDEX+)

  • :index_missing (Boolean)

    index documents missing the field (+INDEXMISSING+)

  • :sortable (Boolean)

    allow sorting by the field (+SORTABLE+)



203
204
205
206
# File 'lib/redis/commands/modules/search/field.rb', line 203

def initialize(name, coord_system = nil, **options)
  super(name, :geoshape, nil, **options)
  @coord_system = coord_system
end

Instance Method Details

#to_argsArray

Render this field as the array of FT.CREATE SCHEMA tokens.

Returns:

  • (Array)

    the schema tokens for this field



211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/redis/commands/modules/search/field.rb', line 211

def to_args
  args = [@name]
  args << "AS" << @alias_name if @alias_name
  args << @type.to_s.upcase
  args << @coord_system if @coord_system

  # Add suffix options (order mirrors the base Field: NOINDEX, INDEXMISSING, SORTABLE).
  # GEOSHAPE supports INDEXMISSING but not INDEXEMPTY/WITHSUFFIXTRIE.
  args << "NOINDEX" if @options[:no_index]
  args << "INDEXMISSING" if @options[:index_missing]
  args << "SORTABLE" if @options[:sortable]

  args
end