X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/f1063497efe41f3a8775048fac91b5799cf636f6..20f1939c4c61ef28b128593b2ae5f841af567042:/sql/functions.sql?ds=inline

diff --git a/sql/functions.sql b/sql/functions.sql
index 32af414d..035eaf90 100644
--- a/sql/functions.sql
+++ b/sql/functions.sql
@@ -1068,6 +1068,9 @@ BEGIN
     ELSEIF NEW.class = 'landuse' AND ST_GeometryType(NEW.geometry) in ('ST_Polygon','ST_MultiPolygon') THEN
       NEW.rank_search := 22;
       NEW.rank_address := NEW.rank_search;
+    ELSEIF NEW.class = 'natural' and NEW.type in ('peak','volcano','mountain_range') THEN
+      NEW.rank_search := 18;
+      NEW.rank_address := 0;
     -- any feature more than 5 square miles is probably worth indexing
     ELSEIF ST_GeometryType(NEW.geometry) in ('ST_Polygon','ST_MultiPolygon') AND ST_Area(NEW.geometry) > 0.1 THEN
       NEW.rank_search := 22;
@@ -1093,9 +1096,6 @@ BEGIN
       NEW.rank_address := NEW.rank_search;
     ELSEIF NEW.class = 'natural' and NEW.type in ('coastline') THEN
       RETURN NULL;
-    ELSEIF NEW.class = 'natural' and NEW.type in ('peak','volcano') THEN
-      NEW.rank_search := 18;
-      NEW.rank_address := 0;
     END IF;
 
   END IF;
@@ -1502,74 +1502,76 @@ BEGIN
       select members from planet_osm_rels where id = NEW.osm_id INTO relation_members;
 
 -- RAISE WARNING 'get_osm_rel_members, label';
-      FOR relMember IN select get_osm_rel_members(relation_members,ARRAY['label']) as member LOOP
+      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(1) 
-          and osm_id = substring(relMember.member,2,10000)::bigint order by rank_search desc limit 1 LOOP
+          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
-          IF NEW.centroid IS NULL THEN
-            NEW.centroid := coalesce(linkedPlacex.centroid,st_centroid(linkedPlacex.geometry));
-          END IF;
+            -- If we don't already have one use this as the centre point of the geometry
+            IF NEW.centroid IS NULL THEN
+              NEW.centroid := coalesce(linkedPlacex.centroid,st_centroid(linkedPlacex.geometry));
+            END IF;
 
-          -- merge in the label name, re-init word vector
-          IF NOT linkedPlacex.name IS NULL THEN
-            NEW.name := linkedPlacex.name || NEW.name;
-            name_vector := make_keywords(NEW.name);
-          END IF;
+            -- merge in the label name, re-init word vector
+            IF NOT linkedPlacex.name IS NULL THEN
+              NEW.name := linkedPlacex.name || NEW.name;
+              name_vector := make_keywords(NEW.name);
+            END IF;
 
-          -- merge in extra tags
-          IF NOT linkedPlacex.extratags IS NULL THEN
-            NEW.extratags := linkedPlacex.extratags || NEW.extratags;
-          END IF;
+            -- merge in extra tags
+            IF NOT linkedPlacex.extratags IS NULL THEN
+              NEW.extratags := linkedPlacex.extratags || NEW.extratags;
+            END IF;
 
-          -- mark the linked place (excludes from search results)
-          UPDATE placex set linked_place_id = NEW.place_id where place_id = linkedPlacex.place_id;
+            -- mark the linked place (excludes from search results)
+            UPDATE placex set linked_place_id = NEW.place_id where place_id = linkedPlacex.place_id;
+
+          END LOOP;
 
         END LOOP;
 
-      END LOOP;
+        IF NEW.centroid IS NULL THEN
 
-      IF NEW.centroid IS NULL THEN
+          FOR relMember IN select get_osm_rel_members(relation_members,ARRAY['admin_center','admin_centre']) as member LOOP
 
-        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(1) 
+              and osm_id = substring(relMember.member,2,10000)::bigint order by rank_search desc limit 1 LOOP
 
-          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'
+              -- But that can be fixed by explicitly setting the label in the data
+              IF make_standard_name(NEW.name->'name') = make_standard_name(linkedPlacex.name->'name') 
+                AND NEW.rank_address = linkedPlacex.rank_address THEN
 
