r44772 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44771‎ | r44772 | r44773 >
Date:17:53, 18 December 2008
Author:rainman
Status:ok
Tags:
Comment:
* 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 (modified) (history)
  • /trunk/extensions/MWSearch/MWSearch_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MWSearch/MWSearch.php
@@ -54,6 +54,9 @@
5555 # hit rates way below 1% even for very long expiry times
5656 $wgLuceneSearchCacheExpiry = 0;
5757
 58+# timeout for search backend to respond
 59+$wgLuceneSearchTimeout = 6;
 60+
5861 $wgExtensionCredits['other'][] = array(
5962 'name' => 'MWSearch',
6063 'svn-date' => '$LastChangedDate$',
Index: trunk/extensions/MWSearch/MWSearch_body.php
@@ -55,12 +55,22 @@
5656 global $wgContLang, $wgLuceneUseRelated;
5757 $fname = 'LuceneSearch::replacePrefixes';
5858 wfProfileIn($fname);
59 - $qlen = strlen($query);
6059 $start = 0; $len = 0; // token start pos and length
6160 $rewritten = ''; // rewritten query
6261 $rindex = 0; // point to last rewritten character
6362 $inquotes = false;
6463
 64+ // "search everything" keyword
 65+ $allkeyword = wfMsgForContent('searchall');
 66+
 67+ // if all namespaces are set, convert to prefixed all: syntax which is more quickly handled by backend
 68+ $nsAllSet = array_keys( SearchEngine::searchableNamespaces() );
 69+ if( $this->namespaces == $nsAllSet && strncmp($query, $allkeyword, strlen($allkeyword)) != 0){
 70+ $query = $allkeyword.':'.$query;
 71+ }
 72+
 73+ $qlen = strlen($query);
 74+
6575 // quick check, most of the time we don't need any rewriting
6676 if(strpos($query,':')===false){
6777 wfProfileOut($fname);
@@ -76,10 +86,6 @@
7787 return trim($ret);
7888 }
7989
80 - // "search everything"
81 - // might not be at the beginning for complex queries
82 - $allkeyword = wfMsgForContent('searchall');
83 -
8490 for($i = 0 ; $i < $qlen ; $i++){
8591 $c = $query[$i];
8692
@@ -152,6 +158,10 @@
153159 wfProfileOut($fname);
154160 return $rewritten;
155161 }
 162+
 163+ function acceptListRedirects() {
 164+ return false;
 165+ }
156166 }
157167
158168 class LuceneResult extends SearchResult {
@@ -437,6 +447,7 @@
438448
439449 global $wgLuceneHost, $wgLucenePort, $wgDBname, $wgMemc;
440450 global $wgLuceneSearchVersion, $wgLuceneSearchCacheExpiry;
 451+ global $wgLuceneSearchTimeout;
441452
442453 if( is_array( $wgLuceneHost ) ) {
443454 $pick = mt_rand( 0, count( $wgLuceneHost ) - 1 );
@@ -469,7 +480,7 @@
470481 wfDebug( "Fetching search data from $searchUrl\n" );
471482 wfSuppressWarnings();
472483 wfProfileIn( $fname.'-contact-'.$host );
473 - $data = Http::get( $searchUrl );
 484+ $data = Http::get( $searchUrl, $wgLuceneSearchTimeout );
474485 wfProfileOut( $fname.'-contact-'.$host );
475486 wfRestoreWarnings();
476487 if( $data === false ) {

Status & tagging log