Compare commits

...

3 Commits

Author SHA1 Message Date
Sarah Hoffmann
f43fec0d57 Merge pull request #3764 from lonvia/update-importance
'refresh --importance' also needs to refresh importances in search_name table
2025-06-27 10:02:18 +02:00
Sarah Hoffmann
af82c3debb remove duplicated test
There is a more extensive test of recompute_importance with
result check in test_refresh_wiki_data.py
2025-06-26 22:35:38 +02:00
Sarah Hoffmann
678702ceb7 rewrite importances in search_name after updating in placex 2025-06-26 20:27:37 +02:00
4 changed files with 28 additions and 19 deletions

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2024 by the Nominatim developer community.
# Copyright (C) 2025 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for bringing auxiliary data in the database up-to-date.
@@ -212,6 +212,11 @@ def recompute_importance(conn: Connection) -> None:
WHERE s.place_id = d.linked_place_id and d.wikipedia is not null
and (s.wikipedia is null or s.importance < d.importance);
""")
cur.execute("""
UPDATE search_name s SET importance = p.importance
FROM placex p
WHERE s.place_id = p.place_id AND s.importance != p.importance
""")
cur.execute('ALTER TABLE placex ENABLE TRIGGER ALL')
conn.commit()

View File

@@ -57,12 +57,15 @@ class MockPlacexTable:
housenumber, rank_search,
extratags, geometry, country_code)
VALUES(nextval('seq_place'), %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s)""",
%s, %s, %s, %s, %s, %s)
RETURNING place_id""",
(osm_type, osm_id or next(self.idseq), cls, typ, names,
admin_level, address, housenumber, rank_search,
extratags, 'SRID=4326;' + geom,
country))
place_id = cur.fetchone()[0]
self.conn.commit()
return place_id
class MockPropertyTable:

View File

@@ -41,18 +41,6 @@ def test_refresh_import_wikipedia(dsn, src_dir, table_factory, temp_db_cursor, r
assert temp_db_cursor.table_rows('wikimedia_importance') > 0
def test_recompute_importance(placex_table, table_factory, temp_db_conn, temp_db_cursor):
temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION compute_importance(extratags HSTORE,
country_code varchar(2),
rank_search SMALLINT,
centroid GEOMETRY,
OUT importance FLOAT,
OUT wikipedia TEXT)
AS $$ SELECT 0.1::float, 'foo'::text $$ LANGUAGE SQL""")
refresh.recompute_importance(temp_db_conn)
@pytest.mark.parametrize('osm_type', ('N', 'W', 'R'))
def test_invalidate_osm_object_simple(placex_table, osm_type, temp_db_conn, temp_db_cursor):
placex_table.add(osm_type=osm_type, osm_id=57283)

View File

@@ -2,7 +2,7 @@
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2022 by the Nominatim developer community.
# Copyright (C) 2025 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for correctly assigning wikipedia pages to places.
@@ -37,7 +37,8 @@ def wiki_csv(tmp_path, sql_preprocessor):
@pytest.mark.parametrize('extra', [{'wikipedia:en': 'Test'},
{'wikipedia': 'en:Test'},
{'wikidata': 'Q123'}])
def test_wikipedia(dsn, temp_db_conn, temp_db_cursor, def_config, wiki_csv, placex_table, extra):
def test_wikipedia(dsn, temp_db_conn, temp_db_cursor, table_factory,
def_config, wiki_csv, placex_table, extra):
import_wikipedia_articles(dsn, wiki_csv([('en', 'Test', 0.3, 'Q123')]))
create_functions(temp_db_conn, def_config)
@@ -45,22 +46,34 @@ def test_wikipedia(dsn, temp_db_conn, temp_db_cursor, def_config, wiki_csv, plac
'SELECT language, title, importance, wikidata FROM wikimedia_importance')
assert content == set([('en', 'Test', 0.3, 'Q123')])
placex_table.add(osm_id=12, extratags=extra)
place_id = placex_table.add(osm_id=12, extratags=extra)
table_factory('search_name',
'place_id BIGINT, importance FLOAT',
[(place_id, 0.2)])
recompute_importance(temp_db_conn)
content = temp_db_cursor.row_set('SELECT wikipedia, importance FROM placex')
assert content == set([('en:Test', 0.3)])
simp = temp_db_cursor.scalar('SELECT importance FROM search_name WHERE place_id = %s',
(place_id,))
assert simp == 0.3
def test_wikipedia_no_match(dsn, temp_db_conn, temp_db_cursor, def_config, wiki_csv,
placex_table):
placex_table, table_factory):
import_wikipedia_articles(dsn, wiki_csv([('de', 'Test', 0.3, 'Q123')]))
create_functions(temp_db_conn, def_config)
placex_table.add(osm_id=12, extratags={'wikipedia': 'en:Test'}, rank_search=10)
place_id = placex_table.add(osm_id=12, extratags={'wikipedia': 'en:Test'}, rank_search=10)
table_factory('search_name',
'place_id BIGINT, importance FLOAT',
[(place_id, 0.2)])
recompute_importance(temp_db_conn)
content = temp_db_cursor.row_set('SELECT wikipedia, importance FROM placex')
assert list(content) == [(None, pytest.approx(0.26667666))]
simp = temp_db_cursor.scalar('SELECT importance FROM search_name WHERE place_id = %s',
(place_id,))
assert simp == pytest.approx(0.26667666)