From: Sarah Hoffmann Date: Thu, 11 Mar 2021 14:03:36 +0000 (+0100) Subject: give preference to full words in address, too X-Git-Tag: v3.7.0~19^2~7 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/182f5f5d7b4e3e01fc0ab60a263fa213260bde57?hp=35f4695b67b50a41caf69378ea13044ea91f1d2c give preference to full words in address, too Full word terms are already preferred for the name part. Adding only one-word partials to the address, makes it impossible to give a similar preference for the address part. Each term adds a rank penalty. The problem here is that we interpret the query forwards and backwards. Having different penalty systems for name and address means that the same term ends up with different penalties and that often leads to interpretations of the wrong direction being in the way. --- diff --git a/lib-php/SearchDescription.php b/lib-php/SearchDescription.php index ea9d7f58..913a90d2 100644 --- a/lib-php/SearchDescription.php +++ b/lib-php/SearchDescription.php @@ -329,51 +329,30 @@ class SearchDescription if ((!$bStructuredPhrases || $iPhrase > 0) && (!empty($this->aName)) - && strpos($sToken, ' ') === false ) { + $oSearch = clone $this; + $oSearch->iSearchRank++; + if (preg_match('#^[0-9 ]+$#', $sToken)) { + $oSearch->iSearchRank++; + } if ($oSearchTerm->iSearchNameCount < CONST_Max_Word_Frequency) { - $oSearch = clone $this; - $oSearch->iSearchRank += $oSearchTerm->iTermCount + 1; - if (empty($this->aName)) { - $oSearch->iSearchRank++; - } - if (preg_match('#^[0-9]+$#', $sToken)) { - $oSearch->iSearchRank++; - } $oSearch->aAddress[$iWordID] = $iWordID; - $aNewSearches[] = $oSearch; } else { - $oSearch = clone $this; - $oSearch->iSearchRank += $oSearchTerm->iTermCount + 1; $oSearch->aAddressNonSearch[$iWordID] = $iWordID; if (!empty($aFullTokens)) { $oSearch->iSearchRank++; } - $aNewSearches[] = $oSearch; - - // revert to the token version? - foreach ($aFullTokens as $oSearchTermToken) { - if (is_a($oSearchTermToken, '\Nominatim\Token\Word')) { - $oSearch = clone $this; - $oSearch->iSearchRank += 3; - $oSearch->aAddress[$oSearchTermToken->iId] - = $oSearchTermToken->iId; - $aNewSearches[] = $oSearch; - } - } } + $aNewSearches[] = $oSearch; } if ((!$this->sPostcode && !$this->aAddress && !$this->aAddressNonSearch) && (empty($this->aName) || $this->iNamePhrase == $iPhrase) ) { $oSearch = clone $this; - $oSearch->iSearchRank += 2; - if (empty($this->aName)) { - $oSearch->iSearchRank += 1; - } - if (preg_match('#^[0-9]+$#', $sToken)) { - $oSearch->iSearchRank += 2; + $oSearch->iSearchRank++; + if (preg_match('#^[0-9 ]+$#', $sToken)) { + $oSearch->iSearchRank++; } if ($oSearchTerm->iSearchNameCount < CONST_Max_Word_Frequency) { if (empty($this->aName) @@ -387,6 +366,9 @@ class SearchDescription } $oSearch->aName[$iWordID] = $iWordID; } else { + if (!empty($aFullTokens)) { + $oSearch->iSearchRank++; + } $oSearch->aNameNonSearch[$iWordID] = $iWordID; } $oSearch->iNamePhrase = $iPhrase;