]> git.openstreetmap.org Git - nominatim.git/blobdiff - sql/functions.sql
force update of linker when linkee is updates
[nominatim.git] / sql / functions.sql
index da496a10c34cb9ed7ab5aa83e86bb5b06a713c1c..a49ba02bc2cf4d48ba04f0c630943bcefcd834a6 100644 (file)
@@ -1491,7 +1491,7 @@ BEGIN
     IF relation_members IS NOT NULL THEN
       FOR relMember IN select get_osm_rel_members(relation_members,ARRAY['label']) as member LOOP
 
-        FOR linkedPlacex IN select * from placex where osm_type = upper(substring(relMember.member,1,1))::"char"
+        FOR linkedPlacex IN select * from placex where osm_type = upper(substring(relMember.member,1,1))::char(1) 
           and osm_id = substring(relMember.member,2,10000)::bigint order by rank_search desc limit 1 LOOP
 
           -- If we don't already have one use this as the centre point of the geometry
@@ -1522,7 +1522,7 @@ BEGIN
 
         FOR relMember IN select get_osm_rel_members(relation_members,ARRAY['admin_center','admin_centre']) as member LOOP
 
-          FOR linkedPlacex IN select * from placex where osm_type = upper(substring(relMember.member,1,1))::"char"
+          FOR linkedPlacex IN select * from placex where osm_type = upper(substring(relMember.member,1,1))::char(1) 
             and osm_id = substring(relMember.member,2,10000)::bigint order by rank_search desc limit 1 LOOP
 
             -- For an admin centre we also want a name match - still not perfect, for example 'new york, new york'
@@ -1571,7 +1571,7 @@ BEGIN
         make_standard_name(name->'name') = make_standard_name(NEW.name->'name')
         AND placex.rank_address = NEW.rank_address
         AND placex.place_id != NEW.place_id
-        AND placex.osm_type = 'N' AND placex.rank_search < 26
+        AND placex.osm_type = 'N'::char(1) AND placex.rank_search < 26
         AND st_covers(NEW.geometry, placex.geometry)
       LOOP
 
@@ -1621,7 +1621,7 @@ BEGIN
 
     -- Still null? how about looking it up by the node id
     IF NEW.importance IS NULL THEN
-      select language||':'||title,importance from wikipedia_article where osm_type = 'N' and osm_id = linked_node_id order by importance desc limit 1 INTO NEW.wikipedia,NEW.importance;
+      select language||':'||title,importance from wikipedia_article where osm_type = 'N'::char(1) and osm_id = linked_node_id order by importance desc limit 1 INTO NEW.wikipedia,NEW.importance;
     END IF;
 
   END IF;
@@ -2144,6 +2144,12 @@ BEGIN
           NEW.name := hstore('ref', NEW.address->'postcode');
       END IF;
 
+      IF NEW.class in ('boundary')
+         AND ST_GeometryType(NEW.geometry) not in ('ST_Polygon','ST_MultiPolygon') THEN
+          DELETE FROM placex where place_id = existingplacex.place_id;
+          RETURN NULL;
+      END IF;
+
       update placex set 
         name = NEW.name,
         address = NEW.address,
@@ -2161,6 +2167,20 @@ BEGIN
           update location_property_osmline p set indexed_status = 2 from planet_osm_ways w where p.linegeo && NEW.geometry and p.osm_id = w.id and NEW.osm_id = any(w.nodes);
       END IF;
 
+      -- linked places should get potential new naming and addresses
+      IF existingplacex.linked_place_id is not NULL THEN
+        update placex x set
+          name = p.name,
+          extratags = p.extratags,
+          indexed_status = 2
+        from place p
+        where x.place_id = existingplacex.linked_place_id
+              and x.indexed_status = 0
+              and x.osm_type = p.osm_type
+              and x.osm_id = p.osm_id
+              and x.class = p.class;
+      END IF;
+
     END IF;
 
     -- Abort the add (we modified the existing place instead)