X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/6727c36298fe6d5e779498d6c7eb88ce7ffdc2a2..c2112fc6ff425db3e3b53431ef820299c27577a2:/sql/functions.sql

diff --git a/sql/functions.sql b/sql/functions.sql
index 878c69c9..bd64697a 100644
--- a/sql/functions.sql
+++ b/sql/functions.sql
@@ -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
@@ -2098,28 +2118,27 @@ BEGIN
 END; 
 $$ LANGUAGE plpgsql;
 
+
 CREATE OR REPLACE FUNCTION get_name_by_language(name hstore, languagepref TEXT[]) RETURNS TEXT
   AS $$
 DECLARE
-  search TEXT[];
-  found BOOLEAN;
+  result TEXT;
 BEGIN
-
   IF name is null THEN
     RETURN null;
   END IF;
 
-  search := languagepref;
-
-  FOR j IN 1..array_upper(search, 1) LOOP
-    IF name ? search[j] AND trim(name->search[j]) != '' THEN
-      return trim(name->search[j]);
+  FOR j IN 1..array_upper(languagepref,1) LOOP
+    IF name ? languagepref[j] THEN
+      result := trim(name->languagepref[j]);
+      IF result != '' THEN
+        return result;
+      END IF;
     END IF;
   END LOOP;
 
   -- anything will do as a fallback - just take the first name type thing there is
-  search := avals(name);
-  RETURN search[1];
+  RETURN trim((avals(name))[1]);
 END;
 $$
 LANGUAGE plpgsql IMMUTABLE;
@@ -2245,7 +2264,6 @@ BEGIN
            housenumber, rank_search, postcode, null
       from placex where place_id = in_place_id
       INTO for_place_id, searchcountrycode, searchhousenumber, searchrankaddress, searchpostcode, searchhousename;
-      RAISE WARNING '% fffff %', in_place_id, for_place_id;
   END IF;
 
 --RAISE WARNING '% % % %',searchcountrycode, searchhousenumber, searchrankaddress, searchpostcode;
