37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/ohm/geoindex.rb', line 37
def within(center, radius, withdist: nil, sort: nil)
raise IndexNotFound unless @geoindex
args = center.is_a?(self.ancestors.first) ? ['GEORADIUSBYMEMBER', key[:geoindex], center.id] : ['GEORADIUS', key[:geoindex], *center]
args << parse_radius(radius)
args << sort if sort
args << 'withdist' if withdist
results = redis.call(*args.flatten)
ids = results.map { |r| [*r][0] }
models = self.ancestors.first.fetch(ids)
if withdist
results.each_with_index.map { |r,i| [models[i], r[1].to_f] }
else
models
end
end
|