]> git.openstreetmap.org Git - nominatim.git/commitdiff
fix API tests wrt postcodes
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 9 Jul 2017 07:37:10 +0000 (09:37 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sat, 19 Aug 2017 17:37:06 +0000 (19:37 +0200)
lib/Geocode.php
test/bdd/api/search/params.feature

index 6f26b3cd73c13582f6341b44cbd0a29786abcc2b..ae6f9cfbb0cf320c99810958de6e483eb5bc0d34 100644 (file)
@@ -422,8 +422,15 @@ class Geocode
         $sPlaceIDs = join(',', array_keys($aPlaceIDs));
 
         $sImportanceSQL = '';
-        if ($this->sViewboxSmallSQL) $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxSmallSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
-        if ($this->sViewboxLargeSQL) $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxLargeSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
+        $sImportanceSQLGeom = '';
+        if ($this->sViewboxSmallSQL) {
+            $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxSmallSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
+            $sImportanceSQLGeom .= " CASE WHEN ST_Contains($this->sViewboxSmallSQL, geometry) THEN 1 ELSE 0.75 END * ";
+        }
+        if ($this->sViewboxLargeSQL) {
+            $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxLargeSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
+            $sImportanceSQLGeom .= " CASE WHEN ST_Contains($this->sViewboxLargeSQL, geometry) THEN 1 ELSE 0.75 END * ";
+        }
 
         $sSQL  = "SELECT ";
         $sSQL .= "    osm_type,";
@@ -502,7 +509,7 @@ class Geocode
         if ($this->bIncludeExtraTags) $sSQL .= "null AS extra,";
         if ($this->bIncludeNameDetails) $sSQL .= "null AS names,";
         $sSQL .= "  ST_x(st_centroid(geometry)) AS lon, ST_y(st_centroid(geometry)) AS lat,";
-        $sSQL .=    $sImportanceSQL."(0.75-(rank_search::float/40)) AS importance, ";
+        $sSQL .=    $sImportanceSQLGeom."(0.75-(rank_search::float/40)) AS importance, ";
         $sSQL .= "  (";
         $sSQL .= "     SELECT max(p.importance*(p.rank_address+2))";
         $sSQL .= "     FROM ";
@@ -747,7 +754,7 @@ class Geocode
                                     if (isset($aSearchTerm['word_id']) && $aSearchTerm['word_id'] && strpos($sNormQuery, $this->normTerm($aSearchTerm['word'])) !== false) {
                                         // If we have structured search or this is the first term,
                                         // make the postcode the primary search element.
-                                        if ($aSearchTerm['operator'] == '' && ($sPhraseType == 'postalcode' || sizeof($aSearch['aName']) == 0)) {
+                                        if ($aSearchTerm['operator'] == '' && ($sPhraseType == 'postalcode' || ($iToken == 0 && $iPhrase == 0))) {
                                             $aNewSearch = $aSearch;
                                             $aNewSearch['sOperator'] = 'postcode';
                                             $aNewSearch['aAddress'] = array_merge($aNewSearch['aAddress'], $aNewSearch['aName']);
@@ -1698,7 +1705,7 @@ class Geocode
                         var_Dump($aPlaceIDs);
                     }
 
-                    if ($aSearch['sPostcode']) {
+                    if (sizeof($aPlaceIDs) && $aSearch['sPostcode']) {
                         $sSQL = 'SELECT place_id FROM placex';
                         $sSQL .= ' WHERE place_id in ('.join(',', $aPlaceIDs).')';
                         $sSQL .= " AND postcode = '".pg_escape_string($aSearch['sPostcode'])."'";
index d1cff1cc5d63818909b751d381fcc2c8e9254298..fba83eab0acdd72f6caeec6cd54e553a93ab5c96 100644 (file)
@@ -25,6 +25,7 @@ Feature: Search queries
           | type         | value |
           | city         | Montevideo |
           | state        | Montevideo |
+          | postcode     | 11000 |
           | country      | Uruguay |
           | country_code | uy |