move excluded place list to SearchContext

This commit is contained in:
Sarah Hoffmann
2017-10-08 23:15:06 +02:00
parent 86c0858130
commit 907133a38c
3 changed files with 33 additions and 32 deletions

View File

@@ -849,6 +849,9 @@ class Geocode
} else if ($this->aViewBox) { } else if ($this->aViewBox) {
$oCtx->setViewboxFromBox($this->aViewBox, $this->bBoundedSearch); $oCtx->setViewboxFromBox($this->aViewBox, $this->bBoundedSearch);
} }
if ($this->aExcludePlaceIDs) {
$oCtx->setExcludeList($this->aExcludePlaceIDs);
}
$sNormQuery = $this->normTerm($this->sQuery); $sNormQuery = $this->normTerm($this->sQuery);
$sLanguagePrefArraySQL = getArraySQL( $sLanguagePrefArraySQL = getArraySQL(
@@ -1108,7 +1111,6 @@ class Geocode
$aPlaceIDs = $oSearch->queryNearbyPoi( $aPlaceIDs = $oSearch->queryNearbyPoi(
$this->oDB, $this->oDB,
$sCountryCodesSQL, $sCountryCodesSQL,
$this->aExcludePlaceIDs ? join(',', $this->aExcludePlaceIDs) : '',
$this->iLimit $this->iLimit
); );
} elseif ($oSearch->isOperator(Operator::POSTCODE)) { } elseif ($oSearch->isOperator(Operator::POSTCODE)) {
@@ -1126,7 +1128,6 @@ class Geocode
$sCountryCodesSQL, $sCountryCodesSQL,
$this->iMinAddressRank, $this->iMinAddressRank,
$this->iMaxAddressRank, $this->iMaxAddressRank,
$this->aExcludePlaceIDs ? join(',', $this->aExcludePlaceIDs) : '',
$this->iLimit $this->iLimit
); );
@@ -1142,7 +1143,6 @@ class Geocode
$aResult = $oSearch->queryHouseNumber( $aResult = $oSearch->queryHouseNumber(
$this->oDB, $this->oDB,
$aPlaceIDs, $aPlaceIDs,
$this->aExcludePlaceIDs ? join(',', $this->aExcludePlaceIDs) : '',
$this->iLimit $this->iLimit
); );
@@ -1159,7 +1159,6 @@ class Geocode
$aPlaceIDs = $oSearch->queryPoiByOperator( $aPlaceIDs = $oSearch->queryPoiByOperator(
$this->oDB, $this->oDB,
$aPlaceIDs, $aPlaceIDs,
$this->aExcludePlaceIDs ? join(',', $this->aExcludePlaceIDs) : '',
$this->iLimit $this->iLimit
); );
} }

View File

