From: Sarah Hoffmann Date: Wed, 5 Feb 2014 19:19:05 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Tag: deploy~560 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/1f2ee8ed77695c2e475508f961db5b37f8d83bd6?hp=ce32d77a658afe254d792d3a9322a620dccddce9 Merge remote-tracking branch 'upstream/master' Conflicts: lib/init-website.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(); } diff --git a/lib/init-website.php b/lib/init-website.php index 4d1c2c70..013aee4b 100644 --- a/lib/init-website.php +++ b/lib/init-website.php @@ -13,5 +13,4 @@ } if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit; - header('Content-type: text/html; charset=utf-8'); diff --git a/lib/lib.php b/lib/lib.php index e569aa8b..482e9598 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -852,12 +852,12 @@ $sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', geometry) ASC limit 1'; //var_dump($sSQL); $aPlace = $oDB->getRow($sSQL); - $iPlaceID = $aPlace['place_id']; - if (PEAR::IsError($iPlaceID)) + if (PEAR::IsError($aPlace)) { - var_Dump($sSQL, $iPlaceID); + var_Dump($sSQL, $aPlace); exit; } + $iPlaceID = $aPlace['place_id']; } // The point we found might be too small - use the address to find what it is a child of diff --git a/lib/template/address-xml.php b/lib/template/address-xml.php index 0747844a..9eeb3b77 100644 --- a/lib/template/address-xml.php +++ b/lib/template/address-xml.php @@ -22,7 +22,8 @@ { echo "setLimit((int)$aParams['limit']); if (isset($aParams['offset'])) $oGeocode->setOffset((int)$aParams['offset']); + if (isset($aParams['fallback'])) $oGeocode->setFallback((int)$aParams['fallback']); + // List of excluded Place IDs - used for more acurate pageing if (isset($aParams['exclude_place_ids']) && $aParams['exclude_place_ids']) { diff --git a/website/status.php b/website/status.php index c9d872d0..a876f999 100644 --- a/website/status.php +++ b/website/status.php @@ -3,24 +3,39 @@ require_once(dirname(dirname(__FILE__)).'/lib/init-website.php'); + function statusError($sMsg) + { + header("HTTP/1.0 500 Internal Server Error"); + echo "ERROR: ".$sMsg; + exit; + } + $oDB =& getDB(); if (!$oDB || PEAR::isError($oDB)) { - echo "ERROR: No database"; - exit; + statusError("No database"); + } + + $sStandardWord = $oDB->getOne("select make_standard_name('a')"); + if (PEAR::isError($sStandardWord)) + { + statusError("Module failed"); + } + if ($sStandardWord != 'a') + { + statusError("Module call failed"); } $iWordID = $oDB->getOne("select word_id,word_token, word, class, type, country_code, operator, search_name_count from word where word_token in (' a')"); if (PEAR::isError($iWordID)) { - echo "ERROR: Query failed"; - exit; + statusError("Query failed"); } if (!$iWordID) { - echo "ERROR: No value"; - exit; + statusError("No value"); } + echo "OK"; exit;