Created
February 24, 2011 10:11
-
-
Save sumskyi/842013 to your computer and use it in GitHub Desktop.
app/models/location.rb
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 Location < ActiveRecord::Base | |
| searchable do | |
| integer :id | |
| spellchk :name | |
| latlon :lat | |
| latlon :lon | |
| string :geohash | |
| end | |
| class << self | |
| # r = Location.by_keyword_and_radius 29.72322024726690, -95.42722710312336, 'restoran', 100 | |
| # r.results | |
| def by_keyword_and_radius(lat, lon, keyword, radius) | |
| @search = Sunspot.search(Location) do | |
| adjust_solr_params do |p| | |
| p.delete(:fq) | |
| p.delete(:qf) | |
| p.delete(:defType) | |
| p.delete(:fl) | |
| p[:qt] = 'geo' | |
| p[:spellcheck] = 'true' | |
| p[:sort] = 'geo_distance asc' | |
| p[:lat] = lat | |
| p[:long] = lon | |
| p[:radius] = radius | |
| p[:q] = keyword | |
| end | |
| end | |
| use_fuzzy | |
| @search | |
| end | |
| private | |
| def use_fuzzy | |
| @raw_results = @search.instance_variable_get(:@solr_result) | |
| logger.info(@raw_results.inspect) | |
| response = @raw_results['response'] | |
| fuzzy = @raw_results['fuzzy'] | |
| @raw_results['response'] = fuzzy if response['numFound'].zero? | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment