From 970d81fb27e2e56b9e91e1516677b0d5c75112d2 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Mon, 7 Jul 2025 12:06:06 +0200 Subject: [PATCH] sort housenumber parents by accuracy first Sorting them by presence of housenumber only will give an undue preference to results with a housenumber while disregarding other factors like matching postcodes. --- src/nominatim_api/search/db_searches/address_search.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nominatim_api/search/db_searches/address_search.py b/src/nominatim_api/search/db_searches/address_search.py index 90688339..806b0dd5 100644 --- a/src/nominatim_api/search/db_searches/address_search.py +++ b/src/nominatim_api/search/db_searches/address_search.py @@ -296,11 +296,15 @@ class AddressSearch(base.AbstractSearch): interpol_sql.label('interpol_hnr'), tiger_sql.label('tiger_hnr')).subquery('unsort') sql = sa.select(unsort)\ - .order_by(sa.case((unsort.c.placex_hnr != None, 1), + .order_by(unsort.c.accuracy + + sa.case((unsort.c.placex_hnr != None, 0), + (unsort.c.interpol_hnr != None, 0), + (unsort.c.tiger_hnr != None, 0), + else_=1), + sa.case((unsort.c.placex_hnr != None, 1), (unsort.c.interpol_hnr != None, 2), (unsort.c.tiger_hnr != None, 3), - else_=4), - unsort.c.accuracy) + else_=4)) sql = sql.limit(LIMIT_PARAM) -- 2.39.5