From a8b023e57eda06bac3e5641f85f718e1d3104fe9 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 26 Nov 2023 17:41:29 +0100 Subject: [PATCH] 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. --- nominatim/api/search/db_searches.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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] -- 2.39.5