From: Sarah Hoffmann Date: Tue, 8 Aug 2023 15:36:38 +0000 (+0200) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Tag: deploy~58 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/d2853de47cac812193083f9b144a0bc818205dd6?hp=0a19cc18e5060e02eb76850cf428a4d9c48ec0c1 Merge remote-tracking branch 'upstream/master' --- diff --git a/nominatim/api/v1/server_glue.py b/nominatim/api/v1/server_glue.py index d1bcc1da..80bf38a4 100644 --- a/nominatim/api/v1/server_glue.py +++ b/nominatim/api/v1/server_glue.py @@ -453,17 +453,24 @@ async def search_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A if params.get('featureType', None) is not None: details['layers'] = napi.DataLayer.ADDRESS + # unstructured query parameters query = params.get('q', None) + # structured query parameters queryparts = {} + for key in ('amenity', 'street', 'city', 'county', 'state', 'postalcode', 'country'): + details[key] = params.get(key, None) + if details[key]: + queryparts[key] = details[key] + try: if query is not None: + if queryparts: + params.raise_error("Structured query parameters" + "(amenity, street, city, county, state, postalcode, country)" + " cannot be used together with 'q' parameter.") queryparts['q'] = query results = await _unstructured_search(query, api, details) else: - for key in ('amenity', 'street', 'city', 'county', 'state', 'postalcode', 'country'): - details[key] = params.get(key, None) - if details[key]: - queryparts[key] = details[key] query = ', '.join(queryparts.values()) results = await api.search_address(**details) diff --git a/test/python/api/test_server_glue_v1.py b/test/python/api/test_server_glue_v1.py index 26e6517e..fe406c42 100644 --- a/test/python/api/test_server_glue_v1.py +++ b/test/python/api/test_server_glue_v1.py @@ -508,9 +508,8 @@ class TestSearchEndPointSearch: a.params['q'] = 'something' a.params['city'] = 'ignored' - res = await glue.search_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a) - - assert len(json.loads(res.output)) == 1 + with pytest.raises(FakeError, match='^400 -- .*cannot be used together'): + res = await glue.search_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a) @pytest.mark.asyncio