X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/73fdf5fae2755ba8c0170ff4b7ebce0aab5c08a4..b57dc6addfe6d91ad78642d1f6881d206b7e425a:/sql/functions.sql

diff --git a/sql/functions.sql b/sql/functions.sql
index aa2a8908..0d691411 100644
--- a/sql/functions.sql
+++ b/sql/functions.sql
@@ -5,7 +5,6 @@
 --  score integer
 --);
 
-
 CREATE OR REPLACE FUNCTION getclasstypekey(c text, t text) RETURNS TEXT
   AS $$
 DECLARE
@@ -1209,7 +1208,13 @@ BEGIN
     END IF;
     IF diameter > 0 THEN
 --      RAISE WARNING 'placex point insert: % % % % %',NEW.osm_type,NEW.osm_id,NEW.class,NEW.type,diameter;
-      update placex set indexed_status = 2 where indexed_status = 0 and rank_search > NEW.rank_search and ST_DWithin(placex.geometry, NEW.geometry, diameter) and (rank_search < 28 or name is not null);
+      IF NEW.rank_search >= 26 THEN
+        -- roads may cause reparenting for >27 rank places
+        update placex set indexed_status = 2 where indexed_status = 0 and rank_search > NEW.rank_search and ST_DWithin(placex.geometry, NEW.geometry, diameter);
+      ELSE
+        -- for all other places the search terms may change as well
+        update placex set indexed_status = 2 where indexed_status = 0 and rank_search > NEW.rank_search and ST_DWithin(placex.geometry, NEW.geometry, diameter) and (rank_search < 28 or name is not null);
+      END IF;
     END IF;
 
   END IF;
@@ -1383,6 +1388,9 @@ BEGIN
 
 --RAISE WARNING 'finding street for %', NEW;
 
+      -- We won't get a better centroid, besides these places are too small to care
+      NEW.centroid := place_centroid;
+
       NEW.parent_place_id := null;
 
       -- to do that we have to find our parent road
@@ -1701,6 +1709,16 @@ BEGIN
         END LOOP;
       END IF;
     END IF;
+
+    -- for the USA we have an additional address table.  Merge in zip codes from there too
+    IF NEW.rank_search = 26 AND NEW.calculated_country_code = 'us' THEN
+      FOR location IN SELECT distinct postcode from location_property_tiger where parent_place_id = NEW.place_id LOOP
+        address_street_word_id := get_name_id(make_standard_name(location.postcode));
+        nameaddress_vector := array_merge(nameaddress_vector, ARRAY[address_street_word_id]);
+        isin_tokens := isin_tokens || address_street_word_id;
+      END LOOP;
+    END IF;
+
 -- RAISE WARNING 'ISIN: %', isin_tokens;
 
     -- Process area matches
