X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/d75a235c1f9ad7bc490ee01ea360d62ddfa54e8e..f3c4196c758a7720aefc26a7043bf1c6553028e2:/lib-sql/functions/placex_triggers.sql?ds=sidebyside diff --git a/lib-sql/functions/placex_triggers.sql b/lib-sql/functions/placex_triggers.sql index b97b9103..fa7156ec 100644 --- a/lib-sql/functions/placex_triggers.sql +++ b/lib-sql/functions/placex_triggers.sql @@ -11,13 +11,15 @@ CREATE OR REPLACE FUNCTION placex_prepare_update(p placex, OUT name HSTORE, OUT address HSTORE, - OUT country_feature VARCHAR) + OUT country_feature VARCHAR, + OUT linked_place_id BIGINT) AS $$ +DECLARE + location RECORD; BEGIN -- For POI nodes, check if the address should be derived from a surrounding -- building. IF p.rank_search < 30 OR p.osm_type != 'N' OR p.address is not null THEN - RAISE WARNING 'self address for % %', p.osm_type, p.osm_id; address := p.address; ELSE -- The additional && condition works around the misguided query @@ -30,12 +32,23 @@ BEGIN and (placex.address ? 'housenumber' or placex.address ? 'street' or placex.address ? 'place') and rank_search = 30 AND ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') LIMIT 1; - RAISE WARNING 'other address for % %: % (%)', p.osm_type, p.osm_id, address, p.centroid; END IF; address := address - '_unlisted_place'::TEXT; name := p.name; + -- Names of linked places need to be merged in, so search for a linkable + -- place already here. + SELECT * INTO location FROM find_linked_place(p); + + IF location.place_id is not NULL THEN + linked_place_id := location.place_id; + + IF NOT location.name IS NULL THEN + name := location.name || name; + END IF; + END IF; + country_feature := CASE WHEN p.admin_level = 2 and p.class = 'boundary' and p.type = 'administrative' and p.osm_type = 'R' @@ -685,6 +698,8 @@ DECLARE nameaddress_vector INTEGER[]; addr_nameaddress_vector INTEGER[]; + linked_place BIGINT; + linked_node_id BIGINT; linked_importance FLOAT; linked_wikipedia TEXT; @@ -720,9 +735,14 @@ BEGIN NEW.extratags := NEW.extratags - 'linked_place'::TEXT; + -- NEW.linked_place_id contains the precomputed linkee. Save this and restore + -- the previous link status. + linked_place := NEW.linked_place_id; + NEW.linked_place_id := OLD.linked_place_id; + IF NEW.linked_place_id is not null THEN NEW.token_info := null; - {% if debug %}RAISE WARNING 'place already linked to %', NEW.linked_place_id;{% endif %} + {% if debug %}RAISE WARNING 'place already linked to %', OLD.linked_place_id;{% endif %} RETURN NEW; END IF; @@ -913,7 +933,7 @@ BEGIN -- determine postcode NEW.postcode := coalesce(token_normalized_postcode(NEW.address->'postcode'), location.postcode, - get_nearest_postcode(NEW.country_code, NEW.geometry)); + get_nearest_postcode(NEW.country_code, NEW.centroid)); IF NEW.name is not NULL THEN NEW.name := add_default_place_name(NEW.country_code, NEW.name); @@ -958,8 +978,9 @@ BEGIN -- --------------------------------------------------------------------------- -- Full indexing {% if debug %}RAISE WARNING 'Using full index mode for % %', NEW.osm_type, NEW.osm_id;{% endif %} - SELECT * INTO location FROM find_linked_place(NEW); - IF location.place_id is not null THEN + IF linked_place is not null THEN + SELECT * INTO location FROM placex WHERE place_id = linked_place; + {% if debug %}RAISE WARNING 'Linked %', location;{% endif %} -- Use the linked point as the centre point of the geometry, @@ -976,11 +997,6 @@ BEGIN NEW.rank_address := location.rank_address; END IF; - -- merge in the label name - IF NOT location.name IS NULL THEN - NEW.name := location.name || NEW.name; - END IF; - -- merge in extra tags NEW.extratags := hstore('linked_' || location.class, location.type) || coalesce(location.extratags, ''::hstore)