reset address and search ranks on update

With ranks being dynamically changed through linking of places,
it is important to reset the ranks on update, so that changes
of the rank due to changes in linking are correctly taken into
account.
This commit is contained in:
Sarah Hoffmann
2020-04-11 09:20:13 +02:00
parent c6d859a08a
commit cd96354bc7
2 changed files with 32 additions and 10 deletions

View File

@@ -392,7 +392,6 @@ DECLARE
country_code VARCHAR(2);
diameter FLOAT;
classtable TEXT;
classtype TEXT;
BEGIN
--DEBUG: RAISE WARNING '% % % %',NEW.osm_type,NEW.osm_id,NEW.class,NEW.type;
@@ -428,8 +427,9 @@ BEGIN
END IF;
SELECT * INTO NEW.rank_search, NEW.rank_address
FROM compute_place_rank(NEW.country_code, NEW.osm_type, NEW.class,
NEW.type, NEW.admin_level, is_area,
FROM compute_place_rank(NEW.country_code,
CASE WHEN is_area THEN 'A' ELSE NEW.osm_type END,
NEW.class, NEW.type, NEW.admin_level,
(NEW.extratags->'capital') = 'yes',
NEW.address->'postcode');
@@ -552,6 +552,17 @@ BEGIN
RETURN NEW;
END IF;
-- recompute the ranks, they might change when linking changes
SELECT * INTO NEW.rank_search, NEW.rank_address
FROM compute_place_rank(NEW.country_code,
CASE WHEN ST_GeometryType(NEW.geometry)
IN ('ST_Polygon','ST_MultiPolygon')
THEN 'A' ELSE NEW.osm_type END,
NEW.class, NEW.type, NEW.admin_level,
(NEW.extratags->'capital') = 'yes',
NEW.address->'postcode');
--DEBUG: RAISE WARNING 'Copy over address tags';
-- housenumber is a computed field, so start with an empty value
NEW.housenumber := NULL;