if ($this->aExcludePlaceIDs) {
$oCtx->setExcludeList($this->aExcludePlaceIDs);
}
+ if ($this->aCountryCodes) {
+ $oCtx->setCountryList($this->aCountryCodes);
+ }
$sNormQuery = $this->normTerm($this->sQuery);
$sLanguagePrefArraySQL = getArraySQL(
array_map("getDBQuoted", $this->aLangPrefOrder)
);
- $sCountryCodesSQL = false;
- if ($this->aCountryCodes) {
- $sCountryCodesSQL = join(',', array_map('addQuotes', $this->aCountryCodes));
- }
$sQuery = $this->sQuery;
if (!preg_match('//u', $sQuery)) {
if (!$oCtx->isBoundedSearch()) {
continue;
}
-
- $aPlaceIDs = $oSearch->queryNearbyPoi(
- $this->oDB,
- $sCountryCodesSQL,
- $this->iLimit
- );
+ $aPlaceIDs = $oSearch->queryNearbyPoi($this->oDB, $this->iLimit);
} elseif ($oSearch->isOperator(Operator::POSTCODE)) {
- $aPlaceIDs = $oSearch->queryPostcode(
- $this->oDB,
- $sCountryCodesSQL,
- $this->iLimit
- );
+ // looking for postcode
+ $aPlaceIDs = $oSearch->queryPostcode($this->oDB, $this->iLimit);
} else {
// Ordinary search:
// First search for places according to name and address.
$aNamedPlaceIDs = $oSearch->queryNamedPlace(
$this->oDB,
$aWordFrequencyScores,
- $sCountryCodesSQL,
$this->iMinAddressRank,
$this->iMaxAddressRank,
$this->iLimit
public $sqlViewboxSmall = '';
public $sqlViewboxLarge = '';
public $sqlViewboxCentre = '';
+ public $sqlCountryList = '';
private $sqlExcludeList = '';
public function hasNearPoint()
$this->sqlExcludeList = ' not in ('.join(',', $aExcluded).')';
}
+ public function setCountryList($aCountries)
+ {
+ $this->sqlCountryList = '('.join(',', array_map('addQuotes', $aCountries)).')';
+ }
+
/**
* Extract a coordinate point from a query string.
*
return 'place_classtype_'.$this->sClass.'_'.$this->sType;
}
- public function countryCodeSQL($sVar, $sCountryList)
+ public function countryCodeSQL($sVar)
{
if ($this->sCountryCode) {
return $sVar.' = \''.$this->sCountryCode."'";
}
- if ($sCountryList) {
- return $sVar.' in ('.$sCountryList.')';
+ if ($this->oContext->sqlCountryList) {
+ return $sVar.' in '.$this->oContext->sqlCountryList;
}
return '';
return chksql($oDB->getCol($sSQL));
}
- public function queryNearbyPoi(&$oDB, $sCountryList, $iLimit)
+ public function queryNearbyPoi(&$oDB, $iLimit)
{
if (!$this->sClass) {
return array();
$sSQL = 'SELECT count(*) FROM pg_tables WHERE tablename = \''.$sPoiTable."'";
if (chksql($oDB->getOne($sSQL))) {
$sSQL = 'SELECT place_id FROM '.$sPoiTable.' ct';
- if ($sCountryList) {
+ if ($this->oContext->sqlCountryList) {
$sSQL .= ' JOIN placex USING (place_id)';
}
if ($this->oContext->hasNearPoint()) {
} else if ($this->oContext->bViewboxBounded) {
$sSQL .= ' WHERE ST_Contains('.$this->oContext->sqlViewboxSmall.', ct.centroid)';
}
- if ($sCountryList) {
- $sSQL .= " AND country_code in ($sCountryList)";
+ if ($this->oContext->sqlCountryList) {
+ $sSQL .= ' AND country_code in '.$this->oContext->sqlCountryList;
}
$sSQL .= $this->oContext->excludeSQL(' AND place_id');
if ($this->oContext->sqlViewboxCentre) {
$sSQL .= 'class=\''.$this->sClass."' and type='".$this->sType."'";
$sSQL .= ' AND '.$this->oContext->withinSQL('geometry');
$sSQL .= ' AND linked_place_id is null';
- if ($sCountryList) {
- $sSQL .= " AND country_code in ($sCountryList)";
+ if ($this->oContext->sqlCountryList) {
+ $sSQL .= ' AND country_code in '.$this->oContext->sqlCountryList;
}
$sSQL .= ' ORDER BY '.$this->oContext->distanceSQL('centroid')." ASC";
$sSQL .= " LIMIT $iLimit";
return array();
}
- public function queryPostcode(&$oDB, $sCountryList, $iLimit)
+ public function queryPostcode(&$oDB, $iLimit)
{
$sSQL = 'SELECT p.place_id FROM location_postcode p ';
}
$sSQL .= "p.postcode = '".reset($this->aName)."'";
- $sCountryTerm = $this->countryCodeSQL('p.country_code', $sCountryList);
- if ($sCountryTerm) {
- $sSQL .= ' AND '.$sCountryTerm;
- }
+ $sSQL .= $this->countryCodeSQL(' AND p.country_code');
$sSQL .= $this->oContext->excludeSQL(' AND p.place_id');
$sSQL .= " LIMIT $iLimit";
return chksql($oDB->getCol($sSQL));
}
- public function queryNamedPlace(&$oDB, $aWordFrequencyScores, $sCountryList, $iMinAddressRank, $iMaxAddressRank, $iLimit)
+ public function queryNamedPlace(&$oDB, $aWordFrequencyScores, $iMinAddressRank, $iMaxAddressRank, $iLimit)
{
$aTerms = array();
$aOrder = array();
}
}
- $sCountryTerm = $this->countryCodeSQL('country_code', $sCountryList);
+ $sCountryTerm = $this->countryCodeSQL('country_code');
if ($sCountryTerm) {
$aTerms[] = $sCountryTerm;
}
return array();
}
-
public function queryHouseNumber(&$oDB, $aRoadPlaceIDs, $iLimit)
{
$sPlaceIDs = join(',', $aRoadPlaceIDs);