X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/d97ca9fcb2ae54080d6b92c7e85ff111308bc1cc..926c4a7d0444321b713e52deadfb0c9ab2b4f91d:/nominatim/api/v1/server_glue.py?ds=inline diff --git a/nominatim/api/v1/server_glue.py b/nominatim/api/v1/server_glue.py index d83adaae..80bf38a4 100644 --- a/nominatim/api/v1/server_glue.py +++ b/nominatim/api/v1/server_glue.py @@ -69,6 +69,11 @@ class ASGIAdaptor(abc.ABC): body of the response to 'output'. """ + @abc.abstractmethod + def base_uri(self) -> str: + """ Return the URI of the original request. + """ + @abc.abstractmethod def config(self) -> Configuration: @@ -448,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) @@ -481,7 +493,7 @@ async def search_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A (str(r.place_id) for r in results if r.place_id)) queryparts['format'] = fmt - moreurl = urlencode(queryparts) + moreurl = params.base_uri() + '/search?' + urlencode(queryparts) else: moreurl = ''