X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/27977411e958a6bfc9037db728d61d296c5487c0..99dcd10d3fb1b79ee69ed73def9038a0f5118ebe:/nominatim/indexer/indexer.py diff --git a/nominatim/indexer/indexer.py b/nominatim/indexer/indexer.py index 52046456..6e0ed60f 100644 --- a/nominatim/indexer/indexer.py +++ b/nominatim/indexer/indexer.py @@ -5,8 +5,10 @@ Main work horse for indexing (computing addresses) the database. import logging import select +import psycopg2 + from .progress import ProgressLogger -from db.async_connection import DBConnection, make_connection +from ..db.async_connection import DBConnection LOG = logging.getLogger() @@ -94,34 +96,40 @@ class Indexer: """ Main indexing routine. """ - def __init__(self, opts): - self.minrank = max(1, opts.minrank) - self.maxrank = min(30, opts.maxrank) - self.conn = make_connection(opts) - self.threads = [DBConnection(opts) for _ in range(opts.threads)] + def __init__(self, dsn, num_threads): + self.conn = psycopg2.connect(dsn) + self.threads = [DBConnection(dsn) for _ in range(num_threads)] - def index_boundaries(self): + def index_boundaries(self, minrank, maxrank): LOG.warning("Starting indexing boundaries using %s threads", len(self.threads)) - for rank in range(max(self.minrank, 5), min(self.maxrank, 26)): + for rank in range(max(minrank, 4), min(maxrank, 26)): self.index(BoundaryRunner(rank)) - def index_by_rank(self): + def index_by_rank(self, minrank, maxrank): """ Run classic indexing by rank. """ + maxrank = min(maxrank, 30) LOG.warning("Starting indexing rank (%i to %i) using %i threads", - self.minrank, self.maxrank, len(self.threads)) + minrank, maxrank, len(self.threads)) - for rank in range(max(1, self.minrank), self.maxrank): + for rank in range(max(1, minrank), maxrank): self.index(RankRunner(rank)) - if self.maxrank == 30: + if maxrank == 30: self.index(RankRunner(0)) self.index(InterpolationRunner(), 20) - self.index(RankRunner(self.maxrank), 20) + self.index(RankRunner(30), 20) else: - self.index(RankRunner(self.maxrank)) + self.index(RankRunner(maxrank)) + + def update_status_table(self): + """ Update the status in the status table to 'indexed'. + """ + with self.conn.cursor() as cur: + cur.execute('UPDATE import_status SET indexed = true') + self.conn.commit() def index(self, obj, batch=1): """ Index a single rank or table. `obj` describes the SQL to use