X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/b68b2ff6b834f4bf6d0b9a0a22ef56c73743a8a8..a759c5b75b66894b1902327097185840a2557f86:/lib/SearchDescription.php?ds=sidebyside diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index 94ba87ff..2053082f 100644 --- a/lib/SearchDescription.php +++ b/lib/SearchDescription.php @@ -2,9 +2,9 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/SpecialSearchOperator.php'); -require_once(CONST_BasePath.'/lib/SearchContext.php'); -require_once(CONST_BasePath.'/lib/Result.php'); +require_once(CONST_LibDir.'/SpecialSearchOperator.php'); +require_once(CONST_LibDir.'/SearchContext.php'); +require_once(CONST_LibDir.'/Result.php'); /** * Description of a single interpretation of a search query. @@ -86,18 +86,6 @@ class SearchDescription $this->sType = $sType; } - /** - * Check if this might be a full address search. - * - * @return bool True if the search contains name, address and housenumber. - */ - public function looksLikeFullAddress() - { - return (!empty($this->aName)) - && (!empty($this->aAddress) || $this->sCountryCode) - && preg_match('/[0-9]+/', $this->sHouseNumber); - } - /** * Check if any operator is set. * @@ -248,6 +236,19 @@ class SearchDescription $oSearch->iSearchRank++; } $aNewSearches[] = $oSearch; + // Housenumbers may appear in the name when the place has its own + // address terms. + if ($oSearchTerm->iId !== null + && ($this->iNamePhrase >= 0 || empty($this->aName)) + && empty($this->aAddress) + ) { + $oSearch = clone $this; + $oSearch->iSearchRank++; + $oSearch->aAddress = $this->aName; + $oSearch->bRareName = false; + $oSearch->aName = array($oSearchTerm->iId => $oSearchTerm->iId); + $aNewSearches[] = $oSearch; + } } } elseif ($sPhraseType == '' && is_a($oSearchTerm, '\Nominatim\Token\SpecialTerm') @@ -332,7 +333,7 @@ class SearchDescription ) { if ($oSearchTerm->iSearchNameCount < CONST_Max_Word_Frequency) { $oSearch = clone $this; - $oSearch->iSearchRank += $oSearchTerm->iTermCount; + $oSearch->iSearchRank += $oSearchTerm->iTermCount + 1; if (empty($this->aName)) { $oSearch->iSearchRank++; } @@ -343,7 +344,7 @@ class SearchDescription $aNewSearches[] = $oSearch; } else { $oSearch = clone $this; - $oSearch->iSearchRank++; + $oSearch->iSearchRank += $oSearchTerm->iTermCount + 1; $oSearch->aAddressNonSearch[$iWordID] = $iWordID; if (!empty($aFullTokens)) { $oSearch->iSearchRank++; @@ -1014,7 +1015,7 @@ class SearchDescription 'Name terms (stop words)' => $this->aNameNonSearch, 'Address terms' => $this->aAddress, 'Address terms (stop words)' => $this->aAddressNonSearch, - 'Address terms (full words)' => $this->aFullNameAddress, + 'Address terms (full words)' => $this->aFullNameAddress ?? '', 'Special search' => $this->iOperator, 'Class' => $this->sClass, 'Type' => $this->sType, @@ -1026,7 +1027,7 @@ class SearchDescription public function dumpAsHtmlTableRow(&$aWordIDs) { $kf = function ($k) use (&$aWordIDs) { - return $aWordIDs[$k]; + return $aWordIDs[$k] ?? '['.$k.']'; }; echo '';