X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/a28e158bddaed6c690c13df01bfd18a6dd647485..HEAD:/src/nominatim_db/indexer/runners.py?ds=inline diff --git a/src/nominatim_db/indexer/runners.py b/src/nominatim_db/indexer/runners.py index d7737c07..e20cf20d 100644 --- a/src/nominatim_db/indexer/runners.py +++ b/src/nominatim_db/indexer/runners.py @@ -19,11 +19,11 @@ from ..typing import Protocol from ..data.place_info import PlaceInfo from ..tokenizer.base import AbstractAnalyzer -# pylint: disable=C0111 def _mk_valuelist(template: str, num: int) -> pysql.Composed: return pysql.SQL(',').join([pysql.SQL(template)] * num) + def _analyze_place(place: DictRow, analyzer: AbstractAnalyzer) -> Json: return Json(analyzer.process_place(PlaceInfo(place))) @@ -41,6 +41,7 @@ SELECT_SQL = pysql.SQL("""SELECT place_id, extra.* LATERAL placex_indexing_prepare(px) as extra """) UPDATE_LINE = "(%s, %s::hstore, %s::hstore, %s::int, %s::jsonb)" + class AbstractPlacexRunner: """ Returns SQL commands for indexing of the placex table. """ @@ -49,7 +50,6 @@ class AbstractPlacexRunner: self.rank = rank self.analyzer = analyzer - def index_places_query(self, batch_size: int) -> Query: return pysql.SQL( """ UPDATE placex @@ -59,7 +59,6 @@ class AbstractPlacexRunner: WHERE place_id = v.id """).format(_mk_valuelist(UPDATE_LINE, batch_size)) - def index_places_params(self, place: DictRow) -> Sequence[Any]: return (place['place_id'], place['name'], @@ -118,7 +117,6 @@ class InterpolationRunner: def __init__(self, analyzer: AbstractAnalyzer) -> None: self.analyzer = analyzer - def name(self) -> str: return "interpolation lines (location_property_osmline)" @@ -126,14 +124,12 @@ class InterpolationRunner: return """SELECT count(*) FROM location_property_osmline WHERE indexed_status > 0""" - def sql_get_objects(self) -> Query: return """SELECT place_id, get_interpolation_address(address, osm_id) as address FROM location_property_osmline WHERE indexed_status > 0 ORDER BY geometry_sector""" - def index_places_query(self, batch_size: int) -> Query: return pysql.SQL("""UPDATE location_property_osmline SET indexed_status = 0, address = v.addr, token_info = v.ti @@ -141,13 +137,11 @@ class InterpolationRunner: WHERE place_id = v.id """).format(_mk_valuelist("(%s, %s::hstore, %s::jsonb)", batch_size)) - def index_places_params(self, place: DictRow) -> Sequence[Any]: return (place['place_id'], place['address'], _analyze_place(place, self.analyzer)) - class PostcodeRunner(Runner): """ Provides the SQL commands for indexing the location_postcode table. """ @@ -155,22 +149,18 @@ class PostcodeRunner(Runner): def name(self) -> str: return "postcodes (location_postcode)" - def sql_count_objects(self) -> Query: return 'SELECT count(*) FROM location_postcode WHERE indexed_status > 0' - def sql_get_objects(self) -> Query: return """SELECT place_id FROM location_postcode WHERE indexed_status > 0 ORDER BY country_code, postcode""" - def index_places_query(self, batch_size: int) -> Query: return pysql.SQL("""UPDATE location_postcode SET indexed_status = 0 WHERE place_id IN ({})""")\ .format(pysql.SQL(',').join((pysql.Placeholder() for _ in range(batch_size)))) - def index_places_params(self, place: DictRow) -> Sequence[Any]: return (place['place_id'], )