]> git.openstreetmap.org Git - nominatim.git/commitdiff
adjust penalty for housenumber-in-name searches
authorSarah Hoffmann <lonvia@denofr.de>
Sat, 26 Jun 2021 08:31:55 +0000 (10:31 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sat, 26 Jun 2021 09:37:15 +0000 (11:37 +0200)
When searching for house numbers in the name (for place-only
terms) then the same penalties need to apply as for the
regular house number search.

Change the code to first compute the penalties and then create
the new search variants.

lib-php/SearchDescription.php

index 67cfbad03041f69f3cc65e247f0c91653c25aeed..44d3a2a5033998a0065a9859ec701057105cb3b0 100644 (file)
@@ -218,29 +218,31 @@ class SearchDescription
                  && is_a($oSearchTerm, '\Nominatim\Token\HouseNumber')
         ) {
             if (!$this->sHouseNumber && $this->iOperator != Operator::POSTCODE) {
-                $oSearch = clone $this;
-                $oSearch->iSearchRank++;
-                $oSearch->iNamePhrase = -1;
-                $oSearch->sHouseNumber = $oSearchTerm->sToken;
-                if ($this->iOperator != Operator::NONE) {
-                    $oSearch->iSearchRank++;
-                }
                 // sanity check: if the housenumber is not mainly made
                 // up of numbers, add a penalty
-                if (preg_match('/\\d/', $oSearch->sHouseNumber) === 0
-                    || preg_match_all('/[^0-9]/', $oSearch->sHouseNumber, $aMatches) > 2) {
-                    $oSearch->iSearchRank++;
+                $iSearchCost = 1;
+                if (preg_match('/\\d/', $oSearchTerm->sToken) === 0
+                    || preg_match_all('/[^0-9]/', $oSearchTerm->sToken, $aMatches) > 2) {
+                    $iSearchCost++;
+                }
+                if ($this->iOperator != Operator::NONE) {
+                    $iSearchCost++;
                 }
                 if (empty($oSearchTerm->iId)) {
-                    $oSearch->iSearchRank++;
+                    $iSearchCost++;
                 }
                 // also must not appear in the middle of the address
                 if (!empty($this->aAddress)
                     || (!empty($this->aAddressNonSearch))
                     || $this->sPostcode
                 ) {
-                    $oSearch->iSearchRank++;
+                    $iSearchCost++;
                 }
+
+                $oSearch = clone $this;
+                $oSearch->iSearchRank += $iSearchCost;
+                $oSearch->iNamePhrase = -1;
+                $oSearch->sHouseNumber = $oSearchTerm->sToken;
                 $aNewSearches[] = $oSearch;
                 // Housenumbers may appear in the name when the place has its own
                 // address terms.
@@ -249,7 +251,7 @@ class SearchDescription
                     && empty($this->aAddress)
                    ) {
                     $oSearch = clone $this;
-                    $oSearch->iSearchRank++;
+                    $oSearch->iSearchRank += $iSearchCost;
                     $oSearch->aAddress = $this->aName;
                     $oSearch->bRareName = false;
                     $oSearch->aName = array($oSearchTerm->iId => $oSearchTerm->iId);