from .config import Configuration
from .tools.exec_utils import run_legacy_script, run_api_script
+from .db.connection import connect
-from .indexer.indexer import Indexer
+LOG = logging.getLogger()
def _num_system_cpus():
try:
@staticmethod
def run(args):
+ from .indexer.indexer import Indexer
+
indexer = Indexer(args.config.get_libpq_dsn(),
args.threads or _num_system_cpus() or 1)
@staticmethod
def run(args):
+ from .tools import refresh
+
+ conn = connect(args.config.get_libpq_dsn())
+
if args.postcodes:
- run_legacy_script('update.php', '--calculate-postcodes',
- nominatim_env=args, throw_on_fail=True)
+ LOG.warning("Update postcodes centroid")
+ refresh.update_postcodes(conn, args.data_dir)
+
if args.word_counts:
- run_legacy_script('update.php', '--recompute-word-counts',
- nominatim_env=args, throw_on_fail=True)
+ LOG.warning('Recompute frequency of full-word search terms')
+ refresh.recompute_word_counts(conn, args.data_dir)
+
if args.address_levels:
- run_legacy_script('update.php', '--update-address-levels',
- nominatim_env=args, throw_on_fail=True)
+ cfg = Path(args.config.ADDRESS_LEVEL_CONFIG)
+ LOG.warning('Updating address levels from %s', cfg)
+ refresh.load_address_levels_from_file(conn, cfg)
+
if args.functions:
- params = ['setup.php', '--create-functions', '--create-partition-functions']
- if args.diffs:
- params.append('--enable-diff-updates')
- if args.enable_debug_statements:
- params.append('--enable-debug-statements')
- run_legacy_script(*params, nominatim_env=args, throw_on_fail=True)
+ LOG.warning('Create functions')
+ refresh.create_functions(conn, args.config, args.data_dir,
+ args.diffs, args.enable_debug_statements)
+
if args.wiki_data:
run_legacy_script('setup.php', '--import-wikipedia-articles',
nominatim_env=args, throw_on_fail=True)
if args.website:
run_legacy_script('setup.php', '--setup-website',
nominatim_env=args, throw_on_fail=True)
+
+ conn.close()
+
return 0