From 4eca0cdee7360935c540dc1aaac1be9f0cbdb2e6 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Mon, 30 Oct 2017 16:01:37 -0700 Subject: [PATCH 1/2] Attempt to fix NEARBY to filter prior to limiting. --- controller/search.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/controller/search.go b/controller/search.go index 59b3a5b3..8fed5ce8 100644 --- a/controller/search.go +++ b/controller/search.go @@ -352,20 +352,14 @@ type iterItem struct { } func nearestNeighbors(sw *scanWriter, lat, lon float64, iter func(id string, o geojson.Object, fields []float64, dist *float64) bool) { - limit := sw.limit * 10 - if limit > limitItems*10 { - limit = limitItems * 10 - } - k := sw.cursor + limit + limit := int(sw.limit) var items []iterItem sw.col.NearestNeighbors(lat, lon, func(id string, o geojson.Object, fields []float64) bool { - if k == 0 { - return false + if _, ok := sw.fieldMatch(fields, o); ok { + dist := o.CalculatedPoint().DistanceTo(geojson.Position{X: lon, Y: lat, Z: 0}) + items = append(items, iterItem{id: id, o: o, fields: fields, dist: dist}) } - dist := o.CalculatedPoint().DistanceTo(geojson.Position{X: lon, Y: lat, Z: 0}) - items = append(items, iterItem{id: id, o: o, fields: fields, dist: dist}) - k-- - return true + return len(items) < limit }) sort.Slice(items, func(i, j int) bool { return items[i].dist < items[j].dist From 1084c60805516cad16b41d921502150e1078ba01 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Tue, 31 Oct 2017 09:48:17 -0700 Subject: [PATCH 2/2] Apply limit on top of cursor --- controller/search.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/search.go b/controller/search.go index 8fed5ce8..8a656779 100644 --- a/controller/search.go +++ b/controller/search.go @@ -352,7 +352,7 @@ type iterItem struct { } func nearestNeighbors(sw *scanWriter, lat, lon float64, iter func(id string, o geojson.Object, fields []float64, dist *float64) bool) { - limit := int(sw.limit) + limit := int(sw.cursor + sw.limit) var items []iterItem sw.col.NearestNeighbors(lat, lon, func(id string, o geojson.Object, fields []float64) bool { if _, ok := sw.fieldMatch(fields, o); ok {