]> git.openstreetmap.org Git - nominatim.git/commitdiff
simplify cross-check of country tokens
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 13 Oct 2017 20:23:39 +0000 (22:23 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 13 Oct 2017 20:23:39 +0000 (22:23 +0200)
Drop country tokens that do not match the country code list
early. Remove in turn the special country code check for
structured phrases. It is sufficient to do this during
word list building.

lib/Geocode.php
lib/SearchDescription.php

index 9115be0b3e333c3c6f08fdbbcac97b254fe3b72d..faf9e770483de9af99741c2967f478e13f9e2560 100644 (file)
@@ -802,7 +802,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;
             }
 
@@ -991,9 +991,10 @@ class Geocode
                 );
                 $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;
                     }
index 143d28647dc1c21db91089fb7a804d74cfee32c0..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)