@@ -22,6 +22,7 @@ class SearchContext
public $sqlViewboxSmall = ''; public $sqlViewboxSmall = '';
public $sqlViewboxLarge = ''; public $sqlViewboxLarge = '';
public $sqlViewboxCentre = ''; public $sqlViewboxCentre = '';
private $sqlExcludeList = '';
public function hasNearPoint() public function hasNearPoint()
{ {
@@ -91,6 +92,11 @@ class SearchContext
$this->sqlViewboxLarge = "'".$sGeom."'::geometry"; $this->sqlViewboxLarge = "'".$sGeom."'::geometry";
} }
public function setExcludeList($aExcluded)
{
$this->sqlExcludeList = ' not in ('.join(',', $aExcluded).')';
}
/** /**
* Extract a coordinate point from a query string. * Extract a coordinate point from a query string.
* *
@@ -138,4 +144,13 @@ class SearchContext
return $sSQL; return $sSQL;
} }
public function excludeSQL($sVariable)
{
if ($this->sqlExcludeList) {
return $sVariable.$this->sqlExcludeList;
}
return '';
}
} }

View File

@@ -382,7 +382,7 @@ class SearchDescription
return chksql($oDB->getCol($sSQL)); return chksql($oDB->getCol($sSQL));
} }
public function queryNearbyPoi(&$oDB, $sCountryList, $sExcludeSQL, $iLimit) public function queryNearbyPoi(&$oDB, $sCountryList, $iLimit)
{ {
if (!$this->sClass) { if (!$this->sClass) {
return array(); return array();
@@ -404,9 +404,7 @@ class SearchDescription
if ($sCountryList) { if ($sCountryList) {
$sSQL .= " AND country_code in ($sCountryList)"; $sSQL .= " AND country_code in ($sCountryList)";
} }
if ($sExcludeSQL) { $sSQL .= $this->oContext->excludeSQL(' AND place_id');
$sSQL .= ' AND place_id not in ('.$sExcludeSQL.')';
}
if ($this->oContext->sqlViewboxCentre) { if ($this->oContext->sqlViewboxCentre) {
$sSQL .= ' ORDER BY ST_Distance('; $sSQL .= ' ORDER BY ST_Distance(';
$sSQL .= $this->oContext->sqlViewboxCentre.', ct.centroid) ASC'; $sSQL .= $this->oContext->sqlViewboxCentre.', ct.centroid) ASC';
@@ -453,6 +451,7 @@ class SearchDescription
if ($sCountryTerm) { if ($sCountryTerm) {
$sSQL .= ' AND '.$sCountryTerm; $sSQL .= ' AND '.$sCountryTerm;
} }
$sSQL .= $this->oContext->excludeSQL(' AND p.place_id');
$sSQL .= " LIMIT $iLimit"; $sSQL .= " LIMIT $iLimit";
if (CONST_Debug) var_dump($sSQL); if (CONST_Debug) var_dump($sSQL);
@@ -460,7 +459,7 @@ class SearchDescription
return chksql($oDB->getCol($sSQL)); return chksql($oDB->getCol($sSQL));
} }
public function queryNamedPlace(&$oDB, $aWordFrequencyScores, $sCountryList, $iMinAddressRank, $iMaxAddressRank, $sExcludeSQL, $iLimit) public function queryNamedPlace(&$oDB, $aWordFrequencyScores, $sCountryList, $iMinAddressRank, $iMaxAddressRank, $iLimit)
{ {
$aTerms = array(); $aTerms = array();
$aOrder = array(); $aOrder = array();
@@ -534,8 +533,9 @@ class SearchDescription
} }
} }
$sExcludeSQL = $this->oContext->excludeSQL('place_id');
if ($sExcludeSQL) { if ($sExcludeSQL) {
$aTerms[] = 'place_id not in ('.$sExcludeSQL.')'; $aTerms[] = $sExcludeSQL;
} }
if ($this->oContext->bViewboxBounded) { if ($this->oContext->bViewboxBounded) {
@@ -590,7 +590,7 @@ class SearchDescription
} }
public function queryHouseNumber(&$oDB, $aRoadPlaceIDs, $sExcludeSQL, $iLimit) public function queryHouseNumber(&$oDB, $aRoadPlaceIDs, $iLimit)
{ {
$sPlaceIDs = join(',', $aRoadPlaceIDs); $sPlaceIDs = join(',', $aRoadPlaceIDs);
@@ -598,9 +598,7 @@ class SearchDescription
$sSQL = 'SELECT place_id FROM placex '; $sSQL = 'SELECT place_id FROM placex ';
$sSQL .= 'WHERE parent_place_id in ('.$sPlaceIDs.')'; $sSQL .= 'WHERE parent_place_id in ('.$sPlaceIDs.')';
$sSQL .= " AND transliteration(housenumber) ~* E'".$sHouseNumberRegex."'"; $sSQL .= " AND transliteration(housenumber) ~* E'".$sHouseNumberRegex."'";
if ($sExcludeSQL) { $sSQL .= $this->oContext->excludeSQL(' AND place_id');
$sSQL .= ' AND place_id not in ('.$sExcludeSQL.')';
}
$sSQL .= " LIMIT $iLimit"; $sSQL .= " LIMIT $iLimit";
if (CONST_Debug) var_dump($sSQL); if (CONST_Debug) var_dump($sSQL);
@@ -629,10 +627,7 @@ class SearchDescription
$sSQL .= " or interpolationtype='all') and "; $sSQL .= " or interpolationtype='all') and ";
$sSQL .= $iHousenumber.">=startnumber and "; $sSQL .= $iHousenumber.">=startnumber and ";
$sSQL .= $iHousenumber."<=endnumber"; $sSQL .= $iHousenumber."<=endnumber";
$sSQL .= $this->oContext->excludeSQL(' AND place_id');
if ($sExcludeSQL) {
$sSQL .= ' AND place_id not in ('.$sExcludeSQL.')';
}
$sSQL .= " limit $iLimit"; $sSQL .= " limit $iLimit";
if (CONST_Debug) var_dump($sSQL); if (CONST_Debug) var_dump($sSQL);
@@ -649,9 +644,7 @@ class SearchDescription
$sSQL = 'SELECT place_id FROM location_property_aux'; $sSQL = 'SELECT place_id FROM location_property_aux';
$sSQL .= ' WHERE parent_place_id in ('.$sPlaceIDs.')'; $sSQL .= ' WHERE parent_place_id in ('.$sPlaceIDs.')';
$sSQL .= " AND housenumber = '".$this->sHouseNumber."'"; $sSQL .= " AND housenumber = '".$this->sHouseNumber."'";
if ($sExcludeSQL) { $sSQL .= $this->oContext->excludeSQL(' AND place_id');
$sSQL .= " AND place_id not in ($sExcludeSQL)";
}
$sSQL .= " limit $iLimit"; $sSQL .= " limit $iLimit";
if (CONST_Debug) var_dump($sSQL); if (CONST_Debug) var_dump($sSQL);
@@ -675,10 +668,7 @@ class SearchDescription
$sSQL .= " or interpolationtype='all') and "; $sSQL .= " or interpolationtype='all') and ";
$sSQL .= $iHousenumber.">=startnumber and "; $sSQL .= $iHousenumber.">=startnumber and ";
$sSQL .= $iHousenumber."<=endnumber"; $sSQL .= $iHousenumber."<=endnumber";
$sSQL .= $this->oContext->excludeSQL(' AND place_id');
if ($sExcludeSQL) {
$sSQL .= ' AND place_id not in ('.$sExcludeSQL.')';
}
$sSQL .= " limit $iLimit"; $sSQL .= " limit $iLimit";
if (CONST_Debug) var_dump($sSQL); if (CONST_Debug) var_dump($sSQL);
@@ -694,7 +684,7 @@ class SearchDescription
} }
public function queryPoiByOperator(&$oDB, $aParentIDs, $sExcludeSQL, $iLimit) public function queryPoiByOperator(&$oDB, $aParentIDs, $iLimit)
{ {
$sPlaceIDs = join(',', $aParentIDs); $sPlaceIDs = join(',', $aParentIDs);
$aClassPlaceIDs = array(); $aClassPlaceIDs = array();
@@ -707,6 +697,7 @@ class SearchDescription
$sSQL .= " AND class='".$this->sClass."' "; $sSQL .= " AND class='".$this->sClass."' ";
$sSQL .= " AND type='".$this->sType."'"; $sSQL .= " AND type='".$this->sType."'";
$sSQL .= " AND linked_place_id is null"; $sSQL .= " AND linked_place_id is null";
$sSQL .= $this->oContext->excludeSQL(' AND place_id');
$sSQL .= " ORDER BY rank_search ASC "; $sSQL .= " ORDER BY rank_search ASC ";
$sSQL .= " LIMIT $iLimit"; $sSQL .= " LIMIT $iLimit";
@@ -783,9 +774,7 @@ class SearchDescription
$sSQL .= " WHERE ST_Contains('$sPlaceGeom', l.centroid)"; $sSQL .= " WHERE ST_Contains('$sPlaceGeom', l.centroid)";
} }
if ($sExcludeSQL) { $sSQL .= $this->oContext->excludeSQL(' AND l.place_id');
$sSQL .= ' AND l.place_id not in ('.$sExcludeSQL.')';
}
$sSQL .= 'limit 300) i '; $sSQL .= 'limit 300) i ';
if ($sOrderBySQL) { if ($sOrderBySQL) {
$sSQL .= 'order by order_term asc'; $sSQL .= 'order by order_term asc';
@@ -816,9 +805,7 @@ class SearchDescription
$sSQL .= " AND ST_DWithin(l.geometry, f.centroid, $fRange)"; $sSQL .= " AND ST_DWithin(l.geometry, f.centroid, $fRange)";
$sSQL .= " AND l.class='".$this->sClass."'"; $sSQL .= " AND l.class='".$this->sClass."'";
$sSQL .= " AND l.type='".$this->sType."'"; $sSQL .= " AND l.type='".$this->sType."'";
if ($sExcludeSQL) { $sSQL .= $this->oContext->excludeSQL(' AND l.place_id');
$sSQL .= " AND l.place_id not in (".$sExcludeSQL.")";
}
if ($sOrderBySQL) { if ($sOrderBySQL) {
$sSQL .= "ORDER BY orderterm ASC"; $sSQL .= "ORDER BY orderterm ASC";
} }