mirror of https://github.com/tidwall/tile38.git
Merge pull request #231 from rshura/try_nearby_fix
Fix NEARBY to filter where clauses prior to limiting.
This commit is contained in:
commit
f99273c4c3
|
@ -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) {
|
func nearestNeighbors(sw *scanWriter, lat, lon float64, iter func(id string, o geojson.Object, fields []float64, dist *float64) bool) {
|
||||||
limit := sw.limit * 10
|
limit := int(sw.cursor + sw.limit)
|
||||||
if limit > limitItems*10 {
|
|
||||||
limit = limitItems * 10
|
|
||||||
}
|
|
||||||
k := sw.cursor + limit
|
|
||||||
var items []iterItem
|
var items []iterItem
|
||||||
sw.col.NearestNeighbors(lat, lon, func(id string, o geojson.Object, fields []float64) bool {
|
sw.col.NearestNeighbors(lat, lon, func(id string, o geojson.Object, fields []float64) bool {
|
||||||
if k == 0 {
|
if _, ok := sw.fieldMatch(fields, o); ok {
|
||||||
return false
|
|
||||||
}
|
|
||||||
dist := o.CalculatedPoint().DistanceTo(geojson.Position{X: lon, Y: lat, Z: 0})
|
dist := o.CalculatedPoint().DistanceTo(geojson.Position{X: lon, Y: lat, Z: 0})
|
||||||
items = append(items, iterItem{id: id, o: o, fields: fields, dist: dist})
|
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 {
|
sort.Slice(items, func(i, j int) bool {
|
||||||
return items[i].dist < items[j].dist
|
return items[i].dist < items[j].dist
|
||||||
|
|
Loading…
Reference in New Issue