From 18d7398d50445187d894d68f6f36aa8efdb7ae03 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Mon, 29 Oct 2018 18:18:04 -0700 Subject: [PATCH] Minor refactoring --- internal/server/search.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/server/search.go b/internal/server/search.go index e2759f33..9aea30f7 100644 --- a/internal/server/search.go +++ b/internal/server/search.go @@ -423,18 +423,17 @@ func (server *Server) nearestNeighbors( if !match { return true } - var dist float64 + var dist, max_dist float64 if s.distance { dist = o.Distance(target) - if target.Meters() > 0 && dist > target.Meters() { - return false - } + max_dist = target.Meters() } else { // don't need actual distances, use haversine as proxy for sorting dist = target.HaversineTo(o.Center()) - if target.Haversine() > 0 && dist > target.Haversine() { - return false - } + max_dist = target.Haversine() + } + if max_dist > 0 && dist > max_dist { + return false } items = append(items, iterItem{id: id, o: o, fields: fields, dist: dist}) if !keepGoing {