]> git.openstreetmap.org Git - nominatim.git/commitdiff
move word recheck into token collection
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 13 Oct 2017 21:04:12 +0000 (23:04 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 13 Oct 2017 21:04:12 +0000 (23:04 +0200)
Drop tokens for special and postcode searches already when
collecting them for ValidTokens when they cannot be found
in the normalized query.

lib/Geocode.php
lib/SearchDescription.php

index faf9e770483de9af99741c2967f478e13f9e2560..f7f97593a8a3b01b2e999e97aafe622c93569063 100644 (file)
@@ -669,7 +669,7 @@ class Geocode
         return $aSearchResults;
     }
 
         return $aSearchResults;
     }
 
-    public function getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bIsStructured, $sNormQuery)
+    public function getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bIsStructured)
     {
         /*
              Calculate all searches using aValidTokens i.e.
     {
         /*
              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) {
                         // 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,
                                 $aNewSearches = $oCurrentSearch->extendWithFullTerm(
                                     $aSearchTerm,
-                                    $bWordInQuery,
                                     isset($aValidTokens[$sToken])
                                       && strpos($sToken, ' ') === false,
                                     $sPhraseType,
                                     isset($aValidTokens[$sToken])
                                       && strpos($sToken, ' ') === false,
                                     $sPhraseType,
@@ -999,6 +990,14 @@ class Geocode
                         continue;
                     }
 
                         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 {
                     if (isset($aValidTokens[$aToken['word_token']])) {
                         $aValidTokens[$aToken['word_token']][] = $aToken;
                     } else {
@@ -1035,7 +1034,7 @@ class Geocode
                 // Any words that have failed completely?
                 // TODO: suggestions
 
                 // Any words that have failed completely?
                 // TODO: suggestions
 
-                $aGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bStructuredPhrases, $sNormQuery);
+                $aGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bStructuredPhrases);
 
                 if ($this->bReverseInPlan) {
                     // Reverse phrase array and also reverse the order of the wordsets in
 
                 if ($this->bReverseInPlan) {
                     // Reverse phrase array and also reverse the order of the wordsets in
@@ -1046,7 +1045,7 @@ class Geocode
                     if (sizeof($aPhrases) > 1) {
                         $aPhrases[sizeof($aPhrases)-1]->invertWordSets();
                     }
                     if (sizeof($aPhrases) > 1) {
                         $aPhrases[sizeof($aPhrases)-1]->invertWordSets();
                     }
-                    $aReverseGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, false, $sNormQuery);
+                    $aReverseGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, false);
 
                     foreach ($aGroupedSearches as $aSearches) {
                         foreach ($aSearches as $aSearch) {
 
                     foreach ($aGroupedSearches as $aSearches) {
                         foreach ($aSearches as $aSearch) {
index ea7c96ef226d5aa8c9a3dd93dedd2acf907d32b4..1325a46335396401e975e72232440b3cf41d7be9 100644 (file)
@@ -178,8 +178,6 @@ class SearchDescription
      * Derive new searches by adding a full term to the existing search.
      *
      * @param mixed[] $aSearchTerm  Description of the token.
      * Derive new searches by adding a full term to the existing search.
      *
      * @param mixed[] $aSearchTerm  Description of the token.
-     * @param bool    $bWordInQuery True, if the normalised version of the word
-     *                              is contained in the query.
      * @param bool    $bHasPartial  True if there are also tokens of partial terms
      *                              with the same name.
      * @param string  $sPhraseType  Type of phrase the token is contained in.
      * @param bool    $bHasPartial  True if there are also tokens of partial terms
      *                              with the same name.
      * @param string  $sPhraseType  Type of phrase the token is contained in.
@@ -193,7 +191,7 @@ class SearchDescription
      *
      * @return SearchDescription[] List of derived search descriptions.
      */
      *
      * @return SearchDescription[] List of derived search descriptions.
      */
-    public function extendWithFullTerm($aSearchTerm, $bWordInQuery, $bHasPartial, $sPhraseType, $bFirstToken, $bFirstPhrase, $bLastToken, &$iGlobalRank)
+    public function extendWithFullTerm($aSearchTerm, $bHasPartial, $sPhraseType, $bFirstToken, $bFirstPhrase, $bLastToken, &$iGlobalRank)
     {
         $aNewSearches = array();
 
     {
         $aNewSearches = array();
 
@@ -224,7 +222,8 @@ class SearchDescription
             // We need to try the case where the postal code is the primary element
             // (i.e. no way to tell if it is (postalcode, city) OR (city, postalcode)
             // so try both.
             // We need to try the case where the postal code is the primary element
             // (i.e. no way to tell if it is (postalcode, city) OR (city, postalcode)
             // so try both.
-            if (!$this->sPostcode && $bWordInQuery
+            if (!$this->sPostcode
+                && $aSearchTerm['word']
                 && pg_escape_string($aSearchTerm['word']) == $aSearchTerm['word']
             ) {
                 // If we have structured search or this is the first term,
                 && pg_escape_string($aSearchTerm['word']) == $aSearchTerm['word']
             ) {
                 // If we have structured search or this is the first term,
@@ -273,16 +272,8 @@ class SearchDescription
                 }
                 $aNewSearches[] = $oSearch;
             }
                 }
                 $aNewSearches[] = $oSearch;
             }
-        } elseif ($sPhraseType == ''
-                  && $aSearchTerm['class'] !== '' && $aSearchTerm['class'] !== null
-        ) {
-            // require a normalized exact match of the term
-            // if we have the normalizer version of the query
-            // available
-            if ($this->iOperator == Operator::NONE
-                && (isset($aSearchTerm['word']) && $aSearchTerm['word'])
-                && $bWordInQuery
-            ) {
+        } elseif ($sPhraseType == '' && $aSearchTerm['class']) {
+            if ($this->iOperator == Operator::NONE) {
                 $oSearch = clone $this;
                 $oSearch->iSearchRank++;
 
                 $oSearch = clone $this;
                 $oSearch->iSearchRank++;