X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/b4c87a09a194a7d966724ce48ba2d8ef0d044ca0..65aba66c99903322bc56c7ca99ac29446dd94d09:/lib/lib.php diff --git a/lib/lib.php b/lib/lib.php index 96d2c048..a7584b37 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -45,7 +45,7 @@ if (!$sUserError) $sUserError = $sError; error_log('ERROR: '.$sError); echo $sUserError."\n"; - exit; + exit(-1); } @@ -94,7 +94,8 @@ function bySearchRank($a, $b) { - if ($a['iSearchRank'] == $b['iSearchRank']) return 0; + if ($a['iSearchRank'] == $b['iSearchRank']) + return strlen($a['sOperator']) + strlen($a['sHouseNumber']) - strlen($b['sOperator']) - strlen($b['sHouseNumber']); return ($a['iSearchRank'] < $b['iSearchRank']?-1:1); } @@ -117,18 +118,26 @@ } - function getPreferredLanguages() + function getPreferredLanguages($sLangString=false) { - // If we have been provided the value in $_GET it overrides browser value - if (isset($_GET['accept-language']) && $_GET['accept-language']) + if (!$sLangString) { - $_SERVER["HTTP_ACCEPT_LANGUAGE"] = $_GET['accept-language']; + // If we have been provided the value in $_GET it overrides browser value + if (isset($_GET['accept-language']) && $_GET['accept-language']) + { + $_SERVER["HTTP_ACCEPT_LANGUAGE"] = $_GET['accept-language']; + $sLangString = $_GET['accept-language']; + } + else if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) + { + $sLangString = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; + } } $aLanguages = array(); - if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) + if ($sLangString) { - if (preg_match_all('/(([a-z]{1,8})(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $aLanguagesParse, PREG_SET_ORDER)) + if (preg_match_all('/(([a-z]{1,8})(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $sLangString, $aLanguagesParse, PREG_SET_ORDER)) { foreach($aLanguagesParse as $iLang => $aLanguage) { @@ -169,7 +178,7 @@ { $aResult = array(array(join(' ',$aWords))); $sFirstToken = ''; - if ($iDepth < 8) { + if ($iDepth < 7) { while(sizeof($aWords) > 1) { $sWord = array_shift($aWords); @@ -246,7 +255,13 @@ if (sizeof($aNearPostcodes)) { - return array(array('lat' => $aNearPostcodes[0]['lat'], 'lon' => $aNearPostcodes[0]['lon'], 'radius' => 0.005)); + $aPostcodes = array(); + foreach($aNearPostcodes as $aPostcode) + { + $aPostcodes[] = array('lat' => $aPostcode['lat'], 'lon' => $aPostcode['lon'], 'radius' => 0.005); + } + + return $aPostcodes; } return false; @@ -371,6 +386,8 @@ 'landuse:commercial' => array('label'=>'Commercial','frequency'=>657,'icon'=>'',), 'place:airport' => array('label'=>'Airport','frequency'=>36,'icon'=>'transport_airport2', 'defdiameter' => 0.03,), + 'aeroway:aerodrome' => array('label'=>'Aerodrome','frequency'=>36,'icon'=>'transport_airport2', 'defdiameter' => 0.03,), + 'aeroway' => array('label'=>'Aeroway','frequency'=>36,'icon'=>'transport_airport2', 'defdiameter' => 0.03,), 'railway:station' => array('label'=>'Station','frequency'=>3431,'icon'=>'transport_train_station2', 'defdiameter' => 0.01,), 'amenity:place_of_worship' => array('label'=>'Place Of Worship','frequency'=>9049,'icon'=>'place_of_worship_unknown3',), 'amenity:pub' => array('label'=>'Pub','frequency'=>18969,'icon'=>'food_pub',), @@ -774,7 +791,7 @@ { $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel'])?$aTypeLabel['simplelabel']:$aTypeLabel['label']); $sTypeLabel = str_replace(' ','_',$sTypeLabel); - if (!isset($aAddress[$sTypeLabel]) || (isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel])) + if (!isset($aAddress[$sTypeLabel]) || (isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel]) || $aLine['class'] == 'place') { $aAddress[$sTypeLabel] = $aLine['localname']?$aLine['localname']:$aLine['housenumber']; } @@ -785,20 +802,6 @@ } - function getWordSuggestions(&$oDB, $sWord) - { - $sWordQuoted = getDBQuoted(trim($sWord)); - $sSQL = "select *,levenshtein($sWordQuoted,word) from test_token "; - $sSQL .= "where (metaphone = dmetaphone($sWordQuoted) or metaphonealt = dmetaphone($sWordQuoted) or "; - $sSQL .= "metaphone = dmetaphone_alt($sWordQuoted) or metaphonealt = dmetaphone_alt($sWordQuoted)) "; - $sSQL .= "and len between length($sWordQuoted)-2 and length($sWordQuoted)+2 "; - $sSQL .= "and levenshtein($sWordQuoted,word) < 3 "; - $sSQL .= "order by levenshtein($sWordQuoted,word) asc, abs(len - length($sWordQuoted)) asc limit 20"; - $aSimilar = $oDB->getAll($sSQL); - return $aSimilar; - } - - function geocodeReverse($fLat, $fLon, $iZoom=18) { $oDB =& getDB(); @@ -860,12 +863,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 @@ -898,16 +901,7 @@ return $iPlaceID; } - function loadStructuredAddressElement(&$aStructuredQuery, &$iMinAddressRank, &$iMaxAddressRank, $aParams, $sKey, $iNewMinAddressRank, $iNewMaxAddressRank) + function addQuotes($s) { - if (!isset($_GET[$sKey])) return false; - $sValue = trim($_GET[$sKey]); - if (!$sValue) return false; - $aStructuredQuery[$sKey] = $sValue; - if ($iMinAddressRank == 0 && $iMaxAddressRank == 30) - { - $iMinAddressRank = $iNewMinAddressRank; - $iMaxAddressRank = $iNewMaxAddressRank; - } - return true; + return "'".$s."'"; }