]> git.openstreetmap.org Git - nominatim.git/blobdiff - website/search.php
Merge remote-tracking branch 'lonvia/address-importance'
[nominatim.git] / website / search.php
index 066e2c817ef4c1120ee4974d7b056fb82a367c5a..dbb364048b3c1ec51a56bee2d2c442cc9adcb610 100755 (executable)
@@ -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))."]";
 
                                                        if ($sNearPointSQL) $aOrder[] = "ST_Distance($sNearPointSQL, centroid) asc";
 
                                                        $sImportanceSQL = '(case when importance = 0 OR importance IS NULL then 0.75-(search_rank::float/40) else importance end)';
-                                                       if (sizeof($aSearch['aFullNameAddress']))
-                                                               $sImportanceSQL .= '*(select count(*) from (select unnest(ARRAY['.join($aSearch['aFullNameAddress'],",").']) INTERSECT select unnest(nameaddress_vector))s)';
-
                                                        if ($sViewboxSmallSQL) $sImportanceSQL .= " * case when ST_Contains($sViewboxSmallSQL, centroid) THEN 1 ELSE 0.5 END";
                                                        if ($sViewboxLargeSQL) $sImportanceSQL .= " * case when ST_Contains($sViewboxLargeSQL, centroid) THEN 1 ELSE 0.5 END";
                                                        $aOrder[] = "$sImportanceSQL DESC";
+                                                       if (sizeof($aSearch['aFullNameAddress']))
+                                                               $aOrder[] = '(select count(*) from (select unnest(ARRAY['.join($aSearch['aFullNameAddress'],",").']) INTERSECT select unnest(nameaddress_vector))s) DESC';
+
                                                
                                                        if (sizeof($aTerms))
                                                        {
                                                                $sSQL = "select place_id";
-                                                               if (sizeof($aSearch['aFullNameAddress']))
-                                                                       $sSQL .= ', (select count(*) from (select unnest(ARRAY['.join($aSearch['aFullNameAddress'],",").']) INTERSECT select unnest(nameaddress_vector))s) as fullwords'; 
-                                                               else
-                                                                       $sSQL .= ', 0';
                                                                $sSQL .= " from search_name";
                                                                $sSQL .= " where ".join(' and ',$aTerms);
                                                                $sSQL .= " order by ".join(', ',$aOrder);
                                                                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();
 //var_Dump($aSearchResults);
 //exit;
        $aClassType = getClassTypesWithImportance();
-       $aRecheckWords = preg_split('/\b/',$sQuery);
+       $aRecheckWords = preg_split('/\b/u',$sQuery);
        foreach($aRecheckWords as $i => $sWord)
        {
                if (!$sWord) unset($aRecheckWords[$i]);