]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/Geocode.php
use correct source for radius column in debug view
[nominatim.git] / lib / Geocode.php
index 0c2a9963e639ce44f785a060190ebb32e4d9b0a2..aef2d3841cc5f4eec9d4e060baf002700e463f1f 100644 (file)
@@ -910,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;
     }
 
@@ -1111,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) {
@@ -1563,7 +1572,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;
@@ -1728,9 +1738,11 @@ class Geocode
                     // Need to verify passes rank limits before dropping out of the loop (yuk!)
                     // reduces the number of place ids, like a filter
                     // rank_address is 30 for interpolated housenumbers
+                    $sWherePlaceId = 'WHERE place_id in (';
+                    $sWherePlaceId .= join(',', array_keys($aResultPlaceIDs)).') ';
+
                     $sSQL = "SELECT place_id ";
-                    $sSQL .= "FROM placex ";
-                    $sSQL .= "WHERE place_id in (".join(',', array_keys($aResultPlaceIDs)).") ";
+                    $sSQL .= "FROM placex ".$sWherePlaceId;
                     $sSQL .= "  AND (";
                     $sSQL .= "         placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
                     if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) {
@@ -1739,18 +1751,22 @@ class Geocode
                     if ($this->aAddressRankList) {
                         $sSQL .= "     OR placex.rank_address in (".join(',', $this->aAddressRankList).")";
                     }
-                    $sSQL .= "  ) ";
+                    $sSQL .= "  ) UNION ";
+                    $sSQL .= " SELECT place_id FROM location_postcode lp ".$sWherePlaceId;
+                    $sSQL .= "  AND (lp.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
+                    if ($this->aAddressRankList) {
+                        $sSQL .= "     OR lp.rank_address in (".join(',', $this->aAddressRankList).")";
+                    }
+                    $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 .= "  FROM location_property_tiger ".$sWherePlaceId;
                     }
                     if ($this->iMaxAddressRank == 30) {
                         $sSQL .= "UNION ";
                         $sSQL .= "  SELECT place_id ";
-                        $sSQL .= "  FROM location_property_osmline ";
-                        $sSQL .= "  WHERE place_id in (".join(',', array_keys($aResultPlaceIDs)).")";
+                        $sSQL .= "  FROM location_property_osmline ".$sWherePlaceId;
                     }
                     if (CONST_Debug) var_dump($sSQL);
                     $aFilteredPlaceIDs = chksql($this->oDB->getCol($sSQL));