]> git.openstreetmap.org Git - nominatim.git/commitdiff
more invalidations when boundary changes rank
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 11 Aug 2022 21:44:09 +0000 (23:44 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sat, 19 Nov 2022 14:43:08 +0000 (15:43 +0100)
When a boundary or place changes its address rank, all places where
it participates as address need to be potentially reindexed.
Also use the computed rank when testing place nodes against
boundaries. Boundaries are computed earlier.

Fixes #2794.

lib-sql/functions/placex_triggers.sql
test/bdd/db/update/linked_places.feature

index 70071b2f592f0c6a38f1a19a02bb0f7ddd95b8f1..bb34883a44fe5b9482e91ae89c1c59bfa3af6b41 100644 (file)
@@ -916,7 +916,8 @@ BEGIN
              LATERAL compute_place_rank(country_code, 'A', class, type,
                                         admin_level, False, null) prank
         WHERE osm_type = 'R'
-              and prank.address_rank = NEW.rank_address
+              and ((class = 'place' and prank.address_rank = NEW.rank_address)
+                   or (class = 'boundary' and rank_address = NEW.rank_address))
               and geometry && NEW.centroid and _ST_Covers(geometry, NEW.centroid)
         LIMIT 1
     LOOP
@@ -1101,6 +1102,15 @@ BEGIN
     END IF;
   END IF;
 
+  {% if not disable_diff_updates %}
+  IF OLD.rank_address != NEW.rank_address THEN
+    -- After a rank shift all addresses containing us must be updated.
+    UPDATE placex p SET indexed_status = 2 FROM place_addressline pa
+      WHERE pa.address_place_id = NEW.place_id and p.place_id = pa.place_id
+            and p.indexed_status = 0 and p.rank_address between 4 and 25;
+  END IF;
+  {% endif %}
+
   IF NEW.admin_level = 2
      AND NEW.class = 'boundary' AND NEW.type = 'administrative'
      AND NEW.country_code IS NOT NULL AND NEW.osm_type = 'R'
index 3b34039d367322451b200ca1c0ecc711aea654ec..c277e8bd1e69c47f0f256dcecadcdff8030c4996 100644 (file)
@@ -307,3 +307,35 @@ Feature: Updates of linked places
             | object | linked_place_id | rank_address |
             | N1     | R1              | 16           |
             | R1     | -               | 16           |
+
+
+    Scenario: Invalidate surrounding place nodes when place type changes
+        Given the grid
+            | 1 |   |   | 2 |
+            |   | 8 | 9 |   |
+            | 4 |   |   | 3 |
+        And the places
+            | osm | class    | type           | name | admin | geometry    |
+            | R1  | boundary | administrative | foo  | 8     | (1,2,3,4,1) |
+        And the places
+            | osm | class | type | name | geometry |
+            | N1  | place | town | foo  | 9        |
+            | N2  | place | city | bar  | 8        |
+        And the relations
+         | id | members  |
+         | 1  | N1:label |
+        When importing
+        Then placex contains
+            | object | linked_place_id | rank_address |
+            | N1     | R1              | 16           |
+            | R1     | -               | 16           |
+            | N2     | -               | 18           |
+
+        When updating places
+            | osm | class | type   | name | geometry |
+            | N1  | place | suburb | foo  | 9        |
+        Then placex contains
+            | object | linked_place_id | rank_address |
+            | N1     | R1              | 20           |
+            | R1     | -               | 20           |
+            | N2     | -               | 16           |