harmonize formatting of frontend php

This commit is contained in:
Sarah Hoffmann
2013-04-12 22:45:24 +02:00
parent 01bcb59e44
commit fb0d219c7b
7 changed files with 868 additions and 838 deletions

View File

@@ -11,10 +11,12 @@
if (CONST_Debug)
{
echo "<hr><h2>Debugging Information</h2><br>";
if ($sSQL) {
if ($sSQL)
{
echo "<h3>SQL query</h3><code>".$sSQL."</code>";
}
if ($vDumpVar) {
if ($vDumpVar)
{
echo "<h3>Result</h3> <code>";
var_dump($vDumpVar);
echo "</code>";
@@ -22,9 +24,9 @@
}
echo "\n</body></html>\n";
exit;
}
function userError($sError)
{
header('HTTP/1.0 400 Bad Request');
@@ -35,9 +37,9 @@
echo '<p>If you feel this error is incorrect feel free to report the bug in the <a href="http://trac.openstreetmap.org">OSM bug database</a>. Please include the error message above and the URL you used.</p>';
echo "\n</body></html>\n";
exit;
}
function fail($sError, $sUserError = false)
{
if (!$sUserError) $sUserError = $sError;
@@ -46,6 +48,7 @@
exit;
}
function getBlockingProcesses()
{
$sStats = file_get_contents('/proc/stat');
@@ -56,6 +59,7 @@
return 0;
}
function getLoadAverage()
{
$sLoadAverage = file_get_contents('/proc/loadavg');
@@ -63,6 +67,7 @@
return (float)$aLoadAverage[0];
}
function getProcessorCount()
{
$sCPU = file_get_contents('/proc/cpuinfo');
@@ -70,6 +75,7 @@
return sizeof($aMatches[0]);
}
function getTotalMemoryMB()
{
$sCPU = file_get_contents('/proc/meminfo');
@@ -77,6 +83,7 @@
return (int)($aMatches[1]/1024);
}
function getCacheMemoryMB()
{
$sCPU = file_get_contents('/proc/meminfo');
@@ -84,29 +91,32 @@
return (int)($aMatches[1]/1024);
}
function bySearchRank($a, $b)
{
if ($a['iSearchRank'] == $b['iSearchRank']) return 0;
return ($a['iSearchRank'] < $b['iSearchRank']?-1:1);
}
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['levenshtein'] != $b['levenshtein'])
// return ($a['levenshtein'] < $b['levenshtein']?-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);
}
function getPreferredLanguages()
{
// If we have been provided the value in $_GET it overrides browser value
@@ -116,7 +126,8 @@
}
$aLanguages = array();
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
{
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))
{
foreach($aLanguagesParse as $iLang => $aLanguage)
@@ -153,6 +164,7 @@
return $aLangPrefOrder;
}
function getWordSets($aWords)
{
$aResult = array(array(join(' ',$aWords)));
@@ -170,6 +182,7 @@
return $aResult;
}
function getTokensFromSets($aSets)
{
$aTokens = array();
@@ -185,6 +198,7 @@
return $aTokens;
}
/*
GB Postcode functions
*/
@@ -216,6 +230,7 @@
return abs(($aValues[$s1[0]]*21+$aValues[$s1[1]]) - ($aValues[$s2[0]]*21+$aValues[$s2[1]]));
}
function gbPostcodeCalculate($sPostcode, $sPostcodeSector, $sPostcodeEnd, &$oDB)
{
// Try an exact match on the gb_postcode table
@@ -235,6 +250,7 @@
return false;
}
function usPostcodeCalculate($sPostcode, &$oDB)
{
$iZipcode = (int)$sPostcode;
@@ -294,6 +310,7 @@
*/
}
function getClassTypes()
{
return array(
@@ -462,7 +479,7 @@
'place:house_number' => array('label'=>'House Number','frequency'=>2086,'icon'=>'','defzoom'=>18,),
'place:country_code' => array('label'=>'Country Code','frequency'=>2086,'icon'=>'','defzoom'=>18,),
//
//
'leisure:pitch' => array('label'=>'Pitch','frequency'=>762,'icon'=>'',),
'highway:unsurfaced' => array('label'=>'Unsurfaced','frequency'=>492,'icon'=>'',),
@@ -600,6 +617,7 @@
);
}
function getClassTypesWithImportance()
{
$aOrders = getClassTypes();
@@ -611,25 +629,31 @@
return $aOrders;
}
function javascript_renderData($xVal)
{
header("Access-Control-Allow-Origin: *");
$jsonout = json_encode($xVal);
if( ! isset($_GET['json_callback'])) {
if( ! isset($_GET['json_callback']))
{
header("Content-Type: application/json; charset=UTF-8");
echo $jsonout;
} else {
if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u',$_GET['json_callback'])) {
} else
{
if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u',$_GET['json_callback']))
{
header("Content-Type: application/javascript; charset=UTF-8");
echo $_GET['json_callback'].'('.$jsonout.')';
} else {
}
else
{
header('HTTP/1.0 400 Bad Request');
}
}
}
function _debugDumpGroupedSearches($aData, $aTokens)
{
$aWordsIDs = array();
@@ -713,7 +737,7 @@
function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCode = false, $bRaw = false)
{
$sSQL = "select *,get_name_by_language(name,$sLanguagePrefArraySQL) as localname from get_addressdata($iPlaceID)";
IF (!$bRaw) $sSQL .= " WHERE isaddress OR type = 'country_code'";
if (!$bRaw) $sSQL .= " WHERE isaddress OR type = 'country_code'";
$sSQL .= " order by rank_address desc,isaddress desc";
$aAddressLines = $oDB->getAll($sSQL);
@@ -723,8 +747,8 @@
exit;
}
if ($bRaw) return $aAddressLines;
//echo "<pre>";
//var_dump($aAddressLines);
//echo "<pre>";
//var_dump($aAddressLines);
$aAddress = array();
$aFallback = array();
$aClassType = getClassTypes();
@@ -758,6 +782,7 @@
return $aAddress;
}
function getWordSuggestions(&$oDB, $sWord)
{
$sWordQuoted = getDBQuoted(trim($sWord));
@@ -771,6 +796,7 @@
return $aSimilar;
}
function geocodeReverse($fLat, $fLon, $iZoom=18)
{
$oDB =& getDB();
@@ -830,7 +856,7 @@
$sSQL .= ' and (ST_GeometryType(geometry) not in (\'ST_Polygon\',\'ST_MultiPolygon\') ';
$sSQL .= ' OR ST_DWithin('.$sPointSQL.', ST_Centroid(geometry), '.$fSearchDiam.'))';
$sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', geometry) ASC limit 1';
//var_dump($sSQL);
//var_dump($sSQL);
$aPlace = $oDB->getRow($sSQL);
$iPlaceID = $aPlace['place_id'];
if (PEAR::IsError($iPlaceID))
@@ -876,7 +902,8 @@
$sValue = trim($_GET[$sKey]);
if (!$sValue) return false;
$aStructuredQuery[$sKey] = $sValue;
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30) {
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30)
{
$iMinAddressRank = $iNewMinAddressRank;
$iMaxAddressRank = $iNewMaxAddressRank;
}

