2 Implementation of the 'index' subcommand.
 
   6 from nominatim.db import status
 
   7 from nominatim.db.connection import connect
 
   9 # Do not repeat documentation of subcommand classes.
 
  10 # pylint: disable=C0111
 
  11 # Using non-top-level imports to avoid eventually unused imports.
 
  12 # pylint: disable=E0012,C0415
 
  17     Reindex all new and modified data.
 
  19     Indexing is the process of computing the address and search terms for
 
  20     the places in the database. Every time data is added or changed, indexing
 
  21     needs to be run. Imports and replication updates automatically take care
 
  22     of indexing. For other cases, this function allows to run indexing manually.
 
  27         group = parser.add_argument_group('Filter arguments')
 
  28         group.add_argument('--boundaries-only', action='store_true',
 
  29                            help="""Index only administrative boundaries.""")
 
  30         group.add_argument('--no-boundaries', action='store_true',
 
  31                            help="""Index everything except administrative boundaries.""")
 
  32         group.add_argument('--minrank', '-r', type=int, metavar='RANK', default=0,
 
  33                            help='Minimum/starting rank')
 
  34         group.add_argument('--maxrank', '-R', type=int, metavar='RANK', default=30,
 
  35                            help='Maximum/finishing rank')
 
  39         from ..indexer.indexer import Indexer
 
  40         from ..tokenizer import factory as tokenizer_factory
 
  42         tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
 
  44         indexer = Indexer(args.config.get_libpq_dsn(), tokenizer,
 
  45                           args.threads or psutil.cpu_count() or 1)
 
  47         if not args.no_boundaries:
 
  48             indexer.index_boundaries(args.minrank, args.maxrank)
 
  49         if not args.boundaries_only:
 
  50             indexer.index_by_rank(args.minrank, args.maxrank)
 
  52         if not args.no_boundaries and not args.boundaries_only \
 
  53            and args.minrank == 0 and args.maxrank == 30:
 
  54             with connect(args.config.get_libpq_dsn()) as conn:
 
  55                 status.set_indexed(conn, True)