mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
Store entrance fields as columns on table
This commit is contained in:
@@ -723,18 +723,27 @@ async def complete_linked_places(conn: SearchConnection, result: BaseResult) ->
|
||||
|
||||
|
||||
async def complete_entrances_details(conn: SearchConnection, results: List[BaseResultT]) -> None:
|
||||
""" Retrieve information about tagged entrances for this place.
|
||||
""" Retrieve information about tagged entrances for the given results.
|
||||
"""
|
||||
t = conn.t.place_entrance
|
||||
place_ids = (r.place_id for r in results)
|
||||
sql = sa.select(t.c.place_id, t.c.entrances).where(t.c.place_id.in_(place_ids))
|
||||
place_ids = (r.place_id for r in results if r.source_table == SourceTable.PLACEX)
|
||||
|
||||
t = conn.t.placex_entrance
|
||||
sql = sa.select(t.c.place_id, t.c.osm_id, t.c.type, t.c.location, t.c.extratags)\
|
||||
.where(t.c.place_id.in_(place_ids))
|
||||
|
||||
current_result = None
|
||||
for place_id, entrances in await conn.execute(sql):
|
||||
if current_result is None or place_id != current_result.place_id:
|
||||
current_result = next((r for r in results if r.place_id == place_id), None)
|
||||
for row in await conn.execute(sql):
|
||||
if current_result is None or row.place_id != current_result.place_id:
|
||||
current_result = next((r for r in results if r.place_id == row.place_id), None)
|
||||
assert current_result is not None
|
||||
current_result.entrances = [EntranceDetails(**r) for r in entrances]
|
||||
if current_result.entrances is None:
|
||||
current_result.entrances = []
|
||||
current_result.entrances.append(EntranceDetails(
|
||||
osm_id=row.osm_id,
|
||||
type=row.type,
|
||||
location=Point.from_wkb(row.location),
|
||||
extratags=row.extratags,
|
||||
))
|
||||
|
||||
|
||||
async def complete_keywords(conn: SearchConnection, result: BaseResult) -> None:
|
||||
|
||||
@@ -128,7 +128,10 @@ class SearchTables:
|
||||
sa.Column('linegeo', Geometry),
|
||||
sa.Column('postcode', sa.Text))
|
||||
|
||||
self.place_entrance = sa.Table(
|
||||
'place_entrance', meta,
|
||||
self.placex_entrance = sa.Table(
|
||||
'placex_entrance', meta,
|
||||
sa.Column('place_id', sa.BigInteger),
|
||||
sa.Column('entrances', KeyValueStore))
|
||||
sa.Column('osm_id', sa.BigInteger),
|
||||
sa.Column('type', sa.Text),
|
||||
sa.Column('location', Geometry, nullable=False),
|
||||
sa.Column('extratags', KeyValueStore))
|
||||
|
||||
@@ -566,12 +566,9 @@ class EntranceDetails:
|
||||
type: str
|
||||
""" The value of the OSM entrance tag (i.e. yes, main, secondary, etc.).
|
||||
"""
|
||||
lat: float
|
||||
""" The latitude of the entrance node.
|
||||
"""
|
||||
lon: float
|
||||
""" The longitude of the entrance node.
|
||||
location: Point
|
||||
""" The location of the entrance node.
|
||||
"""
|
||||
extratags: Dict[str, str]
|
||||
""" The longitude of the entrance node.
|
||||
""" The other tags associated with the entrance node.
|
||||
"""
|
||||
|
||||
@@ -77,8 +77,8 @@ def write_entrances(out: JsonWriter, entrances: Optional[List[EntranceDetails]])
|
||||
out.start_object()\
|
||||
.keyval('osm_id', entrance.osm_id)\
|
||||
.keyval('type', entrance.type)\
|
||||
.keyval('lat', f"{entrance.lat:0.7f}")\
|
||||
.keyval('lon', f"{entrance.lon:0.7f}")
|
||||
.keyval('lat', f"{entrance.location.lat:0.7f}")\
|
||||
.keyval('lon', f"{entrance.location.lon:0.7f}")
|
||||
|
||||
if entrance.extratags:
|
||||
out.keyval('extratags', entrance.extratags)
|
||||
|
||||
@@ -87,8 +87,8 @@ def _create_entrance(root: ET.Element, entrance: EntranceDetails) -> None:
|
||||
entrance_node = ET.SubElement(root, 'entrance', attrib={
|
||||
"osm_id": str(entrance.osm_id),
|
||||
"type": entrance.type,
|
||||
"lat": f"{entrance.lat:0.7f}",
|
||||
"lon": f"{entrance.lon:0.7f}",
|
||||
"lat": f"{entrance.location.lat:0.7f}",
|
||||
"lon": f"{entrance.location.lon:0.7f}",
|
||||
})
|
||||
if entrance.extratags:
|
||||
for k, v in entrance.extratags.items():
|
||||
|
||||
Reference in New Issue
Block a user