]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 4 Mar 2020 07:18:58 +0000 (08:18 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 4 Mar 2020 07:18:58 +0000 (08:18 +0100)
lib/Geocode.php
lib/PlaceLookup.php
lib/SearchDescription.php
sql/functions/address_lookup.sql
sql/functions/placex_triggers.sql
sql/partition-functions.src.sql
test/bdd/db/import/linking.feature
test/bdd/db/update/linked_places.feature
test/bdd/steps/queries.py

index c1d0c46f80310fb76c9b2ca4c14a1111ee20f930..0e5d4a53883924b110a054c8afe143759ff213bd 100644 (file)
@@ -808,9 +808,7 @@ class Geocode
                         $sSQL .= 'WHERE place_id in ('.$sPlaceIds.') ';
                         $sSQL .= '  AND (';
                         $sSQL .= "         placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
-                        if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) {
-                            $sSQL .= "     OR (extratags->'place') = 'city'";
-                        }
+                        $sSQL .= "         OR placex.rank_search between $this->iMinAddressRank and $this->iMaxAddressRank ";
                         if ($this->aAddressRankList) {
                             $sSQL .= '     OR placex.rank_address in ('.join(',', $this->aAddressRankList).')';
                         }
index fce4970158a9395a6c22301fcae70d6ece185398..9f4f143ea23dd2c3f4f7bd488d369671c5ac9bf7 100644 (file)
@@ -215,7 +215,7 @@ class PlaceLookup
                 'ST_Collect(centroid)',
                 'min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END)'
             );
-            $sSQL .= "    (extratags->'place') AS extra_place ";
+            $sSQL .= "    COALESCE(extratags->'place', extratags->'linked_place') AS extra_place ";
             $sSQL .= ' FROM placex';
             $sSQL .= " WHERE place_id in ($sPlaceIDs) ";
             $sSQL .= '   AND (';
@@ -248,7 +248,7 @@ class PlaceLookup
             $sSQL .= '     ref, ';
             if ($this->bExtraTags) $sSQL .= 'extratags, ';
             if ($this->bNameDetails) $sSQL .= 'name, ';
-            $sSQL .= "     extratags->'place' ";
+            $sSQL .= '     extra_place ';
 
             $aSubSelects[] = $sSQL;
         }
index 4fafbec2b21c9899fb1e35c51ac8241647876b58..bb478b29b88af4fbcef3a174d8e5405cedd616ea 100644 (file)
@@ -660,10 +660,7 @@ class SearchDescription
             $aTerms[] = 'address_rank between 16 and 27';
         } elseif (!$this->sClass || $this->iOperator == Operator::NAME) {
             if ($iMinAddressRank > 0) {
-                $aTerms[] = 'address_rank >= '.$iMinAddressRank;
-            }
-            if ($iMaxAddressRank < 30) {
-                $aTerms[] = 'address_rank <= '.$iMaxAddressRank;
+                $aTerms[] = "((address_rank between $iMinAddressRank and $iMaxAddressRank) or (search_rank between $iMinAddressRank and $iMaxAddressRank))";
             }
         }
 
index 585c22c8d918ee8e709c029fcf923a199022a566..dd096728124d1f4e5d13dae849e893d1ec091eda 100644 (file)
@@ -202,8 +202,9 @@ BEGIN
 
   FOR location IN
     SELECT placex.place_id, osm_type, osm_id, name,
-           CASE WHEN extratags ? 'place' THEN 'place' ELSE class END as class,
-           CASE WHEN extratags ? 'place' THEN extratags->'place' ELSE type END as type,
+           CASE WHEN extratags ? 'place' or extratags ? 'linked_place'
+                THEN 'place' ELSE class END as class,
+           coalesce(extratags->'place', extratags->'linked_place', type) as type,
            admin_level, fromarea, isaddress and linked_place_id is NULL as isaddress,
            CASE WHEN rank_address = 11 THEN 5 ELSE rank_address END as rank_address,
            distance, country_code, postcode
index ffc83fa3aa03197e9a3ca22ac32cfbcbf219a12d..e16b778371151ef8c26aa274e6bb35d1ef616b21 100644 (file)
@@ -204,9 +204,26 @@ BEGIN
     END IF;
   END IF;
 
