<?php
+ @define('CONST_ConnectionBucket_PageType', 'Search');
+
require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
require_once(CONST_BasePath.'/lib/log.php');
ini_set('memory_limit', '200M');
+
$oDB =& getDB();
// Display defaults
$iOffset = isset($_GET['offset'])?(int)$_GET['offset']:0;
$iMaxRank = 20;
if ($iFinalLimit > 50) $iFinalLimit = 50;
- $iLimit = $iFinalLimit + min($iFinalLimit, 10);
+ $iLimit = $iFinalLimit + min($iFinalLimit, 10);
$iMinAddressRank = 0;
$iMaxAddressRank = 30;
+ $sAllowedTypesSQLList = false;
// Format for output
if (isset($_GET['format']) && ($_GET['format'] == 'html' || $_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
if (isset($aLangPrefOrder['name:de'])) $bReverseInPlan = true;
if (isset($aLangPrefOrder['name:ru'])) $bReverseInPlan = true;
if (isset($aLangPrefOrder['name:ja'])) $bReverseInPlan = true;
+ if (isset($aLangPrefOrder['name:pl'])) $bReverseInPlan = true;
$sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
array('postalcode', 16, 25),
);
$aStructuredQuery = array();
+ $sAllowedTypesSQLList = '';
foreach($aStructuredOptions as $aStructuredOption)
{
loadStructuredAddressElement($aStructuredQuery, $iMinAddressRank, $iMaxAddressRank, $_GET, $aStructuredOption[0], $aStructuredOption[1], $aStructuredOption[2]);
}
if (sizeof($aStructuredQuery) > 0) {
$sQuery = join(', ', $aStructuredQuery);
+ $sAllowedTypesSQLList = '(\'place\',\'boundary\')';
}
if ($sQuery)
}
}
+ if (CONST_Search_TryDroppedAddressTerms && sizeof($aStructuredQuery) > 0)
+ {
+ $aCopyGroupedSearches = $aGroupedSearches;
+ foreach($aCopyGroupedSearches as $iGroup => $aSearches)
+ {
+ foreach($aSearches as $iSearch => $aSearch)
+ {
+ $aReductionsList = array($aSearch['aAddress']);
+ $iSearchRank = $aSearch['iSearchRank'];
+ while(sizeof($aReductionsList) > 0)
+ {
+ $iSearchRank += 5;
+ if ($iSearchRank > iMaxRank) break 3;
+ $aNewReductionsList = array();
+ foreach($aReductionsList as $aReductionsWordList)
+ {
+ for ($iReductionWord = 0; $iReductionWord < sizeof($aReductionsWordList); $iReductionWord++)
+ {
+ $aReductionsWordListResult = array_merge(array_slice($aReductionsWordList, 0, $iReductionWord), array_slice($aReductionsWordList, $iReductionWord+1));
+ $aReverseSearch = $aSearch;
+ $aSearch['aAddress'] = $aReductionsWordListResult;
+ $aSearch['iSearchRank'] = $iSearchRank;
+ $aGroupedSearches[$iSearchRank][] = $aReverseSearch;
+ if (sizeof($aReductionsWordListResult) > 0)
+ {
+ $aNewReductionsList[] = $aReductionsWordListResult;
+ }
+ }
+ }
+ $aReductionsList = $aNewReductionsList;
+ }
+ }
+ }
+ ksort($aGroupedSearches);
+ }
+
// Filter out duplicate searches
$aSearchHash = array();
foreach($aGroupedSearches as $iGroup => $aSearches)
// Must have a location term
if (!sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['fLon'])
{
- if ($aSearch['sCountryCode'] && !$aSearch['sClass'])
+ if ($aSearch['sCountryCode'] && !$aSearch['sClass'] && !$aSearch['sHouseNumber'])
{
if (4 >= $iMinAddressRank && 4 <= $iMaxAddressRank)
{
if ($bBoundingBoxSearch) $aTerms[] = "centroid && $sViewboxSmallSQL";
if ($sNearPointSQL) $aOrder[] = "ST_Distance($sNearPointSQL, centroid) asc";
- $sImportanceSQL = 'case when importance = 0 OR importance IS NULL then 0.92-(search_rank::float/33) else importance end';
+ $sImportanceSQL = 'case when importance = 0 OR importance IS NULL then 0.75-(search_rank::float/40) else importance end';
if ($sViewboxSmallSQL) $sImportanceSQL .= " * case when ST_Contains($sViewboxSmallSQL, centroid) THEN 1 ELSE 0.5 END";
if ($sViewboxLargeSQL) $sImportanceSQL .= " * case when ST_Contains($sViewboxLargeSQL, centroid) THEN 1 ELSE 0.5 END";
else
$sSQL .= " limit ".$iLimit;
- if (CONST_Debug) { var_dump($sSQL); }
+ if (CONST_Debug) var_dump($sSQL);
+ $iStartTime = time();
$aViewBoxPlaceIDs = $oDB->getAll($sSQL);
if (PEAR::IsError($aViewBoxPlaceIDs))
{
failInternalError("Could not get places for search terms.", $sSQL, $aViewBoxPlaceIDs);
}
+ if (time() - $iStartTime > 60) {
+ file_put_contents(CONST_BasePath.'/log/long_queries.log', date('Y-m-d H:i:s', $iStartTime).' '.$sSQL."\n", FILE_APPEND);
+ }
+
//var_dump($aViewBoxPlaceIDs);
// Did we have an viewbox matches?
$aPlaceIDs = array();
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
$sSQL .= "avg(ST_X(ST_Centroid(geometry))) as lon,avg(ST_Y(ST_Centroid(geometry))) as lat, ";
// $sSQL .= $sOrderSQL." as porder, ";
- $sSQL .= "coalesce(importance,0.9-(rank_search::float/30)) as importance ";
+ $sSQL .= "coalesce(importance,0.75-(rank_search::float/40)) as importance ";
$sSQL .= "from placex where place_id in ($sPlaceIDs) ";
$sSQL .= "and placex.rank_address between $iMinAddressRank and $iMaxAddressRank ";
+ if ($sAllowedTypesSQLList) $sSQL .= "and placex.class in $sAllowedTypesSQLList ";
$sSQL .= "and linked_place_id is null ";
$sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,country_code,importance";
if (!$bDeDupe) $sSQL .= ",place_id";
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
$sSQL .= "avg(ST_X(ST_Centroid(geometry))) as lon,avg(ST_Y(ST_Centroid(geometry))) as lat, ";
// $sSQL .= $sOrderSQL." as porder, ";
- $sSQL .= "coalesce(importance,0.9-(rank_search::float/30)) as importance ";
+ $sSQL .= "coalesce(importance,0.75-(rank_search::float/40)) as importance ";
$sSQL .= "from placex where place_id in ($sPlaceIDs) ";
$sSQL .= "and placex.rank_address between $iMinAddressRank and $iMaxAddressRank ";
$sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,country_code,importance";
}
uasort($aSearchResults, 'byImportance');
-//var_dump($aSearchResults);exit;
-
$aOSMIDDone = array();
$aClassTypeNameDone = array();
$aToFilter = $aSearchResults;
logEnd($oDB, $hLog, sizeof($aToFilter));
}
$sMoreURL = CONST_Website_BaseURL.'search?format='.urlencode($sOutputFormat).'&exclude_place_ids='.join(',',$aExcludePlaceIDs);
- $sMoreURL .= '&accept-language='.$_SERVER["HTTP_ACCEPT_LANGUAGE"];
+ if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) $sMoreURL .= '&accept-language='.$_SERVER["HTTP_ACCEPT_LANGUAGE"];
if ($bShowPolygons) $sMoreURL .= '&polygon=1';
if ($bShowAddressDetails) $sMoreURL .= '&addressdetails=1';
if (isset($_GET['viewbox']) && $_GET['viewbox']) $sMoreURL .= '&viewbox='.urlencode($_GET['viewbox']);