X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/35b52c46562c3dd3427da7bca898d18edfd60047..bef5cea48e3ead13185e01958f7a3a80d185b11e:/nominatim/api/results.py diff --git a/nominatim/api/results.py b/nominatim/api/results.py index 0e3ddeda..98b13380 100644 --- a/nominatim/api/results.py +++ b/nominatim/api/results.py @@ -173,6 +173,19 @@ class ReverseResults(List[ReverseResult]): """ +@dataclasses.dataclass +class SearchResult(BaseResult): + """ A search result for forward geocoding. + """ + bbox: Optional[Bbox] = None + + +class SearchResults(List[SearchResult]): + """ Sequence of forward lookup results ordered by relevance. + May be empty when no result was found. + """ + + def _filter_geometries(row: SaRow) -> Dict[str, str]: return {k[9:]: v for k, v in row._mapping.items() # pylint: disable=W0212 if k.startswith('geometry_')} @@ -255,6 +268,7 @@ def create_from_tiger_row(row: Optional[SaRow], res = class_type(source_table=SourceTable.TIGER, place_id=row.place_id, + osm_object=(row.osm_type, row.osm_id), category=('place', 'houses' if hnr is None else 'house'), postcode=row.postcode, country_code='us', @@ -315,8 +329,8 @@ def _result_row_to_address_row(row: SaRow) -> AddressLine: """ Create a new AddressLine from the results of a datbase query. """ extratags: Dict[str, str] = getattr(row, 'extratags', {}) - if 'place_type' in row: - extratags['place_type'] = row.place_type + if hasattr(row, 'place_type') and row.place_type: + extratags['place'] = row.place_type names = row.name if getattr(row, 'housenumber', None) is not None: