]> git.openstreetmap.org Git - nominatim.git/blobdiff - website/search.php
correct penalty for multi-word countries
[nominatim.git] / website / search.php
index 77892f238883e920549a7134a70c52832bd314c4..91869c3efaf22dc26e3f081893ecf948e405035c 100755 (executable)
                                $sQuery = str_replace($aSpecialTerm[0], ' ', $sQuery);
                                $sToken = $oDB->getOne("select make_standard_name('".$aSpecialTerm[1]."') as string");
                                $sSQL = 'select * from (select word_id,word_token, word, class, type, location, country_code, operator';
-                               $sSQL .= ' from word where word_token in (\' '.$sToken.'\')) as x where (class is not null and class not in (\'place\',\'highway\')) or country_code is not null';
+                               $sSQL .= ' from word where word_token in (\' '.$sToken.'\')) as x where (class is not null and class not in (\'place\')) or country_code is not null';
                                if (CONST_Debug) var_Dump($sSQL);
                                $aSearchWords = $oDB->getAll($sSQL);
                                $aNewSearches = array();
                        // Check which tokens we have, get the ID numbers                       
                        $sSQL = 'select word_id,word_token, word, class, type, location, country_code, operator';
                        $sSQL .= ' from word where word_token in ('.join(',',array_map("getDBQuoted",$aTokens)).')';
-                       $sSQL .= ' and (class is null or class not in (\'highway\'))';
+                       $sSQL .= ' and search_name_count < '.CONST_Max_Word_Frequency;
 //                     $sSQL .= ' group by word_token, word, class, type, location, country_code';
 
                        if (CONST_Debug) var_Dump($sSQL);
                                {
                                        $aNewPhraseSearches = array();
 
-                                       foreach($aPhrases[$iPhrase]['wordsets'] as $iWordset => $aWordset)
+                                       foreach($aPhrases[$iPhrase]['wordsets'] as $aWordset)
                                        {
                                                $aWordsetSearches = $aSearches;
 
                                                // Add all words from this wordset
-                                               foreach($aWordset as $sToken)
+                                               foreach($aWordset as $iToken => $sToken)
                                                {
 //echo "<br><b>$sToken</b>";
                                                        $aNewWordsetSearches = array();
                                                                                        {
                                                                                                $aSearch['sCountryCode'] = strtolower($aSearchTerm['country_code']);
                                                                                                // Country is almost always at the end of the string - increase score for finding it anywhere else (optimisation)
-                                                                                               if ($iWordset+1 != sizeof($aPhrases[$iPhrase]['wordsets']) || $iPhrase+1 != sizeof($aPhrases)) $aSearch['iSearchRank'] += 5;
+                                                                                               if ($iToken+1 != sizeof($aWordset) || $iPhrase+1 != sizeof($aPhrases)) $aSearch['iSearchRank'] += 5;
                                                                                                if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch;
                                                                                        }
                                                                                }
                                                        else
                                                        {
                                                                $sSQL = "select place_id from placex where class='".$aSearch['sClass']."' and type='".$aSearch['sType']."'";
-                                                               $sSQL .= " and st_contains($sViewboxSmallSQL, centroid)";
+                                                               $sSQL .= " and st_contains($sViewboxSmallSQL, geometry)";
                                                                if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)";                                                             
                                                                if ($sViewboxCentreSQL) $sSQL .= " order by st_distance($sViewboxCentreSQL, centroid) asc";
                                                                $sSQL .= " limit $iLimit";
                {
                        if (stripos($sAddress, $sWord)!==false) $iCountWords++;
                }
-               $aResult['importance'] = $aResult['importance'] + $iCountWords;
+               $aResult['importance'] = $aResult['importance'] + ($iCountWords*0.1); // 0.1 is a completely arbitrary number but something in the range 0.1 to 0.5 would seem right
 
 //if (CONST_Debug) var_dump($aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']);
 /*