+  -- If extratags has a place tag, look for linked nodes by their place type.
+  -- Area and node still have to have the same name.
+  IF bnd.extratags ? 'place' and bnd_name is not null THEN
+    FOR linked_placex IN
+      SELECT * FROM placex
+      WHERE make_standard_name(name->'name') = bnd_name
+        AND placex.class = 'place' AND placex.type = bnd.extratags->'place'
+        AND placex.osm_type = 'N'
+        AND placex.rank_search < 26 -- needed to select the right index
+        AND _st_covers(bnd.geometry, placex.geometry)
+    LOOP
+      --DEBUG: RAISE WARNING 'Found type-matching place node %', linked_placex.osm_id;
+      RETURN linked_placex;
+    END LOOP;
+  END IF;
+
   -- Search for relation members with role admin_center.
   IF bnd.osm_type = 'R' and bnd_name is not null
-     and relation_members is not null THEN
+     and relation_members is not null
+  THEN
     FOR rel_member IN
       SELECT get_rel_node_members(relation_members,
                                 ARRAY['admin_center','admin_centre']) as member
@@ -231,7 +248,7 @@ BEGIN
   END IF;
 
   -- Name searches can be done for ways as well as relations
-  IF bnd.osm_type in ('W','R') and bnd_name is not null THEN
+  IF bnd_name is not null THEN
     --DEBUG: RAISE WARNING 'Looking for nodes with matching names';
     FOR linked_placex IN
       SELECT placex.* from placex
@@ -241,7 +258,7 @@ BEGIN
         AND placex.rank_search < 26 -- needed to select the right index
         AND _st_covers(bnd.geometry, placex.geometry)
     LOOP
-      --DEBUG: RAISE WARNING 'Found matching place node %', linkedPlacex.osm_id;
+      --DEBUG: RAISE WARNING 'Found matching place node %', linked_placex.osm_id;
       RETURN linked_placex;
     END LOOP;
   END IF;
@@ -818,19 +835,24 @@ BEGIN
   --DEBUG: RAISE WARNING 'Using full index mode for % %', NEW.osm_type, NEW.osm_id;
   SELECT * INTO location FROM find_linked_place(NEW);
   IF location.place_id is not null THEN
-      --DEBUG: RAISE WARNING 'Linked %', location;
+    --DEBUG: RAISE WARNING 'Linked %', location;
 
     -- Use this as the centre point of the geometry
     NEW.centroid := coalesce(location.centroid,
                              ST_Centroid(location.geometry));
 
+    -- Use the address rank of the linked place, if it has one
+    IF location.rank_address between 5 and 25 THEN
+      NEW.rank_address := location.rank_address;
+    END IF;
+
     -- merge in the label name
     IF NOT location.name IS NULL THEN
       NEW.name := location.name || NEW.name;
     END IF;
 
     -- merge in extra tags
-    NEW.extratags := hstore(location.class, location.type)
+    NEW.extratags := hstore('linked_' || location.class, location.type)
                      || coalesce(location.extratags, ''::hstore)
                      || coalesce(NEW.extratags, ''::hstore);
 
index 8f78032ed18d4e05e5bc5d4f3ea9dc50563db898..34b4d390750798cb506f5fe11507535c0c20278e 100644 (file)
@@ -20,7 +20,8 @@ BEGIN
     FOR r IN 
       SELECT place_id, keywords, rank_address, rank_search, min(ST_Distance(feature, centroid)) as distance, isguess, postcode, centroid
       FROM location_area_large_-partition-
-      WHERE ST_Intersects(geometry, feature) and rank_search < maxrank
+      WHERE ST_Intersects(geometry, feature)
+        AND rank_search < maxrank AND rank_address < maxrank
       GROUP BY place_id, keywords, rank_address, rank_search, isguess, postcode, centroid
       ORDER BY rank_address, isin_tokens && keywords desc, isguess asc,
         ST_Distance(feature, centroid) *
