Describe the bug
Any /search request using the hidden [key=value] category syntax combined with a free-text near-phrase crashes with an uncaught IndexError, returned to the client as a generic 500 Internal Server Error, whenever the category search legitimately returns zero results.
Basically thr ForwardGeocoder.sort_and_cut_results() in src/nominatim_api/search/geocoder.py unconditionally indexes results[0]:
def sort_and_cut_results(self, results: SearchResults) -> SearchResults:
results.sort(key=lambda r: (r.ranking, 0 if r.bbox is None else -r.bbox.area))
final = SearchResults()
min_rank = results[0].rank_search # IndexError if results is empty
min_ranking = results[0].ranking
...
git blame shows the guard against empty results was removed in commit 87a8c24 ("improve result cutting when a POI comes out with top importance", 2025-06-01), which previously wrapped this block in if results:. Still present and unfixed on current master (2991c61).
This is confirmed independent of any specific category backend (old class/type place_classtype_* tables or the newer ltree-based categories column) -- it reproduces on production, which uses the old mechanism.
To Reproduce
curl -G "https://nominatim.openstreetmap.org/search" \
--data-urlencode "q=[amenity=xyzxyz] Berlin" \
--data-urlencode "format=json"
Response: {"title": "500 Internal Server Error"} (HTTP 500). amenity=xyzxyz is not a real OSM tag value, so this query is guaranteed zero category matches everywhere, ruling out a data/import-specific cause.
Software Environment (please complete the following information):
- Nominatim version: 5.3.99-2 (current master, commit 2991c61)
- Postgresql version: 17.9 (Debian 17.9-0+deb13u1)
- Postgis version: 3.5.2
- OS: Debian (x86_64-pc-linux-gnu
Hardware Configuration (please complete the following information):
- RAM:
- number of CPUs:
- type and size of disks:
Ahhh i cant recall
Postgresql Configuration:
NIL
Nominatim Configuration:
NIL
Additional context
Confirmed on two independent instances:
- nominatim.openstreetmap.org (production) -- [amenity=xyzxyz] Berlin -> HTTP 500
- our planet test instance -- same guaranteed-zero-match category, and the originally-noticed [club=scout] Vaduz -> HTTP 500
Describe the bug
Any
/searchrequest using the hidden[key=value]category syntax combined with a free-text near-phrase crashes with an uncaught IndexError, returned to the client as a generic 500 Internal Server Error, whenever the category search legitimately returns zero results.Basically thr
ForwardGeocoder.sort_and_cut_results()in src/nominatim_api/search/geocoder.py unconditionally indexes results[0]:git blame shows the guard against empty results was removed in commit 87a8c24 ("improve result cutting when a POI comes out with top importance", 2025-06-01), which previously wrapped this block in if results:. Still present and unfixed on current master (2991c61).
This is confirmed independent of any specific category backend (old class/type place_classtype_* tables or the newer ltree-based categories column) -- it reproduces on production, which uses the old mechanism.
To Reproduce
Response: {"title": "500 Internal Server Error"} (HTTP 500). amenity=xyzxyz is not a real OSM tag value, so this query is guaranteed zero category matches everywhere, ruling out a data/import-specific cause.
Software Environment (please complete the following information):
Hardware Configuration (please complete the following information):
Postgresql Configuration:
NIL
Nominatim Configuration:
NIL
Additional context
Confirmed on two independent instances: