X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/8ff0aabaf3e82e6bc99894e22d312ccc4b76529f..03873df21182ee9a87f168f6108d93187db0c83e:/sql/functions.sql?ds=sidebyside

diff --git a/sql/functions.sql b/sql/functions.sql
index 03ea4011..2c4429bb 100644
--- a/sql/functions.sql
+++ b/sql/functions.sql
@@ -769,6 +769,13 @@ BEGIN
           -- null record of right type
           select * from placex where osm_type = 'N' and osm_id = waynodes[nodeidpos]::INTEGER and type = 'house' limit 1 INTO nextnode;
           select ST_SetSRID(ST_Point(lon::float/10000000,lat::float/10000000),4326) from planet_osm_nodes where id = waynodes[nodeidpos] INTO nextnode.geometry;
+          IF nextnode.geometry IS NULL THEN
+            -- we don't have any information about this point, most likely
+            -- because an excerpt was updated and the node never imported
+            -- because the interpolation is outside the region of the excerpt.
+            -- Give up.
+            RETURN newpoints;
+          END IF;
         ELSE
           select * from placex where place_id = search_place_id INTO nextnode;
         END IF;
@@ -1213,6 +1220,8 @@ DECLARE
 
   location_rank_search INTEGER;
   location_distance FLOAT;
+  location_parent GEOMETRY;
+  location_isaddress BOOLEAN;
 
   tagpairid INTEGER;
 
@@ -1627,24 +1636,37 @@ BEGIN
 -- RAISE WARNING 'ISIN: %', isin_tokens;
 
     -- Process area matches
-    location_rank_search := 100;
+    location_rank_search := 0;
     location_distance := 0;
--- RAISE WARNING '  getNearFeatures(%,''%'',%,''%'')',NEW.partition, place_centroid, search_maxrank, isin_tokens;
+    location_parent := NULL;
+    -- RAISE WARNING '  getNearFeatures(%,''%'',%,''%'')',NEW.partition, place_centroid, search_maxrank, isin_tokens;
     FOR location IN SELECT * from getNearFeatures(NEW.partition, place_centroid, search_maxrank, isin_tokens) LOOP
 
 --RAISE WARNING '  AREA: %',location;
 
-      IF location.rank_search < location_rank_search THEN
-        location_rank_search := location.rank_search;
+      IF location.rank_address != location_rank_search THEN
+        location_rank_search := location.rank_address;
         location_distance := location.distance * 1.5;
       END IF;
 
       IF location.distance < location_distance OR NOT location.isguess THEN
 
+        location_isaddress := NOT address_havelevel[location.rank_address];
+        IF location_isaddress AND location.isguess AND location_parent IS NOT NULL THEN
+            location_isaddress := ST_Contains(location_parent,location.centroid);
+        END IF;
+
+        -- RAISE WARNING '% isaddress: %', location.place_id, location_isaddress;
         -- Add it to the list of search terms
         nameaddress_vector := array_merge(nameaddress_vector, location.keywords::integer[]);
-        INSERT INTO place_addressline VALUES (NEW.place_id, location.place_id, true, NOT address_havelevel[location.rank_address], location.distance, location.rank_address); 
-        address_havelevel[location.rank_address] := true;
+        INSERT INTO place_addressline VALUES (NEW.place_id, location.place_id, true, location_isaddress, location.distance, location.rank_address);
+
+        IF location_isaddress THEN
+            address_havelevel[location.rank_address] := true;
+            IF NOT location.isguess THEN
+                SELECT geometry FROM placex WHERE place_id = location.place_id INTO location_parent;
+            END IF;
+        END IF;
 
 --RAISE WARNING '  Terms: (%) %',location, nameaddress_vector;
 
@@ -1683,13 +1705,13 @@ BEGIN
     -- for long ways we should add search terms for the entire length
     IF st_length(NEW.geometry) > 0.05 THEN
 
-      location_rank_search := 100;
+      location_rank_search := 0;
       location_distance := 0;
 
       FOR location IN SELECT * from getNearFeatures(NEW.partition, NEW.geometry, search_maxrank, isin_tokens) LOOP
 
-        IF location.rank_search < location_rank_search THEN
-          location_rank_search := location.rank_search;
+        IF location.rank_address != location_rank_search THEN
+          location_rank_search := location.rank_address;
           location_distance := location.distance * 1.5;
         END IF;
 
@@ -2213,14 +2235,14 @@ BEGIN
   END IF;
 
   IF for_place_id IS NULL THEN
-    select parent_place_id, calculated_country_code, housenumber, rank_address, postcode, name, class, type from placex 
+    select parent_place_id, calculated_country_code, housenumber, rank_search, postcode, name, class, type from placex 
       WHERE place_id = in_place_id and rank_address = 30 
       INTO for_place_id, searchcountrycode, searchhousenumber, searchrankaddress, searchpostcode, searchhousename, searchclass, searchtype;
   END IF;
 
   IF for_place_id IS NULL THEN
     for_place_id := in_place_id;
-    select calculated_country_code, housenumber, rank_address, postcode, null from placex where place_id = for_place_id 
+    select calculated_country_code, housenumber, rank_search, postcode, null from placex where place_id = for_place_id 
       INTO searchcountrycode, searchhousenumber, searchrankaddress, searchpostcode, searchhousename;
   END IF;
 
