Created
September 17, 2014 00:36
-
-
Save jraczak/aee23ed26dd54e4083e6 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 VenueSearch < ActiveRecord::Base | |
| def self.search(params) | |
| if params[:zip].present? | |
| logger.info "The zip code is present" | |
| logger.debug(Geocoder.coordinates(params[:zip])) | |
| lat, long = Geocoder.coordinates(params[:zip]) | |
| else | |
| lat = params[:latitude] | |
| long = params[:longitude] | |
| end | |
| fake_distance = 20 * 0.6214 # 1.5 miles | |
| Venue.search(include: [:venue_category, :venue_subcategory]) do | |
| fulltext params[:q].gsub(/[^\s\w]/, ''), minimum_match: 2 do | |
| boost_fields name: 5.0, name_without_punc: 5.0, category: 3.5, subcategory: 3.5, tags: 4.0 | |
| end | |
| paginate page: params[:page] | |
| order_by_geodist :location, lat, long | |
| with(:location).in_radius(lat, long, fake_distance) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment