X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/625b1cd17dd486fef9e6d020b1a2079a976808ed..fd3fcea539878b8f96cb9bcad51152459442ab48:/sql/functions.sql

diff --git a/sql/functions.sql b/sql/functions.sql
index b61f52b2..b248a46d 100644
--- a/sql/functions.sql
+++ b/sql/functions.sql
@@ -909,7 +909,12 @@ BEGIN
   NEW.place_id := nextval('seq_place');
   NEW.indexed_status := 1; --STATUS_NEW
 
-  NEW.country_code := lower(get_country_code(NEW.geometry, NEW.country_code));
+  IF NEW.rank_search >= 4 THEN
+    NEW.country_code := lower(get_country_code(NEW.geometry, NEW.country_code));
+  ELSE
+    NEW.country_code := NULL;
+  END IF;
+
   NEW.partition := get_partition(NEW.geometry, NEW.country_code);
   NEW.geometry_sector := geometry_sector(NEW.partition, NEW.geometry);
 
@@ -920,7 +925,7 @@ BEGIN
       IF NEW.name ? 'name' AND NOT NEW.name ? ('name:'||default_language) THEN
         NEW.name := NEW.name || (('name:'||default_language) => (NEW.name -> 'name'));
       ELSEIF NEW.name ? ('name:'||default_language) AND NOT NEW.name ? 'name' THEN
-        NEW.name := NEW.name || ('name' => (NEW.name -> 'name:'||default_language));
+        NEW.name := NEW.name || ('name' => (NEW.name -> ('name:'||default_language)));
       END IF;
     END IF;
   END IF;
@@ -942,6 +947,11 @@ BEGIN
     -- By doing in postgres we have the country available to us - currently only used for postcode
     IF NEW.class in ('place','boundary') AND NEW.type in ('postcode','postal_code') THEN
 
+        IF NEW.postcode IS NULL THEN
+            -- most likely just a part of a multipolygon postcode boundary, throw it away
+            RETURN NULL;
+        END IF;
+
         NEW.name := 'ref'=>NEW.postcode;
 
         IF NEW.country_code = 'gb' THEN
@@ -1032,6 +1042,10 @@ BEGIN
       ELSEIF NEW.type in ('farm','locality','islet','isolated_dwelling','mountain_pass') THEN
         NEW.rank_search := 20;
         NEW.rank_address := 0;
+        -- Irish townlands, tagged as place=locality and locality=townland
+        IF (NEW.extratags -> 'locality') = 'townland' THEN
+          NEW.rank_address := 20;
+        END IF;
       ELSEIF NEW.type in ('hall_of_residence','neighbourhood','housing_estate','nature_reserve') THEN
         NEW.rank_search := 22;
         NEW.rank_address := 22;
@@ -1247,8 +1261,12 @@ BEGIN
     END IF;
 
     -- reclaculate country and partition (should probably have a country_code and calculated_country_code as seperate fields)
-    SELECT country_code from place where osm_type = NEW.osm_type and osm_id = NEW.osm_id and class = NEW.class and type = NEW.type INTO NEW.country_code;
-    NEW.country_code := lower(get_country_code(NEW.geometry, NEW.country_code));
+    IF NEW.rank_search >= 4 THEN
+      SELECT country_code from place where osm_type = NEW.osm_type and osm_id = NEW.osm_id and class = NEW.class and type = NEW.type INTO NEW.country_code;
+      NEW.country_code := lower(get_country_code(NEW.geometry, NEW.country_code));
+    ELSE
+      NEW.country_code := NULL;
+    END IF;
     NEW.partition := get_partition(NEW.geometry, NEW.country_code);
     NEW.geometry_sector := geometry_sector(NEW.partition, NEW.geometry);
 
@@ -1271,7 +1289,7 @@ BEGIN
         IF NEW.name ? 'name' AND NOT NEW.name ? ('name:'||default_language) THEN
           NEW.name := NEW.name || (('name:'||default_language) => (NEW.name -> 'name'));
         ELSEIF NEW.name ? ('name:'||default_language) AND NOT NEW.name ? 'name' THEN
-          NEW.name := NEW.name || ('name' => (NEW.name -> 'name:'||default_language));
+          NEW.name := NEW.name || ('name' => (NEW.name -> ('name:'||default_language)));
         END IF;
       END IF;
     END IF;