-            -- For an admin centre we also want a name match - still not perfect, for example 'new york, new york'
-            -- But that can be fixed by explicitly setting the label in the data
-            IF make_standard_name(NEW.name->'name') = make_standard_name(linkedPlacex.name->'name') 
-              AND NEW.rank_address = linkedPlacex.rank_address THEN
 
+                -- If we don't already have one use this as the centre point of the geometry
+                IF NEW.centroid IS NULL THEN
+                  NEW.centroid := coalesce(linkedPlacex.centroid,st_centroid(linkedPlacex.geometry));
+                END IF;
 
-              -- If we don't already have one use this as the centre point of the geometry
-              IF NEW.centroid IS NULL THEN
-                NEW.centroid := coalesce(linkedPlacex.centroid,st_centroid(linkedPlacex.geometry));
-              END IF;
+                -- merge in the name, re-init word vector
+                IF NOT linkedPlacex.name IS NULL THEN
+                  NEW.name := linkedPlacex.name || NEW.name;
+                  name_vector := make_keywords(NEW.name);
+                END IF;
 
-              -- merge in the name, re-init word vector
-              IF NOT linkedPlacex.name IS NULL THEN
-                NEW.name := linkedPlacex.name || NEW.name;
-                name_vector := make_keywords(NEW.name);
-              END IF;
+                -- merge in extra tags
+                IF NOT linkedPlacex.extratags IS NULL THEN
+                  NEW.extratags := linkedPlacex.extratags || NEW.extratags;
+                END IF;
 
-              -- merge in extra tags
-              IF NOT linkedPlacex.extratags IS NULL THEN
-                NEW.extratags := linkedPlacex.extratags || NEW.extratags;
-              END IF;
+                -- mark the linked place (excludes from search results)
+                UPDATE placex set linked_place_id = NEW.place_id where place_id = linkedPlacex.place_id;
 
-              -- mark the linked place (excludes from search results)
-              UPDATE placex set linked_place_id = NEW.place_id where place_id = linkedPlacex.place_id;
+                -- keep a note of the node id in case we need it for wikipedia in a bit
+                linked_node_id := linkedPlacex.osm_id;
+              END IF;
 
-              -- keep a note of the node id in case we need it for wikipedia in a bit
-              linked_node_id := linkedPlacex.osm_id;
-            END IF;
+            END LOOP;
 
           END LOOP;
 
-        END LOOP;
-
+        END IF;
       END IF;
 
       -- not found one yet? how about doing a name search
@@ -1697,21 +1699,24 @@ BEGIN
     IF array_upper(isin_tokens, 1) IS NOT NULL THEN
       FOR i IN 1..array_upper(isin_tokens, 1) LOOP
 --RAISE WARNING '  getNearestNamedFeature: % % % %',NEW.partition, place_centroid, search_maxrank, isin_tokens[i];
+        IF NOT ARRAY[isin_tokens[i]] <@ nameaddress_vector THEN
 
-        FOR location IN SELECT * from getNearestNamedFeature(NEW.partition, place_centroid, search_maxrank, isin_tokens[i]) LOOP
+          FOR location IN SELECT * from getNearestNamedFeature(NEW.partition, place_centroid, search_maxrank, isin_tokens[i]) LOOP
 
---RAISE WARNING '  ISIN: %',location;
+  --RAISE WARNING '  ISIN: %',location;
 
-          nameaddress_vector := array_merge(nameaddress_vector, location.keywords::integer[]);
-          INSERT INTO place_addressline VALUES (NEW.place_id, location.place_id, false, NOT address_havelevel[location.rank_address], location.distance, location.rank_address);
-          address_havelevel[location.rank_address] := true;
+            nameaddress_vector := array_merge(nameaddress_vector, location.keywords::integer[]);
+            INSERT INTO place_addressline VALUES (NEW.place_id, location.place_id, false, NOT address_havelevel[location.rank_address], location.distance, location.rank_address);
+            address_havelevel[location.rank_address] := true;
 
-          IF location.rank_address > parent_place_id_rank THEN
-            NEW.parent_place_id = location.place_id;
-            parent_place_id_rank = location.rank_address;
-          END IF;
+            IF location.rank_address > parent_place_id_rank THEN
+              NEW.parent_place_id = location.place_id;
+              parent_place_id_rank = location.rank_address;
+            END IF;
 
-        END LOOP;
+          END LOOP;
+
+        END IF;
 
       END LOOP;
     END IF;
