X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/f335e78d1eb54737202aa7a1bafaece19b6659a6..9cb9b670d182932851613ac8a08d3a1e7c8ce51f:/nominatim/api/results.py diff --git a/nominatim/api/results.py b/nominatim/api/results.py index 1e77d0be..3416fc7a 100644 --- a/nominatim/api/results.py +++ b/nominatim/api/results.py @@ -27,6 +27,24 @@ from nominatim.api.localization import Locales # This file defines complex result data classes. # pylint: disable=too-many-instance-attributes +def _mingle_name_tags(names: Optional[Dict[str, str]]) -> Optional[Dict[str, str]]: + """ Mix-in names from linked places, so that they show up + as standard names where necessary. + """ + if not names: + return None + + out = {} + for k, v in names.items(): + if k.startswith('_place_'): + outkey = k[7:] + out[k if outkey in names else outkey] = v + else: + out[k] = v + + return out + + class SourceTable(enum.Enum): """ Enumeration of kinds of results. """ @@ -210,6 +228,12 @@ class SearchResults(List[SearchResult]): May be empty when no result was found. """ + def localize(self, locales: Locales) -> None: + """ Apply the given locales to all results. + """ + for result in self: + result.localize(locales) + def _filter_geometries(row: SaRow) -> Dict[str, str]: return {k[9:]: v for k, v in row._mapping.items() # pylint: disable=W0212 @@ -229,7 +253,7 @@ def create_from_placex_row(row: Optional[SaRow], place_id=row.place_id, osm_object=(row.osm_type, row.osm_id), category=(row.class_, row.type), - names=row.name, + names=_mingle_name_tags(row.name), address=row.address, extratags=row.extratags, housenumber=row.housenumber, @@ -239,7 +263,7 @@ def create_from_placex_row(row: Optional[SaRow], rank_search=row.rank_search, importance=row.importance, country_code=row.country_code, - centroid=Point.from_wkb(row.centroid.data), + centroid=Point.from_wkb(row.centroid), geometry=_filter_geometries(row)) @@ -264,7 +288,7 @@ def create_from_osmline_row(row: Optional[SaRow], address=row.address, postcode=row.postcode, country_code=row.country_code, - centroid=Point.from_wkb(row.centroid.data), + centroid=Point.from_wkb(row.centroid), geometry=_filter_geometries(row)) if hnr is None: @@ -297,7 +321,7 @@ def create_from_tiger_row(row: Optional[SaRow], category=('place', 'houses' if hnr is None else 'house'), postcode=row.postcode, country_code='us', - centroid=Point.from_wkb(row.centroid.data), + centroid=Point.from_wkb(row.centroid), geometry=_filter_geometries(row)) if hnr is None: @@ -326,7 +350,7 @@ def create_from_postcode_row(row: Optional[SaRow], rank_search=row.rank_search, rank_address=row.rank_address, country_code=row.country_code, - centroid=Point.from_wkb(row.centroid.data), + centroid=Point.from_wkb(row.centroid), geometry=_filter_geometries(row)) @@ -341,7 +365,7 @@ def create_from_country_row(row: Optional[SaRow], return class_type(source_table=SourceTable.COUNTRY, category=('place', 'country'), - centroid=Point.from_wkb(row.centroid.data), + centroid=Point.from_wkb(row.centroid), names=row.name, rank_address=4, rank_search=4, country_code=row.country_code) @@ -378,10 +402,8 @@ def _result_row_to_address_row(row: SaRow) -> AddressLine: if hasattr(row, 'place_type') and row.place_type: extratags['place'] = row.place_type - names = row.name + names = _mingle_name_tags(row.name) or {} if getattr(row, 'housenumber', None) is not None: - if names is None: - names = {} names['housenumber'] = row.housenumber return AddressLine(place_id=row.place_id,