mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 02:58:13 +00:00
rewrite importances in search_name after updating in placex
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of Nominatim. (https://nominatim.org)
|
# 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.
|
# For a full list of authors see the git log.
|
||||||
"""
|
"""
|
||||||
Functions for bringing auxiliary data in the database up-to-date.
|
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
|
WHERE s.place_id = d.linked_place_id and d.wikipedia is not null
|
||||||
and (s.wikipedia is null or s.importance < d.importance);
|
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')
|
cur.execute('ALTER TABLE placex ENABLE TRIGGER ALL')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|||||||
@@ -57,12 +57,15 @@ class MockPlacexTable:
|
|||||||
housenumber, rank_search,
|
housenumber, rank_search,
|
||||||
extratags, geometry, country_code)
|
extratags, geometry, country_code)
|
||||||
VALUES(nextval('seq_place'), %s, %s, %s, %s, %s, %s,
|
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,
|
(osm_type, osm_id or next(self.idseq), cls, typ, names,
|
||||||
admin_level, address, housenumber, rank_search,
|
admin_level, address, housenumber, rank_search,
|
||||||
extratags, 'SRID=4326;' + geom,
|
extratags, 'SRID=4326;' + geom,
|
||||||
country))
|
country))
|
||||||
|
place_id = cur.fetchone()[0]
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
return place_id
|
||||||
|
|
||||||
|
|
||||||
class MockPropertyTable:
|
class MockPropertyTable:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of Nominatim. (https://nominatim.org)
|
# 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.
|
# For a full list of authors see the git log.
|
||||||
"""
|
"""
|
||||||
Tests for correctly assigning wikipedia pages to places.
|
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'},
|
@pytest.mark.parametrize('extra', [{'wikipedia:en': 'Test'},
|
||||||
{'wikipedia': 'en:Test'},
|
{'wikipedia': 'en:Test'},
|
||||||
{'wikidata': 'Q123'}])
|
{'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')]))
|
import_wikipedia_articles(dsn, wiki_csv([('en', 'Test', 0.3, 'Q123')]))
|
||||||
create_functions(temp_db_conn, def_config)
|
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')
|
'SELECT language, title, importance, wikidata FROM wikimedia_importance')
|
||||||
assert content == set([('en', 'Test', 0.3, 'Q123')])
|
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)
|
recompute_importance(temp_db_conn)
|
||||||
|
|
||||||
content = temp_db_cursor.row_set('SELECT wikipedia, importance FROM placex')
|
content = temp_db_cursor.row_set('SELECT wikipedia, importance FROM placex')
|
||||||
assert content == set([('en:Test', 0.3)])
|
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,
|
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')]))
|
import_wikipedia_articles(dsn, wiki_csv([('de', 'Test', 0.3, 'Q123')]))
|
||||||
create_functions(temp_db_conn, def_config)
|
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)
|
recompute_importance(temp_db_conn)
|
||||||
|
|
||||||
content = temp_db_cursor.row_set('SELECT wikipedia, importance FROM placex')
|
content = temp_db_cursor.row_set('SELECT wikipedia, importance FROM placex')
|
||||||
assert list(content) == [(None, pytest.approx(0.26667666))]
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user