]> git.openstreetmap.org Git - nominatim.git/commitdiff
deduplicate search term graph slightly earlier
authorBrian Quinion <openstreetmap@brian.quinion.co.uk>
Mon, 7 Mar 2011 16:16:05 +0000 (16:16 +0000)
committerBrian Quinion <openstreetmap@brian.quinion.co.uk>
Mon, 7 Mar 2011 16:16:05 +0000 (16:16 +0000)
website/search.php

index 2e235ee5dcfb419087b5c4e2a8618eca0cac19d5..d6007ef591730fd918f0801bddc70a0b09191fbc 100755 (executable)
@@ -84,7 +84,7 @@
                $hLog = logStart($oDB, 'search', $sQuery, $aLangPrefOrder);
 
                // Hack to make it handle "new york, ny" (and variants) correctly
-                $sQuery = str_ireplace(array('New York, ny','new york, new york', 'New York ny','new york new york'), 'new york city, new york', $sQuery);
+                $sQuery = str_ireplace(array('New York, ny','new york, new york', 'New York ny','new york new york'), 'new york city, ny', $sQuery);
 
                // If we have a view box create the SQL
                // Small is the actual view box, Large is double (on each axis) that 
                                                                                {
                                                                                        if (sizeof($aSearch['aName']))
                                                                                        {
-                                                                                               if (!isset($aValidTokens[$sToken]) || strlen($sToken) < 4)
+                                                                                               if (!isset($aValidTokens[$sToken]) || strlen($sToken) < 4 || strpos($sToken, ' ') !== false)
                                                                                                {
                                                                                                        $aSearch['aAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
                                                                                                }
                                                                                }
                                                                        }
                                                                }
-                                                               if (isset($aValidTokens[$sToken]) && strlen($sToken) >= 4)
+                                                               if (isset($aValidTokens[$sToken]))
                                                                {
                                                                        // Allow searching for a word - but at extra cost
                                                                        foreach($aValidTokens[$sToken] as $aSearchTerm)
                                                                        {
 //var_Dump('<hr>',$aSearch['aName']);
 
-                                                                               if (sizeof($aCurrentSearch['aName']))
+                                                                               if (sizeof($aCurrentSearch['aName'])  && strlen($sToken) >= 4)
                                                                                {
                                                                                $aSearch = $aCurrentSearch;
                                                                                        $aSearch['iSearchRank'] += 1;
                                                                                if (!sizeof($aCurrentSearch['aName']) || $aCurrentSearch['iNamePhrase'] == $iPhrase)
                                                                                {
                                                                                $aSearch = $aCurrentSearch;
-                                                                                       $aSearch['iSearchRank'] += 4;
+                                                                                       $aSearch['iSearchRank'] += 2;
+                                                                                       if (preg_match('#^[0-9]+$#', $sToken)) $aSearch['iSearchRank'] += 2;
                                                                                        $aSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
                                                                                        $aSearch['iNamePhrase'] = $iPhrase;
                                                                                if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch;
 
                                                $aNewPhraseSearches = array_merge($aNewPhraseSearches, $aNewWordsetSearches);
                                                usort($aNewPhraseSearches, 'bySearchRank');
+
+          $aSearchHash = array();
+          foreach($aNewPhraseSearches as $iSearch => $aSearch)
+          {
+            $sHash = serialize($aSearch);
+            if (isset($aSearchHash[$sHash]))
+            {
+              unset($aNewPhraseSearches[$iSearch]);
+            }
+            else
+            {
+              $aSearchHash[$sHash] = 1;
+            }
+          }
+
                                                $aNewPhraseSearches = array_slice($aNewPhraseSearches, 0, 50);
                                        }