X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/4a3dc3187cc5d220f2728a741d4b6789917655c0..fb7d65b8c377fd5c9a74fef1ef800c9bc8e2abc3:/sql/functions.sql diff --git a/sql/functions.sql b/sql/functions.sql index e404da7c..bd64697a 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -689,7 +689,7 @@ BEGIN -- one with the smallest id because the original node was created first. -- Ignore all nodes marked for deletion. (Might happen when the type changes.) select * from placex where osm_type = 'N' and osm_id = waynodes[nodeidpos]::BIGINT - and indexed_status < 100 + and indexed_status < 100 and housenumber is not NULL order by (type = 'address'),place_id limit 1 INTO nextnode; IF nextnode.place_id IS NOT NULL THEN @@ -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; @@ -2241,9 +2260,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;