X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/023f94b066c11628ecc87ca9876dbe5ec4136776..cdf8c678988cdad7d10cc52b5ece22196c2491f9:/lib/Geocode.php diff --git a/lib/Geocode.php b/lib/Geocode.php index 399139f0..be543012 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -669,7 +669,7 @@ class Geocode return $aSearchResults; } - public function getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $aWordFrequencyScores, $bIsStructured, $sNormQuery) + public function getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bIsStructured) { /* Calculate all searches using aValidTokens i.e. @@ -707,17 +707,8 @@ class Geocode // If the token is valid if (isset($aValidTokens[' '.$sToken])) { foreach ($aValidTokens[' '.$sToken] as $aSearchTerm) { - // Recheck if the original word shows up in the query. - $bWordInQuery = false; - if (isset($aSearchTerm['word']) && $aSearchTerm['word']) { - $bWordInQuery = strpos( - $sNormQuery, - $this->normTerm($aSearchTerm['word']) - ) !== false; - } $aNewSearches = $oCurrentSearch->extendWithFullTerm( $aSearchTerm, - $bWordInQuery, isset($aValidTokens[$sToken]) && strpos($sToken, ' ') === false, $sPhraseType, @@ -745,7 +736,6 @@ class Geocode $aSearchTerm, $bIsStructured, $iPhrase, - $aWordFrequencyScores, isset($aValidTokens[' '.$sToken]) ? $aValidTokens[' '.$sToken] : array() ); @@ -803,7 +793,7 @@ class Geocode // Revisit searches, drop bad searches and give penalty to unlikely combinations. $aGroupedSearches = array(); foreach ($aSearches as $oSearch) { - if (!$oSearch->isValidSearch($this->aCountryCodes)) { + if (!$oSearch->isValidSearch()) { continue; } @@ -990,22 +980,29 @@ class Geocode $this->oDB->getAll($sSQL), "Could not get word tokens." ); - $aPossibleMainWordIDs = array(); $aWordFrequencyScores = array(); foreach ($aDatabaseWords as $aToken) { - // Very special case - require 2 letter country param to match the country code found - if ($bStructuredPhrases && $aToken['country_code'] && !empty($this->aStructuredQuery['country']) - && strlen($this->aStructuredQuery['country']) == 2 && strtolower($this->aStructuredQuery['country']) != $aToken['country_code'] + // Filter country tokens that do not match restricted countries. + if ($this->aCountryCodes + && $aToken['country_code'] + && !in_array($aToken['country_code'], $this->aCountryCodes) ) { continue; } + // Special terms need to appear in their normalized form. + if ($aToken['word'] && $aToken['class']) { + $sNormWord = $this->normTerm($aToken['word']); + if (strpos($sNormQuery, $sNormWord) === false) { + continue; + } + } + if (isset($aValidTokens[$aToken['word_token']])) { $aValidTokens[$aToken['word_token']][] = $aToken; } else { $aValidTokens[$aToken['word_token']] = array($aToken); } - if (!$aToken['class'] && !$aToken['country_code']) $aPossibleMainWordIDs[$aToken['word_id']] = 1; $aWordFrequencyScores[$aToken['word_id']] = $aToken['search_name_count'] + 1; } if (CONST_Debug) var_Dump($aPhrases, $aValidTokens); @@ -1037,7 +1034,7 @@ class Geocode // Any words that have failed completely? // TODO: suggestions - $aGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $aWordFrequencyScores, $bStructuredPhrases, $sNormQuery); + $aGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bStructuredPhrases); if ($this->bReverseInPlan) { // Reverse phrase array and also reverse the order of the wordsets in @@ -1048,7 +1045,7 @@ class Geocode if (sizeof($aPhrases) > 1) { $aPhrases[sizeof($aPhrases)-1]->invertWordSets(); } - $aReverseGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $aWordFrequencyScores, false, $sNormQuery); + $aReverseGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, false); foreach ($aGroupedSearches as $aSearches) { foreach ($aSearches as $aSearch) { @@ -1278,8 +1275,7 @@ class Geocode $aResult['name'] = $aResult['langaddress']; - if ($oCtx->hasNearPoint()) - { + if ($oCtx->hasNearPoint()) { $aResult['importance'] = 0.001; $aResult['foundorder'] = $aResult['addressimportance']; } else {