Ver a proveniência

Added geospatial index and search

master
Adrian Short há 12 anos
ascendente
cometimento
72041be422
1 ficheiros alterados com 12 adições e 0 eliminações
  1. +12
    -0
      app/models/post.rb

+ 12
- 0
app/models/post.rb Ver ficheiro

@@ -10,5 +10,17 @@ class Post
key :loc, Hash # { lng, lat }
timestamps!

ensure_index [[:loc, '2d']]

belongs_to :feed
EARTH_RADIUS_KM = 6378.0
def self.near(lat, lng, radius_km)
all(
:loc => {
'$nearSphere' => [ lng, lat ],
'$maxDistance' => radius_km / EARTH_RADIUS_KM
})
end
end

Carregando…
Cancelar
Guardar