X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/f863040b38a6c7586c06623715f1010c268b1f37..c5fe2ac2067c7154370c3abd6ccca45b0d657547:/sql/functions/placex_triggers.sql diff --git a/sql/functions/placex_triggers.sql b/sql/functions/placex_triggers.sql index d6076356..9803e815 100644 --- a/sql/functions/placex_triggers.sql +++ b/sql/functions/placex_triggers.sql @@ -225,6 +225,7 @@ BEGIN WHERE make_standard_name(name->'name') = bnd_name AND placex.rank_address = bnd.rank_address AND placex.osm_type = 'N' + AND placex.rank_search < 26 -- needed to select the right index AND st_covers(geometry, placex.geometry) LOOP --DEBUG: RAISE WARNING 'Found matching place node %', linkedPlacex.osm_id; @@ -235,7 +236,7 @@ BEGIN RETURN NULL; END; $$ -LANGUAGE plpgsql; +LANGUAGE plpgsql STABLE; CREATE OR REPLACE FUNCTION placex_insert() RETURNS TRIGGER @@ -413,7 +414,6 @@ CREATE OR REPLACE FUNCTION placex_update() RETURNS TRIGGER AS $$ DECLARE - near_centroid GEOMETRY; search_maxdistance FLOAT[]; @@ -421,17 +421,13 @@ DECLARE address_havelevel BOOLEAN[]; i INTEGER; - iMax FLOAT; location RECORD; - way RECORD; - relation RECORD; relation_members TEXT[]; addr_item RECORD; search_diameter FLOAT; search_prevdiameter FLOAT; search_maxrank INTEGER; address_maxrank INTEGER; - address_street_word_id INTEGER; address_street_word_ids INTEGER[]; parent_place_id_rank BIGINT; @@ -732,15 +728,20 @@ BEGIN IF NEW.address IS NOT NULL THEN FOR addr_item IN SELECT * FROM each(NEW.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 - address_street_word_id := get_name_id(make_standard_name(addr_item.value)); - IF address_street_word_id IS NOT NULL AND NOT(ARRAY[address_street_word_id] <@ isin_tokens) THEN - isin_tokens := isin_tokens || address_street_word_id; + IF addr_item.key IN ('city', 'tiger:county', 'state', 'suburb', 'province', + 'district', 'region', 'county', 'municipality', + 'hamlet', 'village', 'subdistrict', 'town', + 'neighbourhood', 'quarter', 'parish') + THEN + address_street_word_ids := word_ids_from_name(addr_item.value); + IF address_street_word_ids is not null THEN + isin_tokens := array_merge(isin_tokens, address_street_word_ids); END IF; IF NOT %REVERSE-ONLY% THEN - address_street_word_id := get_word_id(make_standard_name(addr_item.value)); - IF address_street_word_id IS NOT NULL THEN - nameaddress_vector := array_merge(nameaddress_vector, ARRAY[address_street_word_id]); + address_street_word_ids := addr_ids_from_name(addr_item.value); + IF address_street_word_ids is not null THEN + nameaddress_vector := array_merge(nameaddress_vector, + address_street_word_ids); END IF; END IF; END IF; @@ -749,16 +750,17 @@ BEGIN isin := regexp_split_to_array(addr_item.value, E'[;,]'); IF array_upper(isin, 1) IS NOT NULL THEN FOR i IN 1..array_upper(isin, 1) LOOP - address_street_word_id := get_name_id(make_standard_name(isin[i])); - IF address_street_word_id IS NOT NULL AND NOT(ARRAY[address_street_word_id] <@ isin_tokens) THEN - isin_tokens := isin_tokens || address_street_word_id; + address_street_word_ids := word_ids_from_name(isin[i]); + IF address_street_word_ids is not null THEN + isin_tokens := array_merge(isin_tokens, address_street_word_ids); END IF; -- merge word into address vector IF NOT %REVERSE-ONLY% THEN - address_street_word_id := get_word_id(make_standard_name(isin[i])); - IF address_street_word_id IS NOT NULL THEN - nameaddress_vector := array_merge(nameaddress_vector, ARRAY[address_street_word_id]); + address_street_word_ids := addr_ids_from_name(isin[i]); + IF address_street_word_ids is not null THEN + nameaddress_vector := array_merge(nameaddress_vector, + address_street_word_ids); END IF; END IF; END LOOP;