View File

@@ -5,14 +5,14 @@
require_once(CONST_BasePath.'/lib/log.php');
$sOutputFormat = 'html';
/*
/*
$fLoadAvg = getLoadAverage();
if ($fLoadAvg > 3)
{
echo "Page temporarily blocked due to high server load\n";
exit;
}
*/
*/
ini_set('memory_limit', '200M');
$oDB =& getDB();
@@ -63,7 +63,7 @@
$sSQL = "select place_id, osm_type, osm_id, class, type, name, admin_level, housenumber, street, isin, postcode, calculated_country_code as country_code, importance, wikipedia,";
$sSQL .= " to_char(indexed_date, 'YYYY-MM-DD HH24:MI') as indexed_date, parent_place_id, rank_address, rank_search, get_searchrank_label(rank_search) as rank_search_label, get_name_by_language(name,$sLanguagePrefArraySQL) as localname, ";
$sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, ";
// $sSQL .= " ST_Area(geometry::geography) as area, ";
//$sSQL .= " ST_Area(geometry::geography) as area, ";
$sSQL .= " ST_y(centroid) as lat, ST_x(centroid) as lon,";
$sSQL .= " case when importance = 0 OR importance IS NULL then 0.75-(rank_search::float/40) else importance end as calculated_importance, ";
$sSQL .= " ST_AsText(CASE WHEN ST_NPoints(geometry) > 5000 THEN ST_SimplifyPreserveTopology(geometry, 0.0001) ELSE geometry END) as outlinestring";

