take postcode into account for other searches

Existence of postcode is still optional but if a matching
result is found, then non-matching ones will be discarded.
This commit is contained in:
Sarah Hoffmann
2017-07-05 23:35:22 +02:00
parent 0ecb920866
commit 3714b7ea7d

View File

@@ -755,7 +755,7 @@ class Geocode
// If we have a structured search or this is not the first term,
// add the postcode as an addendum.
if ($sPhraseType == 'postalcode' || sizeof($aSearch['aName'])) {
$aSearch['sPostcode'] = $aSearchTerm['word_token'];
$aSearch['sPostcode'] = substr($aSearchTerm['word_token'], 1);
if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
}
}
@@ -1423,6 +1423,8 @@ class Geocode
$aTerms[] = $aSearch['oNear']->withinSQL('centroid');
$aOrder[] = $aSearch['oNear']->distanceSQL('centroid');
} elseif ($aSearch['sPostcode']) {
$aOrder[] = "(SELECT min(ST_Distance(search_name.centroid, p.geometry)) FROM location_postcode p WHERE p.postcode = '".$aSearch['sPostcode']."')";
}
if (sizeof($this->aExcludePlaceIDs)) {
$aTerms[] = "place_id not in (".join(',', $this->aExcludePlaceIDs).")";
@@ -1711,6 +1713,21 @@ class Geocode
var_Dump($aPlaceIDs);
}
if ($aSearch['sPostcode']) {
$sSQL = 'SELECT place_id FROM placex';
$sSQL .= ' WHERE place_id in ('.join(',', $aPlaceIDs).')';
$sSQL .= " AND postcode = '".pg_escape_string($aSearch['sPostcode'])."'";
if (CONST_Debug) var_dump($sSQL);
$aFilteredPlaceIDs = chksql($this->oDB->getCol($sSQL));
if ($aFilteredPlaceIDs) {
$aPlaceIDs = $aFilteredPlaceIDs;
if (CONST_Debug) {
echo "<br><b>Place IDs after postcode filtering:</b> ";
var_Dump($aPlaceIDs);
}
}
}
foreach ($aPlaceIDs as $iPlaceID) {
// array for placeID => -1 | Tiger housenumber
$aResultPlaceIDs[$iPlaceID] = $searchedHousenumber;