Revision: 44772
Author:   rainman
Date:     2008-12-18 17:53:12 +0000 (Thu, 18 Dec 2008)

Log Message:
-----------
* add custom search timeout (defaults to 6s)
* convert all namespaces to all: prefix for the backend
* supress redirect checkbox in special:search

Modified Paths:
--------------
    trunk/extensions/MWSearch/MWSearch.php
    trunk/extensions/MWSearch/MWSearch_body.php

Modified: trunk/extensions/MWSearch/MWSearch.php
===================================================================
--- trunk/extensions/MWSearch/MWSearch.php      2008-12-18 17:50:54 UTC (rev 
44771)
+++ trunk/extensions/MWSearch/MWSearch.php      2008-12-18 17:53:12 UTC (rev 
44772)
@@ -54,6 +54,9 @@
 # hit rates way below 1% even for very long expiry times
 $wgLuceneSearchCacheExpiry = 0;
 
+# timeout for search backend to respond
+$wgLuceneSearchTimeout = 6;
+
 $wgExtensionCredits['other'][] = array(
        'name'           => 'MWSearch',
        'svn-date' => '$LastChangedDate$',

Modified: trunk/extensions/MWSearch/MWSearch_body.php
===================================================================
--- trunk/extensions/MWSearch/MWSearch_body.php 2008-12-18 17:50:54 UTC (rev 
44771)
+++ trunk/extensions/MWSearch/MWSearch_body.php 2008-12-18 17:53:12 UTC (rev 
44772)
@@ -55,12 +55,22 @@
                global $wgContLang, $wgLuceneUseRelated;
                $fname = 'LuceneSearch::replacePrefixes';
                wfProfileIn($fname);
-               $qlen = strlen($query);
                $start = 0; $len = 0; // token start pos and length
                $rewritten = ''; // rewritten query
                $rindex = 0; // point to last rewritten character
                $inquotes = false;
                
+               // "search everything" keyword
+               $allkeyword = wfMsgForContent('searchall');             
+               
+               // if all namespaces are set, convert to prefixed all: syntax 
which is more quickly handled by backend
+               $nsAllSet = array_keys( SearchEngine::searchableNamespaces() );
+               if( $this->namespaces ==  $nsAllSet && strncmp($query, 
$allkeyword, strlen($allkeyword)) != 0){
+                       $query = $allkeyword.':'.$query;
+               }
+               
+               $qlen = strlen($query);
+               
                // quick check, most of the time we don't need any rewriting
                if(strpos($query,':')===false){ 
                        wfProfileOut($fname);
@@ -76,10 +86,6 @@
                        return trim($ret);
                }
                
-               // "search everything"
-               //  might not be at the beginning for complex queries
-               $allkeyword = wfMsgForContent('searchall');             
-               
                for($i = 0 ; $i < $qlen ; $i++){
                        $c = $query[$i];
 
@@ -152,6 +158,10 @@
                wfProfileOut($fname);
                return $rewritten;
        }
+       
+       function acceptListRedirects() {
+               return false;
+       }
 }
 
 class LuceneResult extends SearchResult {
@@ -437,6 +447,7 @@
                
                global $wgLuceneHost, $wgLucenePort, $wgDBname, $wgMemc;
                global $wgLuceneSearchVersion, $wgLuceneSearchCacheExpiry;
+               global $wgLuceneSearchTimeout;
                
                if( is_array( $wgLuceneHost ) ) {
                        $pick = mt_rand( 0, count( $wgLuceneHost ) - 1 );
@@ -469,7 +480,7 @@
                wfDebug( "Fetching search data from $searchUrl\n" ); 
                wfSuppressWarnings();
                wfProfileIn( $fname.'-contact-'.$host );
-               $data = Http::get( $searchUrl );
+               $data = Http::get( $searchUrl, $wgLuceneSearchTimeout );
                wfProfileOut( $fname.'-contact-'.$host );
                wfRestoreWarnings();
                if( $data === false ) {



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to