From 8eb85f13400cab225639139006596e75645c8b87 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 16 Feb 2021 17:47:06 +0100 Subject: [PATCH] increase penalty for places without housenumber Results where the housenumber was dropped are an unlikely result when they refer to something other than a street. Therefore increase their result rank so that other matches are tried first before choosing them as a result. Improves #2167. --- lib-php/Geocode.php | 6 +++++- lib-php/Result.php | 4 +++- lib-php/SearchDescription.php | 9 +++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib-php/Geocode.php b/lib-php/Geocode.php index 12f9da37..b475add2 100644 --- a/lib-php/Geocode.php +++ b/lib-php/Geocode.php @@ -778,7 +778,7 @@ class Geocode if (!empty($aResults)) { $aSplitResults = Result::splitResults($aResults); Debug::printVar('Split results', $aSplitResults); - if ($iGroupLoop <= 4 && empty($aSplitResults['tail']) + if ($iGroupLoop <= 4 && reset($aSplitResults['head'])->iResultRank > 0) { // Haven't found an exact match for the query yet. // Therefore add result from the next group level. @@ -786,6 +786,10 @@ class Geocode foreach ($aNextResults as $oRes) { $oRes->iResultRank--; } + foreach ($aSplitResults['tail'] as $oRes) { + $oRes->iResultRank--; + $aNextResults[$oRes->iId] = $oRes; + } $aResults = array(); } else { $aResults = $aSplitResults['head']; diff --git a/lib-php/Result.php b/lib-php/Result.php index a67c2fe4..a7747ea3 100644 --- a/lib-php/Result.php +++ b/lib-php/Result.php @@ -26,6 +26,8 @@ class Result public $iExactMatches = 0; /// Subranking within the results (the higher the worse). public $iResultRank = 0; + /// Address rank of the result. + public $iAddressRank; public function debugInfo() { @@ -84,7 +86,7 @@ class Result foreach ($aResults as $oRes) { if ($oRes->iResultRank < $iMinRank) { - $aTail = array_merge($aTail, $aHead); + $aTail += $aHead; $aHead = array($oRes->iId => $oRes); $iMinRank = $oRes->iResultRank; } elseif ($oRes->iResultRank == $iMinRank) { diff --git a/lib-php/SearchDescription.php b/lib-php/SearchDescription.php index 2053082f..ea9d7f58 100644 --- a/lib-php/SearchDescription.php +++ b/lib-php/SearchDescription.php @@ -450,7 +450,11 @@ class SearchDescription // Downgrade the rank of the street results, they are missing // the housenumber. foreach ($aResults as $oRes) { - $oRes->iResultRank++; + if ($oRes->iAddressRank >= 26) { + $oRes->iResultRank++; + } else { + $oRes->iResultRank += 2; + } } $aHnResults = $this->queryHouseNumber($oDB, $aResults); @@ -715,7 +719,7 @@ class SearchDescription $aResults = array(); if (!empty($aTerms)) { - $sSQL = 'SELECT place_id,'.$sExactMatchSQL; + $sSQL = 'SELECT place_id, address_rank,'.$sExactMatchSQL; $sSQL .= ' FROM search_name'; $sSQL .= ' WHERE '.join(' and ', $aTerms); $sSQL .= ' ORDER BY '.join(', ', $aOrder); @@ -728,6 +732,7 @@ class SearchDescription foreach ($aDBResults as $aResult) { $oResult = new Result($aResult['place_id']); $oResult->iExactMatches = $aResult['exactmatch']; + $oResult->iAddressRank = $aResult['address_rank']; $aResults[$aResult['place_id']] = $oResult; } } -- 2.45.2