]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/SearchDescription.php
simplify cross-check of country tokens
[nominatim.git] / lib / SearchDescription.php
index 1f3765ab0d1621c6334aa8234ca0811a9808a172..ea7c96ef226d5aa8c9a3dd93dedd2acf907d32b4 100644 (file)
@@ -155,22 +155,17 @@ class SearchDescription
     /**
      * Check if the combination of parameters is sensible.
      *
-     * @param string[] $aCountryCodes List of country codes.
-     *
      * @return bool True, if the search looks valid.
      */
-    public function isValidSearch(&$aCountryCodes)
+    public function isValidSearch()
     {
         if (!sizeof($this->aName)) {
             if ($this->sHouseNumber) {
                 return false;
             }
-        }
-        if ($aCountryCodes
-            && $this->sCountryCode
-            && !in_array($this->sCountryCode, $aCountryCodes)
-        ) {
-            return false;
+            if (!$this->sClass && !$this->sCountryCode) {
+                return false;
+            }
         }
 
         return true;
@@ -302,7 +297,10 @@ class SearchDescription
                 $oSearch->setPoiSearch($iOp, $aSearchTerm['class'], $aSearchTerm['type']);
                 $aNewSearches[] = $oSearch;
             }
-        } elseif (isset($aSearchTerm['word_id']) && $aSearchTerm['word_id']) {
+        } elseif (isset($aSearchTerm['word_id'])
+                  && $aSearchTerm['word_id']
+                  && $sPhraseType != 'country'
+        ) {
             $iWordID = $aSearchTerm['word_id'];
             if (sizeof($this->aName)) {
                 if (($sPhraseType == '' || !$bFirstPhrase)
@@ -333,14 +331,12 @@ class SearchDescription
      * @param mixed[] $aSearchTerm          Description of the token.
      * @param bool    $bStructuredPhrases   True if the search is structured.
      * @param integer $iPhrase              Number of the phrase the token is in.
-     * @param mixed[] $aWordFrequencyScores Number of times tokens appears
-     *                                      overall in a planet database.
      * @param array[] $aFullTokens          List of full term tokens with the
      *                                      same name.
      *
      * @return SearchDescription[] List of derived search descriptions.
      */
-    public function extendWithPartialTerm($aSearchTerm, $bStructuredPhrases, $iPhrase, &$aWordFrequencyScores, $aFullTokens)
+    public function extendWithPartialTerm($aSearchTerm, $bStructuredPhrases, $iPhrase, $aFullTokens)
     {
         // Only allow name terms.
         if (!(isset($aSearchTerm['word_id']) && $aSearchTerm['word_id'])) {
@@ -354,7 +350,7 @@ class SearchDescription
             && sizeof($this->aName)
             && strpos($aSearchTerm['word_token'], ' ') === false
         ) {
-            if ($aWordFrequencyScores[$iWordID] < CONST_Max_Word_Frequency) {
+            if ($aSearchTerm['search_name_count'] + 1 < CONST_Max_Word_Frequency) {
                 $oSearch = clone $this;
                 $oSearch->iSearchRank++;
                 $oSearch->aAddress[$iWordID] = $iWordID;
@@ -397,7 +393,7 @@ class SearchDescription
             if (preg_match('#^[0-9]+$#', $aSearchTerm['word_token'])) {
                 $oSearch->iSearchRank += 2;
             }
-            if ($aWordFrequencyScores[$iWordID] < CONST_Max_Word_Frequency) {
+            if ($aSearchTerm['search_name_count'] + 1 < CONST_Max_Word_Frequency) {
                 $oSearch->aName[$iWordID] = $iWordID;
             } else {
                 $oSearch->aNameNonSearch[$iWordID] = $iWordID;