def import_and_index_data_from_place_table(context): """ Import data previously set up in the place table. """ nctx = context.nominatim tokenizer = tokenizer_factory.create_tokenizer(nctx.get_test_config()) context.nominatim.copy_from_place(context.db) # XXX use tool function as soon as it is ported with context.db.cursor() as cur: with (context.nominatim.src_dir / 'lib-sql' / 'postcode_tables.sql').open('r') as fd: cur.execute(fd.read()) cur.execute(""" INSERT INTO location_postcode (place_id, indexed_status, country_code, postcode, geometry) SELECT nextval('seq_place'), 1, country_code, upper(trim (both ' ' from address->'postcode')) as pc, ST_Centroid(ST_Collect(ST_Centroid(geometry))) FROM placex WHERE address ? 'postcode' AND address->'postcode' NOT SIMILAR TO '%(,|;)%' AND geometry IS NOT null GROUP BY country_code, pc""") # Call directly as the refresh function does not include postcodes. indexer.LOG.setLevel(logging.ERROR) indexer.Indexer(context.nominatim.get_libpq_dsn(), tokenizer, 1).index_full(analyse=False) check_database_integrity(context)
def test_index_reopen_connection(test_db, threads, monkeypatch): monkeypatch.setattr(indexer.WorkerPool, "REOPEN_CONNECTIONS_AFTER", 15) for _ in range(1000): test_db.add_place(rank_address=30, rank_search=30) idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads) idx.index_by_rank(28, 30) assert 0 == test_db.placex_unindexed()
def test_index_postcodes(test_db, threads): for postcode in range(1000): test_db.add_postcode('de', postcode) for postcode in range(32000, 33000): test_db.add_postcode('us', postcode) idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads) idx.index_postcodes() assert 0 == test_db.scalar("""SELECT count(*) FROM location_postcode WHERE indexed_status != 0""")
def test_index_full(test_db, analyse): for rank in range(4, 10): test_db.add_admin(rank_address=rank, rank_search=rank) for rank in range(31): test_db.add_place(rank_address=rank, rank_search=rank) test_db.add_osmline() for postcode in range(1000): test_db.add_postcode('de', postcode) idx = indexer.Indexer('dbname=test_nominatim_python_unittest', 4) idx.index_full(analyse=analyse) assert 0 == test_db.placex_unindexed() assert 0 == test_db.osmline_unindexed() assert 0 == test_db.scalar("""SELECT count(*) FROM location_postcode WHERE indexed_status != 0""")
def test_index_all_by_rank(test_db, threads, test_tokenizer): for rank in range(31): test_db.add_place(rank_address=rank, rank_search=rank) test_db.add_osmline() assert test_db.placex_unindexed() == 31 assert test_db.osmline_unindexed() == 1 idx = indexer.Indexer('dbname=test_nominatim_python_unittest', test_tokenizer, threads) idx.index_by_rank(0, 30) assert test_db.placex_unindexed() == 0 assert test_db.osmline_unindexed() == 0 assert test_db.scalar("""SELECT count(*) from placex WHERE indexed_status = 0 and indexed_date is null""" ) == 0 # ranks come in order of rank address assert test_db.scalar(""" SELECT count(*) FROM placex p WHERE rank_address > 0 AND indexed_date >= (SELECT min(indexed_date) FROM placex o WHERE p.rank_address < o.rank_address)""") == 0 # placex rank < 30 objects come before interpolations assert test_db.scalar( """SELECT count(*) FROM placex WHERE rank_address < 30 AND indexed_date > (SELECT min(indexed_date) FROM location_property_osmline)""" ) == 0 # placex rank = 30 objects come after interpolations assert test_db.scalar( """SELECT count(*) FROM placex WHERE rank_address = 30 AND indexed_date < (SELECT max(indexed_date) FROM location_property_osmline)""" ) == 0 # rank 0 comes after rank 29 and before rank 30 assert test_db.scalar( """SELECT count(*) FROM placex WHERE rank_address < 30 AND indexed_date > (SELECT min(indexed_date) FROM placex WHERE rank_address = 0)""" ) == 0 assert test_db.scalar( """SELECT count(*) FROM placex WHERE rank_address = 30 AND indexed_date < (SELECT max(indexed_date) FROM placex WHERE rank_address = 0)""" ) == 0
def test_index_partial_with_30(test_db, threads, test_tokenizer): for rank in range(31): test_db.add_place(rank_address=rank, rank_search=rank) test_db.add_osmline() assert test_db.placex_unindexed() == 31 assert test_db.osmline_unindexed() == 1 idx = indexer.Indexer('dbname=test_nominatim_python_unittest', test_tokenizer, threads) idx.index_by_rank(28, 30) assert test_db.placex_unindexed() == 27 assert test_db.osmline_unindexed() == 0 assert test_db.scalar(""" SELECT count(*) FROM placex WHERE indexed_status = 0 AND rank_address between 1 and 27""") == 0
def test_index_partial_without_30(test_db, threads): for rank in range(31): test_db.add_place(rank_address=rank, rank_search=rank) test_db.add_osmline() assert 31 == test_db.placex_unindexed() assert 1 == test_db.osmline_unindexed() idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads) idx.index_by_rank(4, 15) assert 19 == test_db.placex_unindexed() assert 1 == test_db.osmline_unindexed() assert 0 == test_db.scalar(""" SELECT count(*) FROM placex WHERE indexed_status = 0 AND not rank_address between 4 and 15""" )
def test_index_boundaries(test_db, threads): for rank in range(4, 10): test_db.add_admin(rank_address=rank, rank_search=rank) for rank in range(31): test_db.add_place(rank_address=rank, rank_search=rank) test_db.add_osmline() assert 37 == test_db.placex_unindexed() assert 1 == test_db.osmline_unindexed() idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads) idx.index_boundaries(0, 30) assert 31 == test_db.placex_unindexed() assert 1 == test_db.osmline_unindexed() assert 0 == test_db.scalar(""" SELECT count(*) FROM placex WHERE indexed_status = 0 AND class != 'boundary'""")