X-Git-Url: https://git.openstreetmap.org/nominatim.git/blobdiff_plain/ce32d77a658afe254d792d3a9322a620dccddce9..1f2ee8ed77695c2e475508f961db5b37f8d83bd6:/lib/Geocode.php diff --git a/lib/Geocode.php b/lib/Geocode.php index eda692b0..c464aeed 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -20,6 +20,7 @@ protected $iLimit = 20; protected $iFinalLimit = 10; protected $iOffset = 0; + protected $bFallback = false; protected $aCountryCodes = false; protected $aNearPoint = false; @@ -120,6 +121,11 @@ $this->iOffset = $iOffset; } + function setFallback($bFallback = true) + { + $this->bFallback = (bool)$bFallback; + } + function setExcludedPlaceIDs($a) { // TODO: force to int @@ -216,6 +222,11 @@ { $this->sQuery = false; + // Reset + $this->iMinAddressRank = 0; + $this->iMaxAddressRank = 30; + $this->aAddressRankList = array(); + $this->aStructuredQuery = array(); $this->sAllowedTypesSQLList = ''; @@ -235,7 +246,29 @@ $sAllowedTypesSQLList = '(\'place\',\'boundary\')'; } } + } + + function fallbackStructuredQuery() + { + if (!$this->aStructuredQuery) return false; + + $aParams = $this->aStructuredQuery; + + if (sizeof($aParams) == 1) return false; + + $aOrderToFallback = array('postalcode', 'street', 'city', 'county', 'state'); + + foreach($aOrderToFallback as $sType) + { + if (isset($aParams[$sType])) + { + unset($aParams[$sType]); + $this->setStructuredQuery(@$aParams['amenity'], @$aParams['street'], @$aParams['city'], @$aParams['county'], @$aParams['state'], @$aParams['country'], @$aParams['postalcode']); + return true; + } + } + return false; } function getDetails($aPlaceIDs) @@ -1423,6 +1456,14 @@ // No results? Done if (!sizeof($aSearchResults)) { + if ($this->bFallback) + { + if ($this->fallbackStructuredQuery()) + { + return $this->lookup(); + } + } + return array(); }