]> git.openstreetmap.org Git - nominatim.git/commitdiff
increase penalty for places without housenumber
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 16 Feb 2021 16:47:06 +0000 (17:47 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 16 Feb 2021 16:47:06 +0000 (17:47 +0100)
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
lib-php/Result.php
lib-php/SearchDescription.php

index 12f9da37550f856e47a128641a275813d9c4e9de..b475add22e8eefaf3cd85d0cbc85c46e7c66bc98 100644 (file)
@@ -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'];
index a67c2fe474910a20356ac05edafdac68e3168c17..a7747ea34d6fee12e98b0a7eb31c9fbaccfb7fb8 100644 (file)
@@ -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) {
index 2053082f6bbff4a13bd6a5ba6c08bc89366e0c38..ea9d7f58feb5dd06b453033f39ac1ec446f13e31 100644 (file)
@@ -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;
             }
         }