]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'lonvia/address-order'
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 20 Jul 2012 22:53:53 +0000 (00:53 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 20 Jul 2012 22:53:53 +0000 (00:53 +0200)
sql/functions.sql
sql/partitions.src.sql

index 1d653bb205d8e7f17f00f2be8f79eb52726e64a7..25769785b8bfd4fe4a1570e81ff92b369b782125 100644 (file)
@@ -1220,6 +1220,8 @@ DECLARE
 
   location_rank_search INTEGER;
   location_distance FLOAT;
+  location_parent GEOMETRY;
+  location_isaddress BOOLEAN;
 
   tagpairid INTEGER;
 
@@ -1634,24 +1636,37 @@ BEGIN
 -- RAISE WARNING 'ISIN: %', isin_tokens;
 
     -- Process area matches
-    location_rank_search := 100;
+    location_rank_search := 0;
     location_distance := 0;
--- RAISE WARNING '  getNearFeatures(%,''%'',%,''%'')',NEW.partition, place_centroid, search_maxrank, isin_tokens;
+    location_parent := NULL;
+    -- RAISE WARNING '  getNearFeatures(%,''%'',%,''%'')',NEW.partition, place_centroid, search_maxrank, isin_tokens;
     FOR location IN SELECT * from getNearFeatures(NEW.partition, place_centroid, search_maxrank, isin_tokens) LOOP
 
 --RAISE WARNING '  AREA: %',location;
 
-      IF location.rank_search < location_rank_search THEN
-        location_rank_search := location.rank_search;
+      IF location.rank_address != location_rank_search THEN
+        location_rank_search := location.rank_address;
         location_distance := location.distance * 1.5;
       END IF;
 
       IF location.distance < location_distance OR NOT location.isguess THEN
 
+        location_isaddress := NOT address_havelevel[location.rank_address];
+        IF location_isaddress AND location.isguess AND location_parent IS NOT NULL THEN
+            location_isaddress := ST_Contains(location_parent,location.centroid);
+        END IF;
+
+        -- RAISE WARNING '% isaddress: %', location.place_id, location_isaddress;
         -- Add it to the list of search terms
         nameaddress_vector := array_merge(nameaddress_vector, location.keywords::integer[]);
-        INSERT INTO place_addressline VALUES (NEW.place_id, location.place_id, true, NOT address_havelevel[location.rank_address], location.distance, location.rank_address); 
-        address_havelevel[location.rank_address] := true;
+        INSERT INTO place_addressline VALUES (NEW.place_id, location.place_id, true, location_isaddress, location.distance, location.rank_address);
+
+        IF location_isaddress THEN
+            address_havelevel[location.rank_address] := true;
+            IF NOT location.isguess THEN
+                SELECT geometry FROM placex WHERE place_id = location.place_id INTO location_parent;
+            END IF;
+        END IF;
 
 --RAISE WARNING '  Terms: (%) %',location, nameaddress_vector;
 
@@ -1690,13 +1705,13 @@ BEGIN
     -- for long ways we should add search terms for the entire length
     IF st_length(NEW.geometry) > 0.05 THEN
 
-      location_rank_search := 100;
+      location_rank_search := 0;
       location_distance := 0;
 
       FOR location IN SELECT * from getNearFeatures(NEW.partition, NEW.geometry, search_maxrank, isin_tokens) LOOP
 
-        IF location.rank_search < location_rank_search THEN
-          location_rank_search := location.rank_search;
+        IF location.rank_address != location_rank_search THEN
+          location_rank_search := location.rank_address;
           location_distance := location.distance * 1.5;
         END IF;
 
index df4b3b169338361aee77092a6efaadc9ec5e7d3b..324f35bbd22ce8777a735d9d51e93e0a8571d560 100644 (file)
@@ -13,6 +13,17 @@ create type nearfeature as (
   isguess boolean
 );
 
+drop type nearfeaturecentr cascade;
+create type nearfeaturecentr as (
+  place_id BIGINT,
+  keywords int[],
+  rank_address integer,
+  rank_search integer,
+  distance float,
+  isguess boolean,
+  centroid GEOMETRY
+);
+
 CREATE TABLE location_area_country () INHERITS (location_area_large);
 CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry);
 
@@ -46,21 +57,21 @@ CREATE INDEX idx_location_road_-partition-_place_id ON location_road_-partition-
 
 -- end
 
-create or replace function getNearFeatures(in_partition INTEGER, point GEOMETRY, maxrank INTEGER, isin_tokens INT[]) RETURNS setof nearfeature AS $$
+create or replace function getNearFeatures(in_partition INTEGER, point GEOMETRY, maxrank INTEGER, isin_tokens INT[]) RETURNS setof nearfeaturecentr AS $$
 DECLARE
-  r nearfeature%rowtype;
+  r nearfeaturecentr%rowtype;
 BEGIN
 
 -- start
   IF in_partition = -partition- THEN
     FOR r IN 
-      SELECT place_id, keywords, rank_address, rank_search, min(ST_Distance(point, centroid)) as distance, isguess FROM (
+      SELECT place_id, keywords, rank_address, rank_search, min(ST_Distance(point, centroid)) as distance, isguess, centroid FROM (
         SELECT * FROM location_area_large_-partition- WHERE ST_Contains(geometry, point) and rank_search < maxrank
         UNION ALL
         SELECT * FROM location_area_country WHERE ST_Contains(geometry, point) and rank_search < maxrank
       ) as location_area
       GROUP BY place_id, keywords, rank_address, rank_search, isguess, centroid
-      ORDER BY rank_address desc, isin_tokens && keywords desc, isguess asc, 
+      ORDER BY rank_address, isin_tokens && keywords desc, isguess asc,
         ST_Distance(point, centroid) * 
           CASE 
                WHEN rank_address = 16 AND rank_search = 15 THEN 0.2 -- capital city