index ceb455865a776875a56b1c3e4fcbb315d17d4378..1bca7dfc7d0dcf60d09a8a39aba6affbfbad5dde 100644 (file)
@@ -127,3 +127,74 @@ Feature: Linking of places
          | N3:natural | -               |
          | N3:place   | R1              |
 
+    Scenario: Nodes with 'role' label are always linked
+        Given the places
+         | osm  | class    | type           | admin | name  | geometry |
+         | R13  | boundary | administrative | 6     | Garbo | poly-area:0.1 |
+         | N2   | place    | hamlet         | 15    | Vario | 0.006 0.00001 |
+        And the relations
+         | id | members       | tags+type |
+         | 13 | N2:label      | boundary |
+        When importing
+        Then placex contains
+         | object  | linked_place_id |
+         | N2      | R13 |
+        And placex contains
+         | object | centroid      | name+name | extratags+linked_place |
+         | R13    | 0.006 0.00001 | Garbo     | hamlet |
+
+    Scenario: Boundaries with place tags are linked against places with same type
+        Given the places
+         | osm  | class    | type           | admin | name   | extra+place | geometry |
+         | R13  | boundary | administrative | 4     | Berlin | city        |poly-area:0.1 |
+        And the places
+         | osm  | class    | type           | name   | geometry |
+         | N2   | place    | city           | Berlin | 0.006 0.00001 |
+        When importing
+        Then placex contains
+         | object  | linked_place_id |
+         | N2      | R13             |
+        And placex contains
+         | object | rank_address |
+         | R13    | 16 |
+        When searching for ""
+         | city |
+         | Berlin |
+        Then results contain
+          | ID | osm_type | osm_id |
+          |  0 | R | 13 |
+        When searching for ""
+         | state |
+         | Berlin |
+        Then results contain
+          | ID | osm_type | osm_id |
+          |  0 | R | 13 |
+
+
+    Scenario: Boundaries without place tags only link against same admin level
+        Given the places
+         | osm  | class    | type           | admin | name   | geometry |
+         | R13  | boundary | administrative | 4     | Berlin |poly-area:0.1 |
+        And the places
+         | osm  | class    | type           | name   | geometry |
+         | N2   | place    | city           | Berlin | 0.006 0.00001 |
+        When importing
+        Then placex contains
+         | object  | linked_place_id |
+         | N2      | -               |
+        And placex contains
+         | object | rank_address |
+         | R13    | 8 |
+        When searching for ""
+         | state |
+         | Berlin |
+        Then results contain
+          | ID | osm_type | osm_id |
+          |  0 | R | 13 |
+        When searching for ""
+         | city |
+         | Berlin |
+        Then results contain
+          | ID | osm_type | osm_id |
+          |  0 | N | 2 |
+
index 6c31bd8920b45710dbab76099738e02b3651f13c..647d5eafa1ea37db93585603af4be09a65fd38ea 100644 (file)
@@ -125,11 +125,11 @@ Feature: Updates of linked places
         When importing
         Then placex contains
          | object | extratags |
-         | R1     | 'wikidata' : '34', 'place' : 'city' |
+         | R1     | 'wikidata' : '34', 'linked_place' : 'city' |
         When updating places
          | osm | class    | type        | name    | extra+oneway | admin | geometry |
          | N3  | place    | city        | newname | yes          | 30    | 0.00001 0 |
         Then placex contains
          | object | extratags |
-         | R1     | 'wikidata' : '34', 'oneway' : 'yes', 'place' : 'city' |
+         | R1     | 'wikidata' : '34', 'oneway' : 'yes', 'linked_place' : 'city' |
 
index 3f0cffffb74cee1bc66414745a712bc8d36c1665..4e6ec1ff5ab02c6d3556cd17877ca48376c370d6 100644 (file)
@@ -297,7 +297,8 @@ def query_cmd(context, query, dups):
     """
     cmd = ['/usr/bin/env', 'php']
     cmd.append(os.path.join(context.nominatim.build_dir, 'utils', 'query.php'))
-    cmd.extend(['--search', query])
+    if query:
+        cmd.extend(['--search', query])
     # add more parameters in table form
     if context.table:
         for h in context.table.headings: