X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/ab6a99677293c9ddb96a717f03b8a009e98ab955..14e6dab005c49a77ac49b6503f7807e620ea0ed3:/lib/lib.php?ds=sidebyside diff --git a/lib/lib.php b/lib/lib.php index e384949e..a7c805f7 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -3,8 +3,8 @@ function fail($sError, $sUserError = false) { if (!$sUserError) $sUserError = $sError; - log('ERROR:'.$sError); - echo $sUserError; + error_log('ERROR: '.$sError); + echo $sUserError."\n"; exit; } @@ -24,7 +24,14 @@ $aLoadAverage = explode(' ',$sLoadAverage); return (int)$aLoadAverage[0]; } - + + function getProcessorCount() + { + $sCPU = file_get_contents('/proc/cpuinfo'); + preg_match_all('#processor : [0-9]+#', $sCPU, $aMatches); + return sizeof($aMatches[0]); + } + function bySearchRank($a, $b) { if ($a['iSearchRank'] == $b['iSearchRank']) return 0; @@ -33,12 +40,18 @@ function byImportance($a, $b) { +/* + if ($a['importance'] != $b['importance']) + return ($a['importance'] > $b['importance']?-1:1); if ($a['aPointPolygon']['numfeatures'] != $b['aPointPolygon']['numfeatures']) return ($a['aPointPolygon']['numfeatures'] > $b['aPointPolygon']['numfeatures']?-1:1); if ($a['aPointPolygon']['area'] != $b['aPointPolygon']['area']) return ($a['aPointPolygon']['area'] > $b['aPointPolygon']['area']?-1:1); - if ($a['importance'] != $b['importance']) - return ($a['importance'] < $b['importance']?-1:1); +// if ($a['levenshtein'] != $b['levenshtein']) +// return ($a['levenshtein'] < $b['levenshtein']?-1:1); + if ($a['rank_search'] != $b['rank_search']) + return ($a['rank_search'] < $b['rank_search']?-1:1); +*/ return ($a['foundorder'] < $b['foundorder']?-1:1); } @@ -49,7 +62,7 @@ { $_SERVER["HTTP_ACCEPT_LANGUAGE"] = $_GET['accept-language']; } - + $aLanguages = array(); 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)) { @@ -152,25 +165,32 @@ function gbPostcodeCalculate($sPostcode, $sPostcodeSector, $sPostcodeEnd, &$oDB) { // Try an exact match on the gb_postcode table - $sSQL = 'select \'AA\', ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from gb_postcode where upper(postcode) = \''.$sPostcode.'\''; + $sSQL = 'select \'AA\', ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from gb_postcode where postcode = \''.$sPostcode.'\''; $aNearPostcodes = $oDB->getAll($sSQL); if (PEAR::IsError($aNearPostcodes)) { var_dump($sSQL, $aNearPostcodes); exit; } + - if (!sizeof($aNearPostcodes)) + if (sizeof($aNearPostcodes)) { - $sSQL = 'select substring(upper(postcode) from \'^[A-Z][A-Z]?[0-9][0-9A-Z]? [0-9]([A-Z][A-Z])$\'),ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from placex where country_code::text = \'gb\'::text AND substring(upper(postcode) from \'^([A-Z][A-Z]?[0-9][0-9A-Z]? [0-9])[A-Z][A-Z]$\') = \''.$sPostcodeSector.'\' and class=\'place\' and type=\'postcode\' '; - $sSQL .= ' union '; - $sSQL .= 'select substring(upper(postcode) from \'^[A-Z][A-Z]?[0-9][0-9A-Z]? [0-9]([A-Z][A-Z])$\'),ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from gb_postcode where substring(upper(postcode) from \'^([A-Z][A-Z]?[0-9][0-9A-Z]? [0-9])[A-Z][A-Z]$\') = \''.$sPostcodeSector.'\''; - $aNearPostcodes = $oDB->getAll($sSQL); - if (PEAR::IsError($aNearPostcodes)) - { - var_dump($sSQL, $aNearPostcodes); - exit; - } + return array(array('lat' => $aNearPostcodes[0]['lat'], 'lon' => $aNearPostcodes[0]['lon'], 'radius' => 0.005)); + } + + return false; + + /* partial search disabled because it sequentially scans placex + + $sSQL = 'select substring(upper(postcode) from \'^[A-Z][A-Z]?[0-9][0-9A-Z]? [0-9]([A-Z][A-Z])$\'),ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from placex where country_code::text = \'gb\'::text AND substring(postcode from \'^([A-Z][A-Z]?[0-9][0-9A-Z]? [0-9])[A-Z][A-Z]$\') = \''.$sPostcodeSector.'\' and class=\'place\' and type=\'postcode\' '; + $sSQL .= ' union '; + $sSQL .= 'select substring(upper(postcode) from \'^[A-Z][A-Z]?[0-9][0-9A-Z]? [0-9]([A-Z][A-Z])$\'),ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from gb_postcode where substring(postcode from \'^([A-Z][A-Z]?[0-9][0-9A-Z]? [0-9])[A-Z][A-Z]$\') = \''.$sPostcodeSector.'\''; + $aNearPostcodes = $oDB->getAll($sSQL); + if (PEAR::IsError($aNearPostcodes)) + { + var_dump($sSQL, $aNearPostcodes); + exit; } if (!sizeof($aNearPostcodes)) @@ -201,7 +221,7 @@ return array(array('lat' => $fLat, 'lon' => $fLon, 'radius' => $fRadius)); } return false; - + */ /* $fTotalFac is a suprisingly good indicator of accuracy $iZoom = 18 + round(log($fTotalFac,32)); @@ -271,21 +291,21 @@ function getClassTypes() { return array( - 'boundary:adminitrative:2' => array('label'=>'Country','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), - 'boundary:adminitrative:4' => array('label'=>'State','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), - 'boundary:adminitrative:5' => array('label'=>'State District','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), - 'boundary:adminitrative:6' => array('label'=>'County','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), - 'boundary:adminitrative:8' => array('label'=>'City','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), - 'boundary:adminitrative:9' => array('label'=>'City District','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), - 'boundary:adminitrative:10' => array('label'=>'Suburb','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), - 'boundary:adminitrative:11' => array('label'=>'Neighbourhood','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), - 'place:city' => array('label'=>'City','frequency'=>66,'icon'=>'poi_place_city','defzoom'=>12, 'defdiameter' => 0.32,), + 'boundary:administrative:2' => array('label'=>'Country','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), 'place:country' => array('label'=>'Country','frequency'=>0,'icon'=>'poi_boundary_administrative','defzoom'=>6, 'defdiameter' => 15,), + 'boundary:administrative:4' => array('label'=>'State','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), 'place:state' => array('label'=>'State','frequency'=>0,'icon'=>'poi_boundary_administrative','defzoom'=>8, 'defdiameter' => 5.12,), - 'place:region' => array('label'=>'State','frequency'=>0,'icon'=>'poi_boundary_administrative','defzoom'=>8, 'defdiameter' => 5.12,), - 'place:island' => array('label'=>'Island','frequency'=>288,'icon'=>'','defzoom'=>11, 'defdiameter' => 0.64,), + 'boundary:administrative:5' => array('label'=>'State District','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), + 'boundary:administrative:6' => array('label'=>'County','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), 'place:county' => array('label'=>'County','frequency'=>108,'icon'=>'poi_boundary_administrative','defzoom'=>10, 'defdiameter' => 1.28,), - 'boundary:adminitrative' => array('label'=>'Administrative','frequency'=>413,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), + 'boundary:administrative:8' => array('label'=>'City','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), + 'place:city' => array('label'=>'City','frequency'=>66,'icon'=>'poi_place_city','defzoom'=>12, 'defdiameter' => 0.32,), + 'boundary:administrative:9' => array('label'=>'City District','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), + 'boundary:administrative:10' => array('label'=>'Suburb','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), + 'boundary:administrative:11' => array('label'=>'Neighbourhood','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), + 'place:region' => array('label'=>'Region','frequency'=>0,'icon'=>'poi_boundary_administrative','defzoom'=>8, 'defdiameter' => 5.12,), + 'place:island' => array('label'=>'Island','frequency'=>288,'icon'=>'','defzoom'=>11, 'defdiameter' => 0.64,), + 'boundary:administrative' => array('label'=>'Administrative','frequency'=>413,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,), 'place:town' => array('label'=>'Town','frequency'=>1497,'icon'=>'poi_place_town','defzoom'=>14, 'defdiameter' => 0.08,), 'place:village' => array('label'=>'Village','frequency'=>11230,'icon'=>'poi_place_village','defzoom'=>15, 'defdiameter' => 0.04,), 'place:hamlet' => array('label'=>'Hamlet','frequency'=>7075,'icon'=>'poi_place_village','defzoom'=>15, 'defdiameter' => 0.04,), @@ -428,6 +448,9 @@ 'amenity:shop' => array('label'=>'Shop','frequency'=>61,'icon'=>'',), 'place:house' => array('label'=>'House','frequency'=>2086,'icon'=>'','defzoom'=>18,), + 'place:house_name' => array('label'=>'House','frequency'=>2086,'icon'=>'','defzoom'=>18,), + 'place:house_number' => array('label'=>'House Number','frequency'=>2086,'icon'=>'','defzoom'=>18,), + 'place:country_code' => array('label'=>'Country Code','frequency'=>2086,'icon'=>'','defzoom'=>18,), // @@ -549,6 +572,7 @@ 'amenity:shopping' => array('label'=>'Shopping','frequency'=>21,'icon'=>'',), 'natural:scrub' => array('label'=>'Scrub','frequency'=>20,'icon'=>'',), 'natural:fen' => array('label'=>'Fen','frequency'=>20,'icon'=>'',), + 'building:yes' => array('label'=>'Building','frequency'=>200,'icon'=>'',), 'amenity:parking' => array('label'=>'Parking','frequency'=>3157,'icon'=>'',), 'highway:bus_stop' => array('label'=>'Bus Stop','frequency'=>35777,'icon'=>'transport_bus_stop2',), @@ -612,7 +636,7 @@ else { if (is_bool($xVal)) return $xVal?'true':'false'; - if (is_numeric($xVal)) return $xVal; +// if (is_numeric($xVal)) return $xVal; return '"'.str_replace('>','\\>',str_replace(array("\n","\r"),'\\n',str_replace(array("\n\r","\r\n"),'\\n',str_replace('"','\\"',$xVal)))).'"'; } } @@ -620,11 +644,17 @@ function _debugDumpGroupedSearches($aData, $aTokens) { $aWordsIDs = array(); - foreach($aTokens as $sToken => $aWords) + if ($aTokens) { - foreach($aWords as $aToken) + foreach($aTokens as $sToken => $aWords) { - $aWordsIDs[$aToken['word_id']] = $sToken.'('.$aToken['word_id'].')'; + if ($aWords) + { + foreach($aWords as $aToken) + { + $aWordsIDs[$aToken['word_id']] = $sToken.'('.$aToken['word_id'].')'; + } + } } } echo "