Class: Sunspot::Type::LocationType

Inherits:
AbstractType show all
Defined in:
sunspot/lib/sunspot/type.rb

Overview

The Location type encodes geographical coordinates as a GeoHash. The data for this type must respond to the `lat` and `lng` methods; you can use Sunspot::Util::Coordinates as a wrapper if your source data does not follow this API.

Location fields are most usefully searched using the Sunspot::DSL::RestrictionWithType#near method; see that method for more information on geographical search.

Example

  Sunspot.setup(Post) do
    location :coordinates do
      Sunspot::Util::Coordinates.new(coordinates[0], coordinates[1])
    end
  end

Instance Method Summary (collapse)

Methods inherited from AbstractType

#accepts_dynamic?, #accepts_more_like_this?, #to_literal

Instance Method Details

- (Object) indexed_name(name)



348
349
350
# File 'sunspot/lib/sunspot/type.rb', line 348

def indexed_name(name)
  "#{name}_s"
end

- (Object) to_indexed(value)



352
353
354
# File 'sunspot/lib/sunspot/type.rb', line 352

def to_indexed(value)
  GeoHash.encode(value.lat.to_f, value.lng.to_f, 12)
end