]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Mon, 2 Oct 2017 21:10:21 +0000 (23:10 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 2 Oct 2017 21:10:21 +0000 (23:10 +0200)
docs/Import-and-Update.md
lib/Geocode.php
lib/NearPoint.php
test/bdd/api/search/postcode.feature
test/bdd/api/search/queries.feature
test/bdd/api/search/simple.feature
test/php/Nominatim/NearPointTest.php

index 3eda0a02a7821af56ad05723ef5c0a8be4377100..fe95e8654ac1acbcb83408b57295a2cea043953d 100644 (file)
@@ -128,7 +128,8 @@ For a list of other methods see the output of `./utils/update.php --help`.
 Installing the newest version of Pyosmium
 -----------------------------------------
 
-It is recommended to install Pyosmium via pip:
+It is recommended to install Pyosmium via pip. Run (as the same user who
+will later run the updates):
 
     pip install --user osmium
 
index cff70efc4832794ee0229fc9ff356516aa8e1888..3c53777735039137771024752caa0d7454c43481 100644 (file)
@@ -313,12 +313,7 @@ class Geocode
                 if (count($aViewbox) != 4) {
                     userError("Bad parmater 'viewbox'. Expected 4 coordinates.");
                 }
-                $this->setViewBox(array(
-                                   $aViewbox[0],
-                                   $aViewbox[3],
-                                   $aViewbox[2],
-                                   $aViewbox[1]
-                                  ));
+                $this->setViewBox($aViewbox);
             } else {
                 $aRoute = $oParams->getStringList('route');
                 $fRouteWidth = $oParams->getFloat('routewidth');
@@ -915,6 +910,19 @@ class Geocode
 
             //if (CONST_Debug) _debugDumpGroupedSearches($aGroupedSearches, $aValidTokens);
         }
+
+        // Revisit searches, giving penalty to unlikely combinations
+        $aGroupedSearches = array();
+        foreach ($aSearches as $aSearch) {
+            if (!$aSearch['aName']) {
+                if ($aSearch['sHouseNumber']) {
+                    continue;
+                }
+            }
+            $aGroupedSearches[$aSearch['iSearchRank']][] = $aSearch;
+        }
+        ksort($aGroupedSearches);
+
         return $aGroupedSearches;
     }
 
@@ -1116,14 +1124,10 @@ class Geocode
                 if (CONST_Debug) var_Dump($sSQL);
 
                 $aValidTokens = array();
-                if (sizeof($aTokens)) {
-                    $aDatabaseWords = chksql(
-                        $this->oDB->getAll($sSQL),
-                        "Could not get word tokens."
-                    );
-                } else {
-                    $aDatabaseWords = array();
-                }
+                $aDatabaseWords = chksql(
+                    $this->oDB->getAll($sSQL),
+                    "Could not get word tokens."
+                );
                 $aPossibleMainWordIDs = array();
                 $aWordFrequencyScores = array();
                 foreach ($aDatabaseWords as $aToken) {
@@ -1569,7 +1573,8 @@ class Geocode
                             }
 
                             // Fallback to the road (if no housenumber was found)
