Class: Sunspot::Type::LocationType
- Inherits:
-
AbstractType
- Object
- AbstractType
- Sunspot::Type::LocationType
- Defined in:
- 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
#indexed_name(name) ⇒ Object
348 349 350 |
# File 'lib/sunspot/type.rb', line 348 def indexed_name(name) "#{name}_s" end |
#to_indexed(value) ⇒ Object
352 353 354 |
# File 'lib/sunspot/type.rb', line 352 def to_indexed(value) GeoHash.encode(value.lat.to_f, value.lng.to_f, 12) end |