<?php
+ @define('CONST_ConnectionBucket_PageType', 'Search');
+
require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
require_once(CONST_BasePath.'/lib/log.php');
$sSuggestion = $sSuggestionURL = false;
$bDeDupe = isset($_GET['dedupe'])?(bool)$_GET['dedupe']:true;
$bReverseInPlan = false;
- $iLimit = isset($_GET['limit'])?(int)$_GET['limit']:10;
+ $iFinalLimit = isset($_GET['limit'])?(int)$_GET['limit']:10;
$iOffset = isset($_GET['offset'])?(int)$_GET['offset']:0;
$iMaxRank = 20;
- if ($iLimit > 100) $iLimit = 100;
+ if ($iFinalLimit > 50) $iFinalLimit = 50;
+ $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'))
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)
{
else
$sSQL .= " limit ".$iLimit;
- if (CONST_Debug) var_dump($sSQL);
+ if (CONST_Debug) { var_dump($sSQL); }
$aViewBoxPlaceIDs = $oDB->getAll($sSQL);
if (PEAR::IsError($aViewBoxPlaceIDs))
{
$sSQL .= "coalesce(importance,0.9-(rank_search::float/30)) 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";
}
// Absolute limit on number of results
- if (sizeof($aSearchResults) >= $iLimit) break;
+ if (sizeof($aSearchResults) >= $iFinalLimit) break;
}
$sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '1 day'::interval,'YYYY/MM/DD') from import_status limit 1");