tile38/internal
Mike Poindexter 2a4272c95f Improve kNN behavior
The current KNN implementation has two areas that can be improved:

- The current behavior is somewhat incorrect. When performing a kNN
query, the current code fetches k items from the index, and then sorts
these items according to Haversine distance. The problem with this
approach is that since the items fetched from the index are ordered by
a Euclidean metric, there is no guarantee that item k + 1 is not closer
than item k in great circle distance, and hence incorrect results can be
returned when closer items beyond k exist.

- The secondary sort is a performance killer. This requires buffering
all k items (again...they were already run through a priority queue in)
the index, and then a sort. Since the items are mostly sorted, and
Go's sort implementation is a quickSort this is the worst case for the
sort algorithm.

Both of these can be fixed by applying a proper distance metric in
the index nearby operation. In addition, this cleans up the code
considerably, removing a number of special cases that applied only
to NEARBY operations.

This change implements a geodetic distance metric that ensures that
the order from the index is correct, eliminating the need for the
secondary sort and special filtering cases in the ScanWriter code.
2020-04-07 20:10:58 -07:00
..
bing Code cleanup 2019-10-30 10:17:59 -07:00
clip Merge pull request #545 from tidwall/index-kind-geometry-nooverride 2020-04-02 08:15:38 -07:00
collection Improve kNN behavior 2020-04-07 20:10:58 -07:00
deadline Code cleanup 2019-10-30 10:17:59 -07:00
endpoint Code cleanup 2019-10-30 10:17:59 -07:00
expire Fixed data race for hooks with ttls 2019-10-08 09:26:55 -07:00
glob Code cleanup 2019-10-30 10:17:59 -07:00
hservice Faster point in polygon / GeoJSON updates 2018-10-13 04:30:48 -07:00
log Code cleanup 2019-10-30 10:17:59 -07:00
server Improve kNN behavior 2020-04-07 20:10:58 -07:00