Skip to content

Instantly share code, notes, and snippets.

@alindeman
Created April 18, 2012 02:46
Show Gist options
  • Select an option

  • Save alindeman/2410743 to your computer and use it in GitHub Desktop.

Select an option

Save alindeman/2410743 to your computer and use it in GitHub Desktop.
class Office < ActiveRecord::Base
end
# .. for example ..
o = Office.create(latitude: 32, longitude: -86)
class Office < ActiveRecord::Base
searchable do
latlon(:location) { Sunspot::Util::Coordinates.new(latitude, longitude) }
end
end
# Offices within 100 kilometers of (32, -68)
Office.search { with(:location).in_radius(32, -68, 100) }
# Offices within a bounding box of 100 kilometers from (32, -68)
# A bounding box may include areas beyond 100 kilometers of
# (32, -68) so offices may be returned that are outside the
# desired region; however, the search may be more performant.
Office.search { with(:location).in_radius(32, -68, 100, bbox: true) }
Office.search { order_by_geodist(:location, 32, -68) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment