From: Sarah Hoffmann Date: Wed, 5 Jul 2017 21:35:22 +0000 (+0200) Subject: take postcode into account for other searches X-Git-Tag: v3.1.0~88^2~21 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/3714b7ea7d5c269d21693564b81497ccb4056571 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. --- diff --git a/lib/Geocode.php b/lib/Geocode.php index 7f1c4edc..d77d9752 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -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 "
Place IDs after postcode filtering: "; + var_Dump($aPlaceIDs); + } + } + } + foreach ($aPlaceIDs as $iPlaceID) { // array for placeID => -1 | Tiger housenumber $aResultPlaceIDs[$iPlaceID] = $searchedHousenumber;