X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/3742fa2929619a4c54a50d3e79e0eeadb4d6ca6f..9659afbade47d1ec6d5359b2b21e1e874516ed80:/src/nominatim_db/clicmd/index.py diff --git a/src/nominatim_db/clicmd/index.py b/src/nominatim_db/clicmd/index.py index 87e0fc03..c0619f34 100644 --- a/src/nominatim_db/clicmd/index.py +++ b/src/nominatim_db/clicmd/index.py @@ -8,6 +8,7 @@ Implementation of the 'index' subcommand. """ import argparse +import asyncio import psutil @@ -44,19 +45,7 @@ class UpdateIndex: def run(self, args: NominatimArgs) -> int: - from ..indexer.indexer import Indexer - from ..tokenizer import factory as tokenizer_factory - - tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config) - - indexer = Indexer(args.config.get_libpq_dsn(), tokenizer, - args.threads or psutil.cpu_count() or 1) - - if not args.no_boundaries: - indexer.index_boundaries(args.minrank, args.maxrank) - if not args.boundaries_only: - indexer.index_by_rank(args.minrank, args.maxrank) - indexer.index_postcodes() + asyncio.run(self._do_index(args)) if not args.no_boundaries and not args.boundaries_only \ and args.minrank == 0 and args.maxrank == 30: @@ -64,3 +53,22 @@ class UpdateIndex: status.set_indexed(conn, True) return 0 + + + async def _do_index(self, args: NominatimArgs) -> None: + from ..tokenizer import factory as tokenizer_factory + + tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config) + from ..indexer.indexer import Indexer + + indexer = Indexer(args.config.get_libpq_dsn(), tokenizer, + args.threads or psutil.cpu_count() or 1) + + has_pending = True # run at least once + while has_pending: + if not args.no_boundaries: + await indexer.index_boundaries(args.minrank, args.maxrank) + if not args.boundaries_only: + await indexer.index_by_rank(args.minrank, args.maxrank) + await indexer.index_postcodes() + has_pending = indexer.has_pending()