lookup places for address tags for rank < 30

While previously the content of addr:* tags was only added
to the list of address search keywords, we now really look up
the matching place. This has the advantage that we pull in all
potential translations from the place, just like all the other
address terms that are looked up by neighbourhood search.

If no place can be found for a given name, the content of the
addr:* tag is still added to the search keywords as before.
This commit is contained in:
Sarah Hoffmann
2020-11-09 12:03:37 +01:00
parent fecfe62fc6
commit c7472662a6
4 changed files with 141 additions and 38 deletions

View File

@@ -254,6 +254,7 @@ CREATE OR REPLACE FUNCTION insert_addresslines(obj_place_id BIGINT,
maxrank SMALLINT,
address HSTORE,
geometry GEOMETRY,
country TEXT,
OUT parent_place_id BIGINT,
OUT postcode TEXT,
OUT nameaddress_vector INT[])
@@ -265,45 +266,49 @@ DECLARE
current_boundary GEOMETRY := NULL;
current_node_area GEOMETRY := NULL;
location RECORD;
addr_item RECORD;
parent_place_rank INT := 0;
addr_place_ids BIGINT[];
isin_tokens INT[];
location RECORD;
BEGIN
parent_place_id := 0;
nameaddress_vector := '{}'::int[];
isin_tokens := '{}'::int[];
---- convert address store to array of tokenids
IF address IS NOT NULL THEN
FOR addr_item IN SELECT * FROM each(address)
LOOP
IF addr_item.key IN ('city', 'tiger:county', 'state', 'suburb', 'province',
'district', 'region', 'county', 'municipality',
'hamlet', 'village', 'subdistrict', 'town',
'neighbourhood', 'quarter', 'parish')
THEN
isin_tokens := array_merge(isin_tokens,
word_ids_from_name(addr_item.value));
IF NOT %REVERSE-ONLY% THEN
nameaddress_vector := array_merge(nameaddress_vector,
addr_ids_from_name(addr_item.value));
address_havelevel := array_fill(false, ARRAY[maxrank]);
FOR location IN
SELECT * FROM get_places_for_addr_tags(partition, geometry,
address, country)
ORDER BY rank_address, distance, isguess desc
LOOP
IF NOT %REVERSE-ONLY% THEN
nameaddress_vector := array_merge(nameaddress_vector,
location.keywords::int[]);
END IF;
IF location.place_id is not null THEN
location_isaddress := not address_havelevel[location.rank_address];
IF not address_havelevel[location.rank_address] THEN
address_havelevel[location.rank_address] := true;
IF parent_place_rank < location.rank_address THEN
parent_place_id := location.place_id;
parent_place_rank := location.rank_address;
END IF;
END IF;
END LOOP;
END IF;
IF NOT %REVERSE-ONLY% THEN
nameaddress_vector := array_merge(nameaddress_vector, isin_tokens);
END IF;
---- now compute the address terms
FOR i IN 1..maxrank LOOP
address_havelevel[i] := false;
INSERT INTO place_addressline (place_id, address_place_id, fromarea,
isaddress, distance, cached_rank_address)
VALUES (obj_place_id, location.place_id, not location.isguess,
true, location.distance, location.rank_address);
addr_place_ids := array_append(addr_place_ids, location.place_id);
END IF;
END LOOP;
FOR location IN
SELECT * FROM getNearFeatures(partition, geometry, maxrank)
ORDER BY rank_address, isin_tokens && keywords desc, isguess asc,
WHERE addr_place_ids is null or not addr_place_ids @> ARRAY[place_id]
ORDER BY rank_address, isguess asc,
distance *
CASE WHEN rank_address = 16 AND rank_search = 15 THEN 0.2
WHEN rank_address = 16 AND rank_search = 16 THEN 0.25
@@ -920,7 +925,8 @@ BEGIN
NEW.address,
CASE WHEN (NEW.rank_address = 0 or
NEW.rank_search between 26 and 29)
THEN NEW.geometry ELSE NEW.centroid END)
THEN NEW.geometry ELSE NEW.centroid END,
NEW.country_code)
INTO NEW.parent_place_id, NEW.postcode, nameaddress_vector;
--DEBUG: RAISE WARNING 'RETURN insert_addresslines: %, %, %', NEW.parent_place_id, NEW.postcode, nameaddress_vector;

View File

@@ -233,3 +233,50 @@ BEGIN
END;
$$
LANGUAGE plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION get_addr_tag_rank(key TEXT, country TEXT,
OUT from_rank SMALLINT,
OUT to_rank SMALLINT,
OUT extent FLOAT)
AS $$
DECLARE
ranks RECORD;
BEGIN
from_rank := null;
FOR ranks IN
SELECT * FROM
(SELECT l.rank_search, l.rank_address FROM address_levels l
WHERE (l.country_code = country or l.country_code is NULL)
AND l.class = 'place' AND l.type = key
ORDER BY l.country_code LIMIT 1) r
WHERE rank_address > 0
LOOP
extent := reverse_place_diameter(ranks.rank_search);
IF ranks.rank_address <= 4 THEN
from_rank := 4;
to_rank := 4;
ELSEIF ranks.rank_address <= 9 THEN
from_rank := 5;
to_rank := 9;
ELSEIF ranks.rank_address <= 12 THEN
from_rank := 10;
to_rank := 12;
ELSEIF ranks.rank_address <= 16 THEN
from_rank := 13;
to_rank := 16;
ELSEIF ranks.rank_address <= 21 THEN
from_rank := 17;
to_rank := 21;
ELSEIF ranks.rank_address <= 24 THEN
from_rank := 22;
to_rank := 24;
ELSE
from_rank := 25;
to_rank := 25;
END IF;
END LOOP;
END;
$$
LANGUAGE plpgsql IMMUTABLE;