Created
April 18, 2012 02:46
-
-
Save alindeman/2410743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Office < ActiveRecord::Base | |
| end | |
| # .. for example .. | |
| o = Office.create(latitude: 32, longitude: -86) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Office < ActiveRecord::Base | |
| searchable do | |
| latlon(:location) { Sunspot::Util::Coordinates.new(latitude, longitude) } | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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