]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/indexer/indexer.py
add tests for indexer
[nominatim.git] / nominatim / indexer / indexer.py
index 520464565bebc96f04769b336c04604a531bab8f..6e0ed60fa6a949ef32446bee80f5641358a1745c 100644 (file)
@@ -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