From: Sarah Hoffmann Date: Sun, 26 Nov 2023 16:41:29 +0000 (+0100) Subject: restrict base results in near search by rank X-Git-Tag: v4.4.0~76^2~1 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/a8b023e57eda06bac3e5641f85f718e1d3104fe9?ds=sidebyside restrict base results in near search by rank This avoids in particular that roads or POIs are used as base for the near search when a place result is present. --- diff --git a/nominatim/api/search/db_searches.py b/nominatim/api/search/db_searches.py index 10f1e3b4..ce5fbc63 100644 --- a/nominatim/api/search/db_searches.py +++ b/nominatim/api/search/db_searches.py @@ -256,9 +256,20 @@ class NearSearch(AbstractSearch): base.sort(key=lambda r: (r.accuracy, r.rank_search)) max_accuracy = base[0].accuracy + 0.5 + if base[0].rank_address == 0: + min_rank = 0 + max_rank = 0 + elif base[0].rank_address < 26: + min_rank = 1 + max_rank = min(25, base[0].rank_address + 4) + else: + min_rank = 26 + max_rank = 30 base = nres.SearchResults(r for r in base if r.source_table == nres.SourceTable.PLACEX and r.accuracy <= max_accuracy - and r.bbox and r.bbox.area < 20) + and r.bbox and r.bbox.area < 20 + and r.rank_address >= min_rank + and r.rank_address <= max_rank) if base: baseids = [b.place_id for b in base[:5] if b.place_id]