Created
May 16, 2016 23:29
-
-
Save leandronsp/4291da4ba0550eecd2e45d9f9f2443ba to your computer and use it in GitHub Desktop.
This file contains 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
pg_search_scope :_expensive_search_with_coords, (lambda do |term, lat, lon| | |
{ | |
query: term, | |
against: { name: 'A' }, | |
associated_against: { | |
city_aliases: { name: 'B' }, | |
region: { name: 'C' }, | |
country: { name: 'D' } | |
}, | |
ignoring: :accents, | |
ranked_by: self.complext_script(lat, lon), | |
order_with_rank: 'pg_search_rank DESC' | |
} | |
end) # end lambda. Ugly, I know :P | |
def self.complex_script(lat, lon) | |
<<-SCRIPT | |
:tsearch * log(GREATEST(CAST(population AS integer), 3)) | |
* (3.0 ^ (CAST((point(latitude,longitude) <@> point(#{lat}, #{lon})) | |
AS numeric) + 1.0) ^ -0.1) | |
SCRIPT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment