]> git.openstreetmap.org Git - nominatim.git/commitdiff
restrict base results in near search by rank
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 26 Nov 2023 16:41:29 +0000 (17:41 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 26 Nov 2023 16:41:29 +0000 (17:41 +0100)
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

index 10f1e3b448dd2427f6325578022120e81b13df0d..ce5fbc6341cd7d68efebe2100dc858a9ef6a2ffc 100644 (file)
@@ -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]