A4J
A4J

Reputation: 889

Proximity searches in Rails

What proximity search options are there for Rails? (Perhaps with pros and cons of each?)

(Example usage, A Yellow Pages type app where businesses can list, and users can enter their postcode and find businesses that are close to them, or within a radius of specified miles.)

Update: The app is pretty much exactly like the example app above - Businesses can list in the app which is essential a directory (which will have categories for each type of business) and users can go to a category and sort the results by distance (after entering their postcode - so the businesses closest to them, gets shown first). There will be no searching by name or other criteria - it is a simple go to the 'Boxer Dog Breeders' page and sort by distance.

Upvotes: 1

Views: 1537

Answers (3)

Gerry
Gerry

Reputation: 5336

Well the answer depends on what you want to do. If you want simple proximity searches (within a radius and stuff) then the Geocoder gem is more than fine! Now, if you want more advanced search capabilities (polygon, multi-polygon searches etc) I would suggest to go with the PostrgeSQL database and the wonderful PostGIS extension. For use with Rails you should definitely check out the PostGIS adapter for ActiveRecord which comes from the author of a really nice gem called RGeo which uses the superfast libraries GEOS and Proj for the Geospatial calculations.

Otherwise if you find that you need a dedicated search server that has GIS capabilities then you should definitely use ElasticSearch and Ruby has a great gem to aid you with ES called Tire.

Hope I helped!

Upvotes: 8

rogal111
rogal111

Reputation: 5933

If you plan to add addational search criteria (eg. name of firm, category) or complex sorting and your DB will grow over 10000 I'm recommend using external search server. For example sphinx search + thinking sphinx.

Here is example of geosearching: http://freelancing-god.github.com/ts/en/geosearching.html

RoR model solutions (like Geocoder) are not very efficient with full text searching.

Upvotes: 1

user650230
user650230

Reputation:

I don't have experience with Geocoding myself, but Alex Reisner's Geocoder gem looks like the best option, by a mile.

Geocoder is a complete geocoding solution for Ruby. With Rails it adds geocoding (by street or IP address), reverse geocoding (find street address based on given coordinates), and distance queries. It’s as simple as calling geocode on your objects, and then using a scope like Venue.near("Billings, MT").

Checkout the README for a full example on how to use it.

Upvotes: 0

Related Questions