mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-12 22:04:07 +00:00
move country list to SearchContext
This commit is contained in:
@@ -852,15 +852,14 @@ class Geocode
|
|||||||
if ($this->aExcludePlaceIDs) {
|
if ($this->aExcludePlaceIDs) {
|
||||||
$oCtx->setExcludeList($this->aExcludePlaceIDs);
|
$oCtx->setExcludeList($this->aExcludePlaceIDs);
|
||||||
}
|
}
|
||||||
|
if ($this->aCountryCodes) {
|
||||||
|
$oCtx->setCountryList($this->aCountryCodes);
|
||||||
|
}
|
||||||
|
|
||||||
$sNormQuery = $this->normTerm($this->sQuery);
|
$sNormQuery = $this->normTerm($this->sQuery);
|
||||||
$sLanguagePrefArraySQL = getArraySQL(
|
$sLanguagePrefArraySQL = getArraySQL(
|
||||||
array_map("getDBQuoted", $this->aLangPrefOrder)
|
array_map("getDBQuoted", $this->aLangPrefOrder)
|
||||||
);
|
);
|
||||||
$sCountryCodesSQL = false;
|
|
||||||
if ($this->aCountryCodes) {
|
|
||||||
$sCountryCodesSQL = join(',', array_map('addQuotes', $this->aCountryCodes));
|
|
||||||
}
|
|
||||||
|
|
||||||
$sQuery = $this->sQuery;
|
$sQuery = $this->sQuery;
|
||||||
if (!preg_match('//u', $sQuery)) {
|
if (!preg_match('//u', $sQuery)) {
|
||||||
@@ -1107,25 +1106,16 @@ class Geocode
|
|||||||
if (!$oCtx->isBoundedSearch()) {
|
if (!$oCtx->isBoundedSearch()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$aPlaceIDs = $oSearch->queryNearbyPoi($this->oDB, $this->iLimit);
|
||||||
$aPlaceIDs = $oSearch->queryNearbyPoi(
|
|
||||||
$this->oDB,
|
|
||||||
$sCountryCodesSQL,
|
|
||||||
$this->iLimit
|
|
||||||
);
|
|
||||||
} elseif ($oSearch->isOperator(Operator::POSTCODE)) {
|
} elseif ($oSearch->isOperator(Operator::POSTCODE)) {
|
||||||
$aPlaceIDs = $oSearch->queryPostcode(
|
// looking for postcode
|
||||||
$this->oDB,
|
$aPlaceIDs = $oSearch->queryPostcode($this->oDB, $this->iLimit);
|
||||||
$sCountryCodesSQL,
|
|
||||||
$this->iLimit
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Ordinary search:
|
// Ordinary search:
|
||||||
// First search for places according to name and address.
|
// First search for places according to name and address.
|
||||||
$aNamedPlaceIDs = $oSearch->queryNamedPlace(
|
$aNamedPlaceIDs = $oSearch->queryNamedPlace(
|
||||||
$this->oDB,
|
$this->oDB,
|
||||||
$aWordFrequencyScores,
|
$aWordFrequencyScores,
|
||||||
$sCountryCodesSQL,
|
|
||||||
$this->iMinAddressRank,
|
$this->iMinAddressRank,
|
||||||
$this->iMaxAddressRank,
|
$this->iMaxAddressRank,
|
||||||
$this->iLimit
|
$this->iLimit
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class SearchContext
|
|||||||
public $sqlViewboxSmall = '';
|
public $sqlViewboxSmall = '';
|
||||||
public $sqlViewboxLarge = '';
|
public $sqlViewboxLarge = '';
|
||||||
public $sqlViewboxCentre = '';
|
public $sqlViewboxCentre = '';
|
||||||
|
public $sqlCountryList = '';
|
||||||
private $sqlExcludeList = '';
|
private $sqlExcludeList = '';
|
||||||
|
|
||||||
public function hasNearPoint()
|
public function hasNearPoint()
|
||||||
@@ -97,6 +98,11 @@ class SearchContext
|
|||||||
$this->sqlExcludeList = ' not in ('.join(',', $aExcluded).')';
|
$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.
|
* Extract a coordinate point from a query string.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -109,13 +109,13 @@ class SearchDescription
|
|||||||
return 'place_classtype_'.$this->sClass.'_'.$this->sType;
|
return 'place_classtype_'.$this->sClass.'_'.$this->sType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function countryCodeSQL($sVar, $sCountryList)
|
public function countryCodeSQL($sVar)
|
||||||
{
|
{
|
||||||
if ($this->sCountryCode) {
|
if ($this->sCountryCode) {
|
||||||
return $sVar.' = \''.$this->sCountryCode."'";
|
return $sVar.' = \''.$this->sCountryCode."'";
|
||||||
}
|
}
|
||||||
if ($sCountryList) {
|
if ($this->oContext->sqlCountryList) {
|
||||||
return $sVar.' in ('.$sCountryList.')';
|
return $sVar.' in '.$this->oContext->sqlCountryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
@@ -382,7 +382,7 @@ class SearchDescription
|
|||||||
return chksql($oDB->getCol($sSQL));
|
return chksql($oDB->getCol($sSQL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function queryNearbyPoi(&$oDB, $sCountryList, $iLimit)
|
public function queryNearbyPoi(&$oDB, $iLimit)
|
||||||
{
|
{
|
||||||
if (!$this->sClass) {
|
if (!$this->sClass) {
|
||||||
return array();
|
return array();
|
||||||
@@ -393,7 +393,7 @@ class SearchDescription
|
|||||||
$sSQL = 'SELECT count(*) FROM pg_tables WHERE tablename = \''.$sPoiTable."'";
|
$sSQL = 'SELECT count(*) FROM pg_tables WHERE tablename = \''.$sPoiTable."'";
|
||||||
if (chksql($oDB->getOne($sSQL))) {
|
if (chksql($oDB->getOne($sSQL))) {
|
||||||
$sSQL = 'SELECT place_id FROM '.$sPoiTable.' ct';
|
$sSQL = 'SELECT place_id FROM '.$sPoiTable.' ct';
|
||||||
if ($sCountryList) {
|
if ($this->oContext->sqlCountryList) {
|
||||||
$sSQL .= ' JOIN placex USING (place_id)';
|
$sSQL .= ' JOIN placex USING (place_id)';
|
||||||
}
|
}
|
||||||
if ($this->oContext->hasNearPoint()) {
|
if ($this->oContext->hasNearPoint()) {
|
||||||
@@ -401,8 +401,8 @@ class SearchDescription
|
|||||||
} else if ($this->oContext->bViewboxBounded) {
|
} else if ($this->oContext->bViewboxBounded) {
|
||||||
$sSQL .= ' WHERE ST_Contains('.$this->oContext->sqlViewboxSmall.', ct.centroid)';
|
$sSQL .= ' WHERE ST_Contains('.$this->oContext->sqlViewboxSmall.', ct.centroid)';
|
||||||
}
|
}
|
||||||
if ($sCountryList) {
|
if ($this->oContext->sqlCountryList) {
|
||||||
$sSQL .= " AND country_code in ($sCountryList)";
|
$sSQL .= ' AND country_code in '.$this->oContext->sqlCountryList;
|
||||||
}
|
}
|
||||||
$sSQL .= $this->oContext->excludeSQL(' AND place_id');
|
$sSQL .= $this->oContext->excludeSQL(' AND place_id');
|
||||||
if ($this->oContext->sqlViewboxCentre) {
|
if ($this->oContext->sqlViewboxCentre) {
|
||||||
@@ -421,8 +421,8 @@ class SearchDescription
|
|||||||
$sSQL .= 'class=\''.$this->sClass."' and type='".$this->sType."'";
|
$sSQL .= 'class=\''.$this->sClass."' and type='".$this->sType."'";
|
||||||
$sSQL .= ' AND '.$this->oContext->withinSQL('geometry');
|
$sSQL .= ' AND '.$this->oContext->withinSQL('geometry');
|
||||||
$sSQL .= ' AND linked_place_id is null';
|
$sSQL .= ' AND linked_place_id is null';
|
||||||
if ($sCountryList) {
|
if ($this->oContext->sqlCountryList) {
|
||||||
$sSQL .= " AND country_code in ($sCountryList)";
|
$sSQL .= ' AND country_code in '.$this->oContext->sqlCountryList;
|
||||||
}
|
}
|
||||||
$sSQL .= ' ORDER BY '.$this->oContext->distanceSQL('centroid')." ASC";
|
$sSQL .= ' ORDER BY '.$this->oContext->distanceSQL('centroid')." ASC";
|
||||||
$sSQL .= " LIMIT $iLimit";
|
$sSQL .= " LIMIT $iLimit";
|
||||||
@@ -433,7 +433,7 @@ class SearchDescription
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function queryPostcode(&$oDB, $sCountryList, $iLimit)
|
public function queryPostcode(&$oDB, $iLimit)
|
||||||
{
|
{
|
||||||
$sSQL = 'SELECT p.place_id FROM location_postcode p ';
|
$sSQL = 'SELECT p.place_id FROM location_postcode p ';
|
||||||
|
|
||||||
@@ -447,10 +447,7 @@ class SearchDescription
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sSQL .= "p.postcode = '".reset($this->aName)."'";
|
$sSQL .= "p.postcode = '".reset($this->aName)."'";
|
||||||
$sCountryTerm = $this->countryCodeSQL('p.country_code', $sCountryList);
|
$sSQL .= $this->countryCodeSQL(' AND p.country_code');
|
||||||
if ($sCountryTerm) {
|
|
||||||
$sSQL .= ' AND '.$sCountryTerm;
|
|
||||||
}
|
|
||||||
$sSQL .= $this->oContext->excludeSQL(' AND p.place_id');
|
$sSQL .= $this->oContext->excludeSQL(' AND p.place_id');
|
||||||
$sSQL .= " LIMIT $iLimit";
|
$sSQL .= " LIMIT $iLimit";
|
||||||
|
|
||||||
@@ -459,7 +456,7 @@ class SearchDescription
|
|||||||
return chksql($oDB->getCol($sSQL));
|
return chksql($oDB->getCol($sSQL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function queryNamedPlace(&$oDB, $aWordFrequencyScores, $sCountryList, $iMinAddressRank, $iMaxAddressRank, $iLimit)
|
public function queryNamedPlace(&$oDB, $aWordFrequencyScores, $iMinAddressRank, $iMaxAddressRank, $iLimit)
|
||||||
{
|
{
|
||||||
$aTerms = array();
|
$aTerms = array();
|
||||||
$aOrder = array();
|
$aOrder = array();
|
||||||
@@ -506,7 +503,7 @@ class SearchDescription
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sCountryTerm = $this->countryCodeSQL('country_code', $sCountryList);
|
$sCountryTerm = $this->countryCodeSQL('country_code');
|
||||||
if ($sCountryTerm) {
|
if ($sCountryTerm) {
|
||||||
$aTerms[] = $sCountryTerm;
|
$aTerms[] = $sCountryTerm;
|
||||||
}
|
}
|
||||||
@@ -589,7 +586,6 @@ class SearchDescription
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function queryHouseNumber(&$oDB, $aRoadPlaceIDs, $iLimit)
|
public function queryHouseNumber(&$oDB, $aRoadPlaceIDs, $iLimit)
|
||||||
{
|
{
|
||||||
$sPlaceIDs = join(',', $aRoadPlaceIDs);
|
$sPlaceIDs = join(',', $aRoadPlaceIDs);
|
||||||
|
|||||||
Reference in New Issue
Block a user