]> git.openstreetmap.org Git - nominatim.git/blobdiff - sql/functions.sql
get rid of sector index, no longer used
[nominatim.git] / sql / functions.sql
index 658771b74c70f74b2d7658c50fa62d335ca6fae3..3c8f16e0831a5696d7974f48889183bc79b9fc10 100644 (file)
@@ -1403,6 +1403,26 @@ BEGIN
         select * from search_name where place_id = NEW.parent_place_id INTO location;
         NEW.calculated_country_code := location.country_code;
 
+        -- Merge the postcode into the parent's address if necessary XXXX
+        IF NEW.postcode IS NOT NULL THEN
+          isin_tokens := '{}'::int[];
+          address_street_word_id := getorcreate_word_id(make_standard_name(NEW.postcode));
+          IF address_street_word_id is not null
+             and not ARRAY[address_street_word_id] <@ location.nameaddress_vector THEN
+             isin_tokens := isin_tokens || address_street_word_id;
+          END IF;
+          address_street_word_id := getorcreate_name_id(make_standard_name(NEW.postcode));
+          IF address_street_word_id is not null
+             and not ARRAY[address_street_word_id] <@ location.nameaddress_vector THEN
+             isin_tokens := isin_tokens || address_street_word_id;
+          END IF;
+          IF isin_tokens != '{}'::int[] THEN
+             UPDATE search_name
+                SET nameaddress_vector = search_name.nameaddress_vector || isin_tokens
+              WHERE place_id = NEW.parent_place_id;
+          END IF;
+        END IF;
+
 --RAISE WARNING '%', NEW.name;
         -- If there is no name it isn't searchable, don't bother to create a search record
         IF NEW.name is NULL THEN
@@ -2241,9 +2261,10 @@ BEGIN
   END IF;
 
   IF for_place_id IS NULL THEN
-    for_place_id := in_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;
+    select coalesce(linked_place_id, place_id),  calculated_country_code,
+           housenumber, rank_search, postcode, null
+      from placex where place_id = in_place_id
+      INTO for_place_id, searchcountrycode, searchhousenumber, searchrankaddress, searchpostcode, searchhousename;
   END IF;
 
 --RAISE WARNING '% % % %',searchcountrycode, searchhousenumber, searchrankaddress, searchpostcode;