Created
January 9, 2014 10:19
-
-
Save karol-blaszczyk/8332124 to your computer and use it in GitHub Desktop.
Localization
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
def self.search_pricings_for(service_ids, postal_code) | |
pcc = PostalCodeCoordinates.find_by_postal_code(postal_code) if postal_code | |
lat_lon = pcc.lat_lon_string if pcc | |
unless pcc | |
search = Tire.search do |search| | |
search.size 0 | |
end | |
return search | |
end | |
search = Tire.search 'service_pricings' do |search| | |
search.size 1000 | |
if lat_lon | |
search.filter :or, [ | |
{ term: { locations: "virtual" }}, | |
{ and: [ | |
{term: { locations: "stationary" }}, | |
{geo_distance: { | |
distance: "#{MainSearcher::DEFAULT_RANGE}km", | |
service_location: lat_lon | |
}} | |
]}, | |
{ and: [ | |
{ missing: { field: "locations" }}, | |
{geo_distance: { | |
distance: "#{MainSearcher::DEFAULT_RANGE}km", | |
service_location: lat_lon | |
}} | |
]}, | |
{ and: [ | |
{term: { locations: "customer" }}, | |
{ | |
or: Location::DRIVE_RADIUSES.collect do |radius| | |
{ | |
and: | |
[ | |
{geo_distance: { | |
distance: "#{radius}km", | |
service_location: lat_lon | |
} | |
}, | |
{term: { drive_radius: radius }} | |
] | |
} | |
end | |
} | |
]} | |
] | |
# sorting does not work | |
search.sort do | |
by :_geo_distance, {mode: "min", service_location: lat_lon, unit: 'km', order: 'asc'} | |
end | |
end | |
search.filter :terms, service_id: service_ids | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment