]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 18 Jan 2013 21:31:11 +0000 (22:31 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 18 Jan 2013 21:31:11 +0000 (22:31 +0100)
1  2 
website/search.php

diff --combined website/search.php
index a92ac30ad57c3ad82eae0031fbe0df71b7259807,e00d8791b2afb9490bf2dc95810271b5ae827a8e..0d398cc43db216255a251bc20eacb59efa9fed04
@@@ -71,7 -71,6 +71,7 @@@
        if (isset($aLangPrefOrder['name:de'])) $bReverseInPlan = true;
        if (isset($aLangPrefOrder['name:ru'])) $bReverseInPlan = true;
        if (isset($aLangPrefOrder['name:ja'])) $bReverseInPlan = true;
 +      if (isset($aLangPrefOrder['name:pl'])) $bReverseInPlan = true;
  
        $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
  
                                                                                        {
                                                                                                $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 ($iToken+1 != sizeof($aWordset) || $iPhrase+1 != sizeof($aPhrases)) $aSearch['iSearchRank'] += 5;
+                                                                                               // If reverse order is enabled, it may appear at the beginning as well.
+                                                                                               if (($iToken+1 != sizeof($aWordset) || $iPhrase+1 != sizeof($aPhrases)) &&
+                                                                                                               (!$bReverseInPlan || $iToken > 0 || $iPhrase > 0))
+                                                                                               {
+                                                                                                       $aSearch['iSearchRank'] += 5;
+                                                                                               }
                                                                                                if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch;
                                                                                        }
                                                                                }
                                                                if ($sCountryCodesSQL) $sSQL .= " join placex using (place_id)";
                                                                $sSQL .= " where st_contains($sViewboxSmallSQL, ct.centroid)";
                                                                if ($sCountryCodesSQL) $sSQL .= " and country_code in ($sCountryCodesSQL)";                                                             
+                                                               if (sizeof($aExcludePlaceIDs))
+                                                               {
+                                                                       $sSQL .= " and place_id not in (".join(',',$aExcludePlaceIDs).")";
+                                                               }
                                                                if ($sViewboxCentreSQL) $sSQL .= " order by st_distance($sViewboxCentreSQL, ct.centroid) asc";
                                                                $sSQL .= " limit $iLimit";
                                                                if (CONST_Debug) var_dump($sSQL);
                                                                $aPlaceIDs = $oDB->getCol($sSQL);
  
-                                                               if (!sizeof($aPlaceIDs))
+                                                               // If excluded place IDs are given, it is fair to assume that
+                                                               // there have been results in the small box, so no further
+                                                               // expansion in that case.
+                                                               if (!sizeof($aPlaceIDs) && !sizeof($aExcludePlaceIDs))
                                                                {
                                                                        $sSQL = "select place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." ct";
                                                                        if ($sCountryCodesSQL) $sSQL .= " join placex using (place_id)";
                                                                else
                                                                        $sSQL .= " limit ".$iLimit;
  
 -                                                              if (CONST_Debug) { var_dump($sSQL); }
 +                                                              if (CONST_Debug) var_dump($sSQL);
 +                                                              $iStartTime = time();
                                                                $aViewBoxPlaceIDs = $oDB->getAll($sSQL);
                                                                if (PEAR::IsError($aViewBoxPlaceIDs))
                                                                {
                                                                        failInternalError("Could not get places for search terms.", $sSQL, $aViewBoxPlaceIDs);
                                                                }
 +                                                              if (time() - $iStartTime > 60) {
 +                                                                      file_put_contents(CONST_BasePath.'/log/long_queries.log', date('Y-m-d H:i:s', $iStartTime).' '.$sSQL."\n", FILE_APPEND);
 +                                                              }
 +
  //var_dump($aViewBoxPlaceIDs);
                                                                // Did we have an viewbox matches?
                                                                $aPlaceIDs = array();