]> git.openstreetmap.org Git - nominatim.git/blobdiff - src/nominatim_db/clicmd/admin.py
lift restrictions on search with frequent terms slightly
[nominatim.git] / src / nominatim_db / clicmd / admin.py
index 66dbbe99a04134ebb4d64e85987f3aec57ed270e..1edff174dc37ad251de9d9d048736098d717d2f0 100644 (file)
@@ -11,8 +11,8 @@ import logging
 import argparse
 import random
 
 import argparse
 import random
 
-import nominatim_api as napi
-from nominatim_core.db.connection import connect
+from ..errors import UsageError
+from ..db.connection import connect, table_exists
 from .args import NominatimArgs
 
 # Do not repeat documentation of subcommand classes.
 from .args import NominatimArgs
 
 # Do not repeat documentation of subcommand classes.
@@ -95,6 +95,11 @@ class AdminFuncs:
 
 
     def _warm(self, args: NominatimArgs) -> int:
 
 
     def _warm(self, args: NominatimArgs) -> int:
+        try:
+            import nominatim_api as napi
+        except ModuleNotFoundError as exp:
+            raise UsageError("Warming requires nominatim API. "
+                             "Install with 'pip install nominatim-api'.") from exp
         LOG.warning('Warming database caches')
 
         api = napi.NominatimAPI(args.project_dir)
         LOG.warning('Warming database caches')
 
         api = napi.NominatimAPI(args.project_dir)
@@ -110,7 +115,7 @@ class AdminFuncs:
 
                 tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
                 with connect(args.config.get_libpq_dsn()) as conn:
 
                 tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
                 with connect(args.config.get_libpq_dsn()) as conn:
-                    if conn.table_exists('search_name'):
+                    if table_exists(conn, 'search_name'):
                         words = tokenizer.most_frequent_words(conn, 1000)
                     else:
                         words = []
                         words = tokenizer.most_frequent_words(conn, 1000)
                     else:
                         words = []