diff --git a/backend/app/routers/locations.py b/backend/app/routers/locations.py index ed09b32..7944451 100644 --- a/backend/app/routers/locations.py +++ b/backend/app/routers/locations.py @@ -8,6 +8,7 @@ import json import urllib.request import urllib.parse import logging +import re from app.database import get_db from app.models.location import Location @@ -70,6 +71,12 @@ async def search_locations( addr = item.get("address", {}) house_number = addr.get("house_number", "") road = addr.get("road", "") + # If Nominatim didn't return a house_number but the user's + # query starts with one, preserve it from the original query. + if not house_number and road: + m = re.match(r"^(\d+[\w/-]*)\s+", q.strip()) + if m: + house_number = m.group(1) # Build a name that preserves the house number if house_number and road: name = f"{house_number} {road}"