1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Implementation of the 'index' subcommand.
12 from nominatim.db import status
13 from nominatim.db.connection import connect
15 # Do not repeat documentation of subcommand classes.
16 # pylint: disable=C0111
17 # Using non-top-level imports to avoid eventually unused imports.
18 # pylint: disable=E0012,C0415
23 Reindex all new and modified data.
25 Indexing is the process of computing the address and search terms for
26 the places in the database. Every time data is added or changed, indexing
27 needs to be run. Imports and replication updates automatically take care
28 of indexing. For other cases, this function allows to run indexing manually.
33 group = parser.add_argument_group('Filter arguments')
34 group.add_argument('--boundaries-only', action='store_true',
35 help="""Index only administrative boundaries.""")
36 group.add_argument('--no-boundaries', action='store_true',
37 help="""Index everything except administrative boundaries.""")
38 group.add_argument('--minrank', '-r', type=int, metavar='RANK', default=0,
39 help='Minimum/starting rank')
40 group.add_argument('--maxrank', '-R', type=int, metavar='RANK', default=30,
41 help='Maximum/finishing rank')
45 from ..indexer.indexer import Indexer
46 from ..tokenizer import factory as tokenizer_factory
48 tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
50 indexer = Indexer(args.config.get_libpq_dsn(), tokenizer,
51 args.threads or psutil.cpu_count() or 1)
53 if not args.no_boundaries:
54 indexer.index_boundaries(args.minrank, args.maxrank)
55 if not args.boundaries_only:
56 indexer.index_by_rank(args.minrank, args.maxrank)
58 if not args.no_boundaries and not args.boundaries_only \
59 and args.minrank == 0 and args.maxrank == 30:
60 with connect(args.config.get_libpq_dsn()) as conn:
61 status.set_indexed(conn, True)