-                            if (!sizeof($aPlaceIDs) && preg_match('/[0-9]+/', $aSearch['sHouseNumber'])) {
+                            if (!sizeof($aPlaceIDs) && preg_match('/[0-9]+/', $aSearch['sHouseNumber'])
+                                && ($aSearch['aAddress'] || $aSearch['sCountryCode'])) {
                                 $aPlaceIDs = $aRoadPlaceIDs;
                                 //set to -1, if no housenumbers were found
                                 $searchedHousenumber = -1;
@@ -1745,20 +1750,19 @@ class Geocode
                     if ($this->aAddressRankList) {
                         $sSQL .= "     OR placex.rank_address in (".join(',', $this->aAddressRankList).")";
                     }
-                    if (CONST_Use_US_Tiger_Data) {
-                        $sSQL .= "  ) ";
+                    $sSQL .= "  ) ";
+                    if (CONST_Use_US_Tiger_Data && $this->iMaxAddressRank == 30) {
                         $sSQL .= "UNION ";
                         $sSQL .= "  SELECT place_id ";
                         $sSQL .= "  FROM location_property_tiger ";
                         $sSQL .= "  WHERE place_id in (".join(',', array_keys($aResultPlaceIDs)).") ";
-                        $sSQL .= "    AND (30 between $this->iMinAddressRank and $this->iMaxAddressRank ";
-                        if ($this->aAddressRankList) $sSQL .= " OR 30 in (".join(',', $this->aAddressRankList).")";
                     }
-                    $sSQL .= ") UNION ";
-                    $sSQL .= "  SELECT place_id ";
-                    $sSQL .= "  FROM location_property_osmline ";
-                    $sSQL .= "  WHERE place_id in (".join(',', array_keys($aResultPlaceIDs)).")";
-                    $sSQL .= "    AND startnumber is not NULL AND (30 between $this->iMinAddressRank and $this->iMaxAddressRank)";
+                    if ($this->iMaxAddressRank == 30) {
+                        $sSQL .= "UNION ";
+                        $sSQL .= "  SELECT place_id ";
+                        $sSQL .= "  FROM location_property_osmline ";
+                        $sSQL .= "  WHERE place_id in (".join(',', array_keys($aResultPlaceIDs)).")";
+                    }
                     if (CONST_Debug) var_dump($sSQL);
                     $aFilteredPlaceIDs = chksql($this->oDB->getCol($sSQL));
                     $tempIDs = array();
index 4f0531d91510fbe4c2146c8a17259287c29eade6..30845b76e12fa19801198b0c5e2a358ce615b012 100644 (file)
@@ -81,8 +81,8 @@ class NearPoint
         $fQueryLat = null;
         $fQueryLon = null;
 
-        if (preg_match('/\\b([NS])[ ]+([0-9]+[0-9.]*)[° ]+([0-9.]+)?[′\']*[, ]+([EW])[ ]+([0-9]+)[° ]+([0-9]+[0-9.]*)[′\']*?\\b/', $sQuery, $aData)) {
-            /*              1         2                   3                  4         5            6
+        if (preg_match('/\\s*([NS])[ ]+([0-9]+[0-9.]*)[° ]+([0-9.]+)?[′\']*[, ]+([EW])[ ]+([0-9]+)[° ]+([0-9]+[0-9.]*)[′\']*\\s*/', $sQuery, $aData)) {
+            /*               1         2                   3                    4         5            6
              * degrees decimal minutes
              * N 40 26.767, W 79 58.933
              * N 40°26.767′, W 79°58.933′
@@ -90,8 +90,8 @@ class NearPoint
             $sFound    = $aData[0];
             $fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2] + $aData[3]/60);
             $fQueryLon = ($aData[4]=='E'?1:-1) * ($aData[5] + $aData[6]/60);
-        } elseif (preg_match('/\\b([0-9]+)[° ]+([0-9]+[0-9.]*)?[′\']*[ ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+[0-9.]*)?[′\' ]+([EW])\\b/', $sQuery, $aData)) {
-            /*                    1             2                      3          4            5                    6
+        } elseif (preg_match('/\\s*([0-9]+)[° ]+([0-9]+[0-9.]*)?[′\']*[ ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+[0-9.]*)?[′\' ]+([EW])\\s*/', $sQuery, $aData)) {
+            /*                     1            2                         3          4            5                      6
              * degrees decimal minutes
              * 40 26.767 N, 79 58.933 W
              * 40° 26.767′ N 79° 58.933′ W
@@ -99,8 +99,8 @@ class NearPoint
             $sFound    = $aData[0];
             $fQueryLat = ($aData[3]=='N'?1:-1) * ($aData[1] + $aData[2]/60);
             $fQueryLon = ($aData[6]=='E'?1:-1) * ($aData[4] + $aData[5]/60);
-        } elseif (preg_match('/\\b([NS])[ ]([0-9]+)[° ]+([0-9]+)[′\' ]+([0-9]+)[″"]*[, ]+([EW])[ ]([0-9]+)[° ]+([0-9]+)[′\' ]+([0-9]+)[″"]*\\b/', $sQuery, $aData)) {
-            /*                    1        2            3            4                5        6            7            8
+        } elseif (preg_match('/\\s*([NS])[ ]([0-9]+)[° ]+([0-9]+)[′\' ]+([0-9]+)[″"]*[, ]+([EW])[ ]([0-9]+)[° ]+([0-9]+)[′\' ]+([0-9]+)[″"]*\\s*/', $sQuery, $aData)) {
+            /*                     1        2            3              4                 5        6            7              8
              * degrees decimal seconds
              * N 40 26 46 W 79 58 56
              * N 40° 26′ 46″, W 79° 58′ 56″
@@ -108,8 +108,8 @@ class NearPoint
             $sFound    = $aData[0];
             $fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2] + $aData[3]/60 + $aData[4]/3600);
             $fQueryLon = ($aData[5]=='E'?1:-1) * ($aData[6] + $aData[7]/60 + $aData[8]/3600);
-        } elseif (preg_match('/\\b([0-9]+)[° ]+([0-9]+)[′\' ]+([0-9]+)[″" ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+)[′\' ]+([0-9]+)[″" ]+([EW])\\b/', $sQuery, $aData)) {
-            /*                    1            2            3            4          5            6            7            8
+        } elseif (preg_match('/\\s*([0-9]+)[° ]+([0-9]+)[′\' ]+([0-9]+)[″" ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+)[′\' ]+([0-9]+)[″" ]+([EW])\\s*/', $sQuery, $aData)) {
+            /*                     1            2              3             4          5            6              7             8
              * degrees decimal seconds
              * 40 26 46 N 79 58 56 W
              * 40° 26′ 46″ N, 79° 58′ 56″ W
@@ -117,26 +117,27 @@ class NearPoint
             $sFound    = $aData[0];
             $fQueryLat = ($aData[4]=='N'?1:-1) * ($aData[1] + $aData[2]/60 + $aData[3]/3600);
             $fQueryLon = ($aData[8]=='E'?1:-1) * ($aData[5] + $aData[6]/60 + $aData[7]/3600);
-        } elseif (preg_match('/\\b([NS])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*[, ]+([EW])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*\\b/', $sQuery, $aData)) {
-            /*                    1        2                               3        4
+        } elseif (preg_match('/\\s*([NS])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*[, ]+([EW])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*\\s*/', $sQuery, $aData)) {
+            /*                     1        2                               3        4
              * degrees decimal
              * N 40.446° W 79.982°
              */
             $sFound    = $aData[0];
             $fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2]);
             $fQueryLon = ($aData[3]=='E'?1:-1) * ($aData[4]);
-        } elseif (preg_match('/\\b([0-9]+[0-9]*\\.[0-9]+)[° ]+([NS])[, ]+([0-9]+[0-9]*\\.[0-9]+)[° ]+([EW])\\b/', $sQuery, $aData)) {
-            /*                    1                           2          3                           4
+        } elseif (preg_match('/\\s*([0-9]+[0-9]*\\.[0-9]+)[° ]+([NS])[, ]+([0-9]+[0-9]*\\.[0-9]+)[° ]+([EW])\\s*/', $sQuery, $aData)) {
+            /*                     1                           2          3                           4
              * degrees decimal
              * 40.446° N 79.982° W
              */
             $sFound    = $aData[0];
             $fQueryLat = ($aData[2]=='N'?1:-1) * ($aData[1]);
             $fQueryLon = ($aData[4]=='E'?1:-1) * ($aData[3]);
-        } elseif (preg_match('/(\\[|^|\\b)?(-?[0-9]+[0-9]*\\.[0-9]+)[, ]+(-?[0-9]+[0-9]*\\.[0-9]+)(\\]|$|\\b)/', $sQuery, $aData)) {
-            /*                 1           2                             3                        4
+        } elseif (preg_match('/(\\s*\\[|^\\s*|\\s*)(-?[0-9]+[0-9]*\\.[0-9]+)[, ]+(-?[0-9]+[0-9]*\\.[0-9]+)(\\]\\s*|\\s*$|\\s*)/', $sQuery, $aData)) {
+            /*                 1                   2                             3                        4
              * degrees decimal
              * 12.34, 56.78
+             * 12.34 56.78
              * [12.456,-78.90]
              */
             $sFound    = $aData[0];
index f92aff3cba2151090530e6495b62a635626ead1a..6033f7cca5978ca105960579d0bcfc3fbc852cb3 100644 (file)
@@ -18,3 +18,10 @@ Feature: Searches with postcodes
             | country_code |
             | li           |
 
+    Scenario: Postcode search with country code restriction
+        When sending json search query "9490" with address
+            | countrycodes |
+            | li |
+        Then result addresses contain
+            | country_code |
+            | li           |
index 49e1d9c052e575e2880add13d3309ddfe5167482..2767f87cfd40fc84bb74005983be0fbd066b6d2a 100644 (file)
@@ -96,6 +96,24 @@ Feature: Search queries
           | class    | type |
           | man_made | mast |
 
+    Scenario: Arbitrary key/value search near a road
+        When sending json search query "[leisure=table_soccer_table] immenbusch"
+        Then results contain
+          | class   | type |
+          | leisure | table_soccer_table |
+
+    Scenario: Ignore other country codes in structured search with country
+        When sending json search query ""
+            | city | country |
+            | li   | de      |
+        Then exactly 0 results are returned
+
+    Scenario: Ignore country searches when query is restricted to countries
+        When sending json search query "de"
+            | countrycodes |
+            | li  |
+        Then exactly 0 results are returned
+
     # https://trac.openstreetmap.org/ticket/5094
     Scenario: housenumbers are ordered by complete match first
         When sending json search query "6395 geminis, montevideo" with address
index aa8c8ce8c46afa50cc3c0e16753e560319132aae..ea709b8094d7e0845a6343232f95ccfce512e656 100644 (file)
@@ -107,7 +107,7 @@ Feature: Simple Tests
           | attr        | value |
           | querystring | xnznxvcx |
           | polygon     | false |
-          | viewbox     | 12,45.13,77,33 |
+          | viewbox     | 12,33,77,45.13 |
 
     Scenario: Empty XML search with viewboxlbrt
         When sending xml search query "xnznxvcx"
@@ -127,7 +127,7 @@ Feature: Simple Tests
           | attr        | value |
           | querystring | pub |
           | polygon     | false |
-          | viewbox     | 12,45.13,77,33 |
+          | viewbox     | 12,33,77,45.13 |
 
     Scenario Outline: Empty XML search with polygon values
         When sending xml search query "xnznxvcx"
index 5ad73451ecf997660758cd2c6d2e1782011c6b1e..bee7d3eb3e11d368c1512e1970a7ce1f6cba47eb 100644 (file)
@@ -27,7 +27,7 @@ class NearPointTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals($aRes['pt']->lat(), 12.456);
         $this->assertEquals($aRes['pt']->lon(), -78.90);
         $this->assertEquals($aRes['pt']->radius(), 0.1);
-        $this->assertEquals($aRes['query'], 'abc   def');
+        $this->assertEquals($aRes['query'], 'abc def');
 
         $aRes = NearPoint::extractFromQuery(' [12.456,-78.90] ');
         $this->assertEquals($aRes['pt']->lat(), 12.456);
@@ -69,6 +69,7 @@ class NearPointTest extends \PHPUnit_Framework_TestCase
             $aRes = NearPoint::extractFromQuery($sQuery);
             $this->assertEquals(40.446, $aRes['pt']->lat(), 'degrees decimal ' . $sQuery, 0.01);
             $this->assertEquals(-79.982, $aRes['pt']->lon(), 'degrees decimal ' . $sQuery, 0.01);
+            $this->assertEquals('', $aRes['query']);
         }
     }