mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
convert admin --analyse-indexing to new indexing method
A proper run of indexing requires the place information from the analyzer. Add the pre-processing of place data, so the right information is handed into the update function.
This commit is contained in:
@@ -9,47 +9,75 @@ Functions for database analysis and maintenance.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from psycopg2.extras import Json, register_hstore
|
||||
|
||||
from nominatim.db.connection import connect
|
||||
from nominatim.tokenizer import factory as tokenizer_factory
|
||||
from nominatim.errors import UsageError
|
||||
from nominatim.data.place_info import PlaceInfo
|
||||
|
||||
LOG = logging.getLogger()
|
||||
|
||||
def analyse_indexing(conn, osm_id=None, place_id=None):
|
||||
def _get_place_info(cursor, osm_id, place_id):
|
||||
sql = """SELECT place_id, extra.*
|
||||
FROM placex, LATERAL placex_indexing_prepare(placex) as extra
|
||||
"""
|
||||
|
||||
if osm_id:
|
||||
osm_type = osm_id[0].upper()
|
||||
if osm_type not in 'NWR' or not osm_id[1:].isdigit():
|
||||
LOG.fatal('OSM ID must be of form <N|W|R><id>. Got: %s', osm_id)
|
||||
raise UsageError("OSM ID parameter badly formatted")
|
||||
|
||||
sql += ' WHERE placex.osm_type = %s AND placex.osm_id = %s'
|
||||
values = (osm_type, int(osm_id[1:]))
|
||||
elif place_id is not None:
|
||||
sql += ' WHERE placex.place_id = %s'
|
||||
values = (place_id, )
|
||||
else:
|
||||
LOG.fatal("No OSM object given to index.")
|
||||
raise UsageError("OSM object not found")
|
||||
|
||||
cursor.execute(sql + ' LIMIT 1', values)
|
||||
|
||||
if cursor.rowcount < 1:
|
||||
LOG.fatal("OSM object %s not found in database.", osm_id)
|
||||
raise UsageError("OSM object not found")
|
||||
|
||||
return cursor.fetchone()
|
||||
|
||||
|
||||
def analyse_indexing(config, osm_id=None, place_id=None):
|
||||
""" Analyse indexing of a single Nominatim object.
|
||||
"""
|
||||
with conn.cursor() as cur:
|
||||
if osm_id:
|
||||
osm_type = osm_id[0].upper()
|
||||
if osm_type not in 'NWR' or not osm_id[1:].isdigit():
|
||||
LOG.fatal('OSM ID must be of form <N|W|R><id>. Got: %s', osm_id)
|
||||
raise UsageError("OSM ID parameter badly formatted")
|
||||
cur.execute('SELECT place_id FROM placex WHERE osm_type = %s AND osm_id = %s',
|
||||
(osm_type, osm_id[1:]))
|
||||
with connect(config.get_libpq_dsn()) as conn:
|
||||
register_hstore(conn)
|
||||
with conn.cursor() as cur:
|
||||
place = _get_place_info(cur, osm_id, place_id)
|
||||
|
||||
if cur.rowcount < 1:
|
||||
LOG.fatal("OSM object %s not found in database.", osm_id)
|
||||
raise UsageError("OSM object not found")
|
||||
cur.execute("update placex set indexed_status = 2 where place_id = %s",
|
||||
(place['place_id'], ))
|
||||
|
||||
place_id = cur.fetchone()[0]
|
||||
cur.execute("""SET auto_explain.log_min_duration = '0';
|
||||
SET auto_explain.log_analyze = 'true';
|
||||
SET auto_explain.log_nested_statements = 'true';
|
||||
LOAD 'auto_explain';
|
||||
SET client_min_messages = LOG;
|
||||
SET log_min_messages = FATAL""")
|
||||
|
||||
if place_id is None:
|
||||
LOG.fatal("No OSM object given to index.")
|
||||
raise UsageError("OSM object not found")
|
||||
tokenizer = tokenizer_factory.get_tokenizer_for_db(config)
|
||||
|
||||
cur.execute("update placex set indexed_status = 2 where place_id = %s",
|
||||
(place_id, ))
|
||||
with tokenizer.name_analyzer() as analyzer:
|
||||
cur.execute("""UPDATE placex
|
||||
SET indexed_status = 0, address = %s, token_info = %s,
|
||||
name = %s, linked_place_id = %s
|
||||
WHERE place_id = %s""",
|
||||
(place['address'],
|
||||
Json(analyzer.process_place(PlaceInfo(place))),
|
||||
place['name'], place['linked_place_id'], place['place_id']))
|
||||
|
||||
cur.execute("""SET auto_explain.log_min_duration = '0';
|
||||
SET auto_explain.log_analyze = 'true';
|
||||
SET auto_explain.log_nested_statements = 'true';
|
||||
LOAD 'auto_explain';
|
||||
SET client_min_messages = LOG;
|
||||
SET log_min_messages = FATAL""")
|
||||
# we do not want to keep the results
|
||||
conn.rollback()
|
||||
|
||||
cur.execute("update placex set indexed_status = 0 where place_id = %s",
|
||||
(place_id, ))
|
||||
|
||||
# we do not want to keep the results
|
||||
conn.rollback()
|
||||
|
||||
for msg in conn.notices:
|
||||
print(msg)
|
||||
for msg in conn.notices:
|
||||
print(msg)
|
||||
|
||||
Reference in New Issue
Block a user