$oSearch->sHouseNumber = $oSearchTerm->sToken;
// sanity check: if the housenumber is not mainly made
// up of numbers, add a penalty
- if (preg_match_all('/[^0-9]/', $oSearch->sHouseNumber, $aMatches) > 2) {
+ if (preg_match('/\\d/', $oSearch->sHouseNumber) === 0
+ || preg_match_all('/[^0-9]/', $oSearch->sHouseNumber, $aMatches) > 2) {
$oSearch->iSearchRank++;
}
if (empty($oSearchTerm->iId)) {
//now search for housenumber, if housenumber provided
if ($this->sHouseNumber && !empty($aResults)) {
- $aNamedPlaceIDs = $aResults;
- $aResults = $this->queryHouseNumber($oDB, $aNamedPlaceIDs);
+ // Downgrade the rank of the street results, they are missing
+ // the housenumber.
+ foreach ($aResults as $oRes) {
+ $oRes->iResultRank++;
+ }
+
+ $aHnResults = $this->queryHouseNumber($oDB, $aResults);
- if (empty($aResults) && $this->looksLikeFullAddress()) {
- $aResults = $aNamedPlaceIDs;
+ if (!empty($aHnResults)) {
+ foreach ($aHnResults as $oRes) {
+ $aResults[$oRes->iId] = $oRes;
+ }
}
}
if ($sPlaceIds) {
$sSQL = 'SELECT place_id FROM placex';
$sSQL .= ' WHERE place_id in ('.$sPlaceIds.')';
- $sSQL .= " AND postcode = '".$this->sPostcode."'";
+ $sSQL .= " AND postcode != '".$this->sPostcode."'";
Debug::printSQL($sSQL);
$aFilteredPlaceIDs = chksql($oDB->getCol($sSQL));
if ($aFilteredPlaceIDs) {
- $aNewResults = array();
foreach ($aFilteredPlaceIDs as $iPlaceId) {
- $aNewResults[$iPlaceId] = $aResults[$iPlaceId];
+ $aResults[$iPlaceId]->iResultRank++;
}
- $aResults = $aNewResults;
- Debug::printVar('Place IDs after postcode filtering', $aResults);
}
}
}
Debug::printSQL($sSQL);
+ $iPlaceId = $oDB->getOne($sSQL);
+
$aResults = array();
- foreach (chksql($oDB->getCol($sSQL)) as $iPlaceId) {
+ if ($iPlaceId) {
$aResults[$iPlaceId] = new Result($iPlaceId);
}
$sSQL .= ', search_name s ';
$sSQL .= 'WHERE s.place_id = p.parent_place_id ';
$sSQL .= 'AND array_cat(s.nameaddress_vector, s.name_vector)';
- $sSQL .= ' @> '.getArraySQL($this->aAddress).' AND ';
+ $sSQL .= ' @> '.$oDB->getArraySQL($this->aAddress).' AND ';
} else {
$sSQL .= 'WHERE ';
}
}
if (!empty($this->aName)) {
- $aTerms[] = 'name_vector @> '.getArraySQL($this->aName);
+ $aTerms[] = 'name_vector @> '.$oDB->getArraySQL($this->aName);
}
if (!empty($this->aAddress)) {
// For infrequent name terms disable index usage for address
if ($this->bRareName) {
- $aTerms[] = 'array_cat(nameaddress_vector,ARRAY[]::integer[]) @> '.getArraySQL($this->aAddress);
+ $aTerms[] = 'array_cat(nameaddress_vector,ARRAY[]::integer[]) @> '.$oDB->getArraySQL($this->aAddress);
} else {
- $aTerms[] = 'nameaddress_vector @> '.getArraySQL($this->aAddress);
+ $aTerms[] = 'nameaddress_vector @> '.$oDB->getArraySQL($this->aAddress);
}
}
if (!empty($this->aFullNameAddress)) {
$sExactMatchSQL = ' ( ';
$sExactMatchSQL .= ' SELECT count(*) FROM ( ';
- $sExactMatchSQL .= ' SELECT unnest('.getArraySQL($this->aFullNameAddress).')';
+ $sExactMatchSQL .= ' SELECT unnest('.$oDB->getArraySQL($this->aFullNameAddress).')';
$sExactMatchSQL .= ' INTERSECT ';
$sExactMatchSQL .= ' SELECT unnest(nameaddress_vector)';
$sExactMatchSQL .= ' ) s';