X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/2f8a29ba39e4ca995334f2702985afa761bfffbd..f9a488cd5a420ce63010c2b3293d0e91750e4994:/sql/functions.sql?ds=sidebyside

diff --git a/sql/functions.sql b/sql/functions.sql
index 3c8f16e0..5b068dfe 100644
--- a/sql/functions.sql
+++ b/sql/functions.sql
@@ -1,3 +1,15 @@
+-- Splits the line at the given point and returns the two parts
+-- in a multilinestring.
+CREATE OR REPLACE FUNCTION split_line_on_node(line GEOMETRY, point GEOMETRY)
+RETURNS GEOMETRY
+  AS $$
+BEGIN
+  RETURN ST_Split(ST_Snap(line, point, 0.0005), point);
+END;
+$$
+LANGUAGE plpgsql;
+
+
 CREATE OR REPLACE FUNCTION geometry_sector(partition INTEGER, place geometry) RETURNS INTEGER
   AS $$
 DECLARE
@@ -1161,7 +1173,8 @@ BEGIN
     DELETE FROM place_addressline WHERE place_id = NEW.place_id;
     result := deleteRoad(NEW.partition, NEW.place_id);
     result := deleteLocationArea(NEW.partition, NEW.place_id, NEW.rank_search);
-    UPDATE placex set linked_place_id = null where linked_place_id = NEW.place_id;
+    UPDATE placex set linked_place_id = null, indexed_status = 2
+           where linked_place_id = NEW.place_id;
 
     IF NEW.linked_place_id is not null THEN
       RETURN NEW;
@@ -2118,28 +2131,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;
@@ -2184,7 +2196,8 @@ END;
 $$
 LANGUAGE plpgsql;
 
-CREATE OR REPLACE FUNCTION get_address_by_language(for_place_id BIGINT, languagepref TEXT[]) RETURNS TEXT
+--housenumber only needed for tiger data
+CREATE OR REPLACE FUNCTION get_address_by_language(for_place_id BIGINT, housenumber INTEGER, languagepref TEXT[]) RETURNS TEXT
   AS $$
 DECLARE
   result TEXT[];
@@ -2196,7 +2209,7 @@ BEGIN
   result := '{}';
   prevresult := '';
 
-  FOR location IN select * from get_addressdata(for_place_id) where isaddress order by rank_address desc LOOP
+  FOR location IN select * from get_addressdata(for_place_id, housenumber) where isaddress order by rank_address desc LOOP
     currresult := trim(get_name_by_language(location.name, languagepref));
     IF currresult != prevresult AND currresult IS NOT NULL AND result[(100 - location.rank_address)] IS NULL THEN
       result[(100 - location.rank_address)] := trim(get_name_by_language(location.name, languagepref));
@@ -2224,10 +2237,10 @@ create type addressline as (
   distance FLOAT
 );
 
-CREATE OR REPLACE FUNCTION get_addressdata(in_place_id BIGINT) RETURNS setof addressline 
+CREATE OR REPLACE FUNCTION get_addressdata(in_place_id BIGINT, in_housenumber INTEGER) RETURNS setof addressline 
   AS $$
 DECLARE
-  for_place_id BIGINT;
+  for_place_id BIGINT;--parent_place_id
   result TEXT[];
   search TEXT[];
   found INTEGER;
@@ -2243,11 +2256,14 @@ DECLARE
   countryname HSTORE;
   hadcountry BOOLEAN;
 BEGIN
-
-  select parent_place_id,'us', housenumber, 30, postcode, null, 'place', 'house' from location_property_tiger 
-    WHERE place_id = in_place_id 
-    INTO for_place_id,searchcountrycode, searchhousenumber, searchrankaddress, searchpostcode, searchhousename, searchclass, searchtype;
-
+    --first query tiger data
+  select parent_place_id,'us', 30, postcode, null, 'place', 'house' from location_property_tiger 
+    WHERE place_id = in_place_id AND in_housenumber>=startnumber AND in_housenumber <= endnumber
+    INTO for_place_id,searchcountrycode, searchrankaddress, searchpostcode, searchhousename, searchclass, searchtype;
+  IF for_place_id IS NOT NULL THEN
+    searchhousenumber = in_housenumber::text;
+  END IF;
+  
   IF for_place_id IS NULL THEN
     select parent_place_id,'us', housenumber, 30, postcode, null, 'place', 'house' from location_property_aux
       WHERE place_id = in_place_id 
