Skip to content

Instantly share code, notes, and snippets.

@leandronsp
Created May 16, 2016 23:28
Show Gist options
  • Save leandronsp/428b93edd5f6af14ddaf0dd602fc1e9f to your computer and use it in GitHub Desktop.
Save leandronsp/428b93edd5f6af14ddaf0dd602fc1e9f to your computer and use it in GitHub Desktop.
class CityDocument < ActiveRecord::Base
include PgSearch
self.table_name = 'city_document_view'
self.primary_key = 'city_id'
pg_search_scope :_not_so_expensive_search_with_coords, (lambda do |term, lat, lon|
{
query: term,
##
# not using :associated against anymore
##
against: {
city_name: 'A',
aliases: 'B',
region_name: 'C',
country_name: 'D'
},
ignoring: :accents,
ranked_by: self.complext_script(lat, lon),
order_with_rank: 'pg_search_rank DESC'
}
end)
CityDocument._not_so_expensive_search_with_coords('london', 34.54426, -91.96903)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment