Skip to content
Snippets Groups Projects
Commit 2c96be13 authored by Alex Reisner's avatar Alex Reisner
Browse files

Fix Mongoid/Ruby 1.8 "can't find special index".

Hash order needs to be preserved so with Ruby 1.8 we use a
BSON::OrderedHash instead of a generic one.
parent 4252a06b
No related branches found
No related tags found
No related merge requests found
...@@ -19,11 +19,17 @@ module Geocoder::Store ...@@ -19,11 +19,17 @@ module Geocoder::Store
coords = Geocoder::Calculations.extract_coordinates(location) coords = Geocoder::Calculations.extract_coordinates(location)
radius = args.size > 0 ? args.shift : 20 radius = args.size > 0 ? args.shift : 20
options = args.size > 0 ? args.shift : {} options = args.size > 0 ? args.shift : {}
conds = {:coordinates => {
"$nearSphere" => coords.reverse, # Use BSON::OrderedHash if Ruby's hashes are unordered.
"$maxDistance" => Geocoder::Calculations.distance_to_radians( # Conditions must be in order required by indexes (see mongo gem).
radius, options[:units] || :mi) empty = RUBY_VERSION.split('.')[1].to_i < 9 ? BSON::OrderedHash.new : {}
}}
conds = empty.clone
conds[:coordinates] = empty.clone
conds[:coordinates]["$nearSphere"] = coords.reverse
conds[:coordinates]["$maxDistance"] = \
Geocoder::Calculations.distance_to_radians(radius, options[:units] || :mi)
if obj = options[:exclude] if obj = options[:exclude]
conds[:_id.ne] = obj.id conds[:_id.ne] = obj.id
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment