X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/3cf763475ffe3b5b5d65955a7128bd77aebd69de..15a1666f8a1e19c338015fccd502be6cfd5c24df:/lib/SearchDescription.php diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index d8c541db..f0106063 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. @@ -21,8 +21,6 @@ class SearchDescription private $bRareName = false; /// List of word ids making up the address of the object. private $aAddress = array(); - /// Subset of word ids of full words making up the address. - private $aFullNameAddress = array(); /// List of word ids that appear in the name but should be ignored. private $aNameNonSearch = array(); /// List of word ids that appear in the address but should be ignored. @@ -219,6 +217,9 @@ class SearchDescription ) { $oSearch = clone $this; $oSearch->iSearchRank++; + if (strlen($oSearchTerm->sPostcode) < 4) { + $oSearch->iSearchRank += 4 - strlen($oSearchTerm->sPostcode); + } $oSearch->sPostcode = $oSearchTerm->sPostcode; $aNewSearches[] = $oSearch; } @@ -256,6 +257,7 @@ class SearchDescription $oSearch = clone $this; $oSearch->iSearchRank++; $oSearch->aAddress = $this->aName; + $oSearch->bRareName = false; $oSearch->aName = array($oSearchTerm->iId => $oSearchTerm->iId); $aNewSearches[] = $oSearch; } @@ -295,11 +297,9 @@ class SearchDescription if (!empty($this->aName) || !($bFirstPhrase || $sPhraseType == '')) { if (($sPhraseType == '' || !$bFirstPhrase) && !$bHasPartial) { $oSearch = clone $this; - $oSearch->iSearchRank += 2; + $oSearch->iSearchRank += 3 * $oSearchTerm->iTermCount; $oSearch->aAddress[$iWordID] = $iWordID; $aNewSearches[] = $oSearch; - } else { - $this->aFullNameAddress[$iWordID] = $iWordID; } } else { $oSearch = clone $this; @@ -345,16 +345,19 @@ class SearchDescription ) { if ($oSearchTerm->iSearchNameCount < CONST_Max_Word_Frequency) { $oSearch = clone $this; - $oSearch->iSearchRank += 2; + $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++; + $oSearch->iSearchRank += $oSearchTerm->iTermCount + 1; $oSearch->aAddressNonSearch[$iWordID] = $iWordID; - if (preg_match('#^[0-9]+$#', $sToken)) { - $oSearch->iSearchRank += 2; - } if (!empty($aFullTokens)) { $oSearch->iSearchRank++; } @@ -364,7 +367,7 @@ class SearchDescription foreach ($aFullTokens as $oSearchTermToken) { if (is_a($oSearchTermToken, '\Nominatim\Token\Word')) { $oSearch = clone $this; - $oSearch->iSearchRank++; + $oSearch->iSearchRank += 3; $oSearch->aAddress[$oSearchTermToken->iId] = $oSearchTermToken->iId; $aNewSearches[] = $oSearch; @@ -703,10 +706,11 @@ class SearchDescription $sImportanceSQL .= $this->oContext->viewboxImportanceSQL('centroid'); $aOrder[] = "$sImportanceSQL DESC"; - if (!empty($this->aFullNameAddress)) { + $aFullNameAddress = $this->oContext->getFullNameTerms(); + if (!empty($aFullNameAddress)) { $sExactMatchSQL = ' ( '; $sExactMatchSQL .= ' SELECT count(*) FROM ( '; - $sExactMatchSQL .= ' SELECT unnest('.$oDB->getArraySQL($this->aFullNameAddress).')'; + $sExactMatchSQL .= ' SELECT unnest('.$oDB->getArraySQL($aFullNameAddress).')'; $sExactMatchSQL .= ' INTERSECT '; $sExactMatchSQL .= ' SELECT unnest(nameaddress_vector)'; $sExactMatchSQL .= ' ) s';