View File

@@ -115,7 +115,8 @@
// The point we found might be too small - use the address to find what it is a child of
if ($iPlaceID && $iMaxRank < 28)
{
if ($aPlace['rank_search'] > 28 && $iParentPlaceID) {
if ($aPlace['rank_search'] > 28 && $iParentPlaceID)
{
$iPlaceID = $iParentPlaceID;
}
$sSQL = "select address_place_id from place_addressline where place_id = $iPlaceID order by abs(cached_rank_address - $iMaxRank) asc,cached_rank_address desc,isaddress desc,distance desc limit 1";
@@ -141,7 +142,7 @@
$sSQL .= " from placex where place_id = $iPlaceID ";
$aPlace = $oDB->getRow($sSQL);
//var_dump($sSQL, $aPlace); exit;
//var_dump($sSQL, $aPlace); exit;
if ($bShowAddressDetails)
{

View File

@@ -37,13 +37,16 @@
// Show / use polygons
$bShowPolygons = (boolean)isset($_GET['polygon']) && $_GET['polygon'];
if ($sOutputFormat == 'html') {
if ($sOutputFormat == 'html')
{
$bAsText = $bShowPolygons;
$bShowPolygons = false;
$bAsGeoJSON = false;
$bAsKML = false;
$bAsSVG = false;
} else {
}
else
{
$bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson'];
$bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml'];
$bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg'];
@@ -53,10 +56,14 @@
+ ($bAsKML?1:0)
+ ($bAsSVG?1:0)
+ ($bAsText?1:0)
) > CONST_PolygonOutput_MaximumTypes) {
if (CONST_PolygonOutput_MaximumTypes) {
) > CONST_PolygonOutput_MaximumTypes)
{
if (CONST_PolygonOutput_MaximumTypes)
{
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
} else {
}
else
{
userError("Polygon output is disabled");
}
exit;
@@ -138,7 +145,8 @@
$sValue = trim($_GET[$sKey]);
if (!$sValue) return false;
$aStructuredQuery[$sKey] = $sValue;
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30) {
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30)
{
$iMinAddressRank = $iNewMinAddressRank;
$iMaxAddressRank = $iNewMaxAddressRank;
}
@@ -161,7 +169,8 @@
{
loadStructuredAddressElement($aStructuredQuery, $iMinAddressRank, $iMaxAddressRank, $_GET, $aStructuredOption[0], $aStructuredOption[1], $aStructuredOption[2]);
}
if (sizeof($aStructuredQuery) > 0) {
if (sizeof($aStructuredQuery) > 0)
{
$sQuery = join(', ', $aStructuredQuery);
if ($iMaxAddressRank < 30)
{
@@ -201,7 +210,9 @@
$aCoOrdinates[1] += $fWidth;
$aCoOrdinates[3] -= $fWidth;
$sViewboxLargeSQL = "ST_SetSRID(ST_MakeBox2D(ST_Point(".(float)$aCoOrdinates[0].",".(float)$aCoOrdinates[1]."),ST_Point(".(float)$aCoOrdinates[2].",".(float)$aCoOrdinates[3].")),4326)";
} else {
}
else
{
$bBoundingBoxSearch = false;
}
if (isset($_GET['route']) && $_GET['route'] && isset($_GET['routewidth']) && $_GET['routewidth'])
@@ -398,16 +409,14 @@
// Check which tokens we have, get the ID numbers
$sSQL = 'select word_id,word_token, word, class, type, country_code, operator, search_name_count';
$sSQL .= ' from word where word_token in ('.join(',',array_map("getDBQuoted",$aTokens)).')';
// $sSQL .= ' and search_name_count < '.CONST_Max_Word_Frequency;
// $sSQL .= ' group by word_token, word, class, type, country_code';
//$sSQL .= ' and search_name_count < '.CONST_Max_Word_Frequency;
//$sSQL .= ' group by word_token, word, class, type, country_code';
if (CONST_Debug) var_Dump($sSQL);
$aValidTokens = array();
if (sizeof($aTokens))
$aDatabaseWords = $oDB->getAll($sSQL);
else
$aDatabaseWords = array();
if (sizeof($aTokens)) $aDatabaseWords = $oDB->getAll($sSQL);
else $aDatabaseWords = array();
if (PEAR::IsError($aDatabaseWords))
{
failInternalError("Could not get word tokens.", $sSQL, $aDatabaseWords);
@@ -524,14 +533,14 @@
// Add all words from this wordset
foreach($aWordset as $iToken => $sToken)
{
//echo "<br><b>$sToken</b>";
//echo "<br><b>$sToken</b>";
$aNewWordsetSearches = array();
foreach($aWordsetSearches as $aCurrentSearch)
{
//echo "<i>";
//var_dump($aCurrentSearch);
//echo "</i>";
//echo "<i>";
//var_dump($aCurrentSearch);
//echo "</i>";
// If the token is valid
if (isset($aValidTokens[' '.$sToken]))
@@ -571,12 +580,12 @@
{
$aSearch['sHouseNumber'] = $sToken;
if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch;
/*
/*
// Fall back to not searching for this item (better than nothing)
$aSearch = $aCurrentSearch;
$aSearch['iSearchRank'] += 1;
if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch;
*/
*/
}
}
elseif ($sPhraseType == '' && $aSearchTerm['class'] !== '' && $aSearchTerm['class'] !== null)
@@ -621,7 +630,7 @@
else
{
$aSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
// $aSearch['iNamePhrase'] = $iPhrase;
//$aSearch['iNamePhrase'] = $iPhrase;
}
if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch;
}
@@ -692,7 +701,7 @@
usort($aNewWordsetSearches, 'bySearchRank');
$aWordsetSearches = array_slice($aNewWordsetSearches, 0, 50);
}
// var_Dump('<hr>',sizeof($aWordsetSearches)); exit;
//var_Dump('<hr>',sizeof($aWordsetSearches)); exit;
$aNewPhraseSearches = array_merge($aNewPhraseSearches, $aNewWordsetSearches);
usort($aNewPhraseSearches, 'bySearchRank');
@@ -701,14 +710,8 @@
foreach($aNewPhraseSearches as $iSearch => $aSearch)
{
$sHash = serialize($aSearch);
if (isset($aSearchHash[$sHash]))
{
unset($aNewPhraseSearches[$iSearch]);
}
else
{
$aSearchHash[$sHash] = 1;
}
if (isset($aSearchHash[$sHash])) unset($aNewPhraseSearches[$iSearch]);
else $aSearchHash[$sHash] = 1;
}
$aNewPhraseSearches = array_slice($aNewPhraseSearches, 0, 50);
@@ -735,7 +738,7 @@
if ($iSearchCount > 50) break;
}
// if (CONST_Debug) _debugDumpGroupedSearches($aGroupedSearches, $aValidTokens);
//if (CONST_Debug) _debugDumpGroupedSearches($aGroupedSearches, $aValidTokens);
}
}
@@ -772,8 +775,8 @@
$aSearch['aName'] = array($iReverseItem);
$aGroupedSearches[$iGroup][] = $aSearch;
}
// $aReverseSearch['aName'][$iReverseItem] = $iReverseItem;
// $aGroupedSearches[$iGroup][] = $aReverseSearch;
//$aReverseSearch['aName'][$iReverseItem] = $iReverseItem;
//$aGroupedSearches[$iGroup][] = $aReverseSearch;
}
}
}
@@ -963,7 +966,6 @@
if (sizeof($aSearch['aFullNameAddress']))
$aOrder[] = '(select count(*) from (select unnest(ARRAY['.join($aSearch['aFullNameAddress'],",").']) INTERSECT select unnest(nameaddress_vector))s) DESC';
if (sizeof($aTerms))
{
$sSQL = "select place_id";
@@ -983,21 +985,21 @@
{
failInternalError("Could not get places for search terms.", $sSQL, $aViewBoxPlaceIDs);
}
//var_dump($aViewBoxPlaceIDs);
//var_dump($aViewBoxPlaceIDs);
// Did we have an viewbox matches?
$aPlaceIDs = array();
$bViewBoxMatch = false;
foreach($aViewBoxPlaceIDs as $aViewBoxRow)
{
// if ($bViewBoxMatch == 1 && $aViewBoxRow['in_small'] == 'f') break;
// if ($bViewBoxMatch == 2 && $aViewBoxRow['in_large'] == 'f') break;
// if ($aViewBoxRow['in_small'] == 't') $bViewBoxMatch = 1;
// else if ($aViewBoxRow['in_large'] == 't') $bViewBoxMatch = 2;
//if ($bViewBoxMatch == 1 && $aViewBoxRow['in_small'] == 'f') break;
//if ($bViewBoxMatch == 2 && $aViewBoxRow['in_large'] == 'f') break;
//if ($aViewBoxRow['in_small'] == 't') $bViewBoxMatch = 1;
//else if ($aViewBoxRow['in_large'] == 't') $bViewBoxMatch = 2;
$aPlaceIDs[] = $aViewBoxRow['place_id'];
}
}
//var_Dump($aPlaceIDs);
//exit;
//var_Dump($aPlaceIDs);
//exit;
if ($aSearch['sHouseNumber'] && sizeof($aPlaceIDs))
{
@@ -1023,7 +1025,7 @@
{
$sSQL .= " and place_id not in (".join(',',$aExcludePlaceIDs).")";
}
// $sSQL .= " limit $iLimit";
//$sSQL .= " limit $iLimit";
if (CONST_Debug) var_dump($sSQL);
$aPlaceIDs = $oDB->getCol($sSQL);
}
@@ -1035,7 +1037,7 @@
{
$sSQL .= " and place_id not in (".join(',',$aExcludePlaceIDs).")";
}
// $sSQL .= " limit $iLimit";
//$sSQL .= " limit $iLimit";
if (CONST_Debug) var_dump($sSQL);
$aPlaceIDs = $oDB->getCol($sSQL);
}
@@ -1051,7 +1053,6 @@
if ($aSearch['sClass'] && sizeof($aPlaceIDs))
{
$sPlaceIDs = join(',',$aPlaceIDs);
$aClassPlaceIDs = array();
if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'name')
@@ -1189,7 +1190,7 @@
// Did we find anything?
if (isset($aResultPlaceIDs) && sizeof($aResultPlaceIDs))
{
//var_Dump($aResultPlaceIDs);exit;
//var_Dump($aResultPlaceIDs);exit;
// Get the details for display (is this a redundant extra step?)
$sPlaceIDs = join(',',$aResultPlaceIDs);
$sOrderSQL = 'CASE ';
@@ -1203,7 +1204,7 @@
$sSQL .= "get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
// $sSQL .= $sOrderSQL." as porder, ";
//$sSQL .= $sOrderSQL." as porder, ";
$sSQL .= "coalesce(importance,0.75-(rank_search::float/40)) as importance, ";
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(placex.place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
$sSQL .= "(extratags->'place') as extra_place ";
@@ -1225,7 +1226,7 @@
$sSQL .= "null as placename,";
$sSQL .= "null as ref,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
// $sSQL .= $sOrderSQL." as porder, ";
//$sSQL .= $sOrderSQL." as porder, ";
$sSQL .= "-0.15 as importance, ";
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_tiger.place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
$sSQL .= "null as extra_place ";
@@ -1239,7 +1240,7 @@
$sSQL .= "null as placename,";
$sSQL .= "null as ref,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
// $sSQL .= $sOrderSQL." as porder, ";
//$sSQL .= $sOrderSQL." as porder, ";
$sSQL .= "-0.10 as importance, ";
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_aux.place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
$sSQL .= "null as extra_place ";
@@ -1249,10 +1250,10 @@
if (!$bDeDupe) $sSQL .= ",place_id";
$sSQL .= ",get_address_by_language(place_id, $sLanguagePrefArraySQL) ";
$sSQL .= "order by importance desc";
// $sSQL .= "order by rank_search,rank_address,porder asc";
//$sSQL .= "order by rank_search,rank_address,porder asc";
if (CONST_Debug) { echo "<hr>"; var_dump($sSQL); }
$aSearchResults = $oDB->getAll($sSQL);
//var_dump($sSQL,$aSearchResults);exit;
//var_dump($sSQL,$aSearchResults);exit;
if (PEAR::IsError($aSearchResults))
{
@@ -1282,7 +1283,7 @@
$sSQL .= "get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
// $sSQL .= $sOrderSQL." as porder, ";
//$sSQL .= $sOrderSQL." as porder, ";
$sSQL .= "coalesce(importance,0.75-(rank_search::float/40)) as importance, ";
$sSQL .= "(extratags->'place') as extra_place ";
$sSQL .= "from placex where place_id in ($sPlaceIDs) ";
@@ -1301,7 +1302,7 @@
$sSQL .= "null as placename,";
$sSQL .= "null as ref,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
// $sSQL .= $sOrderSQL." as porder, ";
//$sSQL .= $sOrderSQL." as porder, ";
$sSQL .= "-0.15 as importance, ";
$sSQL .= "null as extra_place ";
$sSQL .= "from location_property_tiger where place_id in ($sPlaceIDs) ";
@@ -1314,7 +1315,7 @@
$sSQL .= "null as placename,";
$sSQL .= "null as ref,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
// $sSQL .= $sOrderSQL." as porder, ";
//$sSQL .= $sOrderSQL." as porder, ";
$sSQL .= "-0.10 as importance, ";
$sSQL .= "null as extra_place ";
$sSQL .= "from location_property_aux where place_id in ($sPlaceIDs) ";
@@ -1323,10 +1324,10 @@
if (!$bDeDupe) $sSQL .= ",place_id";
$sSQL .= ",get_address_by_language(place_id, $sLanguagePrefArraySQL) ";
$sSQL .= "order by importance desc";
// $sSQL .= "order by rank_search,rank_address,porder asc";
//$sSQL .= "order by rank_search,rank_address,porder asc";
if (CONST_Debug) { echo "<hr>", var_dump($sSQL); }
$aSearchResults = $oDB->getAll($sSQL);
//var_dump($sSQL,$aSearchResults);exit;
//var_dump($sSQL,$aSearchResults);exit;
if (PEAR::IsError($aSearchResults))
{
@@ -1341,8 +1342,8 @@
{
$sSearchResult = 'No Results Found';
}
//var_Dump($aSearchResults);
//exit;
//var_Dump($aSearchResults);
//exit;
$aClassType = getClassTypesWithImportance();
$aRecheckWords = preg_split('/\b/u',$sQuery);
foreach($aRecheckWords as $i => $sWord)
@@ -1380,7 +1381,8 @@
if ($bAsSVG) $aResult['assvg'] = $aPointPolygon['assvg'];
if ($bAsText) $aResult['astext'] = $aPointPolygon['astext'];
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null ) {
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null )
{
$aResult['lat'] = $aPointPolygon['centrelat'];
$aResult['lon'] = $aPointPolygon['centrelon'];
}
@@ -1494,8 +1496,8 @@
$aResult['address'] = array_merge(array('city' => array_shift(array_values($aResult['address']))), $aResult['address']);
}
//var_dump($aResult['address']);
//exit;
//var_dump($aResult['address']);
//exit;
}
// Adjust importance for the number of exact string matches in the result
@@ -1509,8 +1511,8 @@
$aResult['importance'] = $aResult['importance'] + ($iCountWords*0.1); // 0.1 is a completely arbitrary number but something in the range 0.1 to 0.5 would seem right
//if (CONST_Debug) var_dump($aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']);
/*
//if (CONST_Debug) var_dump($aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']);
/*
if (isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['importance'])
&& $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['importance'])
{
@@ -1525,7 +1527,7 @@
{
$aResult['importance'] = 1000000000000000;
}
*/
*/
$aResult['name'] = $aResult['langaddress'];
$aResult['foundorder'] = -$aResult['addressimportance'];
$aSearchResults[$iResNum] = $aResult;