r11682 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11681‎ | r11682 | r11683 >
Date:08:36, 9 November 2005
Author:vibber
Status:old
Tags:
Comment:
* (bug 3880) If search server doesn't respond, try the next one automatically.
* If no search servers respond, have a maybe friendlier, more content-free error message ;)
Modified paths:
  • /trunk/extensions/LuceneSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LuceneSearch.php
@@ -198,8 +198,7 @@
199199 if ( $wgDisableTextSearch ) {
200200 $wgOut->addHTML(wfMsg('searchdisabled'));
201201 } else {
202 - global $wgLastLuceneHost;
203 - $wgOut->addWikiText(wfMsg('lucenefailure', $wgLastLuceneHost));
 202+ $wgOut->addWikiText(wfMsg('lucenefallback'));
204203 }
205204 $wgOut->addHTML(wfMsg('googlesearch',
206205 htmlspecialchars($q),
@@ -622,21 +621,13 @@
623622 $fname = 'LuceneSearchSet::newFromQuery';
624623 wfProfileIn( $fname );
625624
626 - global $wgLuceneHost, $wgLucenePort, $wgDBname, $wgMemc, $wgLastLuceneHost;
 625+ global $wgLuceneHost, $wgLucenePort, $wgDBname, $wgMemc;
627626
628 - if( is_array( $wgLuceneHost ) ) {
629 - $pick = mt_rand( 0, count( $wgLuceneHost ) - 1 );
630 - $host = $wgLuceneHost[$pick];
631 - } else {
632 - $host = $wgLuceneHost;
633 - }
634 - $wgLastLuceneHost = $host;
635 -
636627 global $wgUseLatin1, $wgContLang, $wgInputEncoding;
637628 $enctext = rawurlencode( trim( $wgUseLatin1
638629 ? $wgContLang->iconv( $wgInputEncoding, 'utf-8', $query )
639630 : $query ) );
640 - $searchUrl = "http://$host:$wgLucenePort/$method/$wgDBname/$enctext?" .
 631+ $searchPath = "/$method/$wgDBname/$enctext?" .
641632 wfArrayToCGI( array(
642633 'namespaces' => implode( ',', $namespaces ),
643634 'offset' => $offset,
@@ -644,11 +635,11 @@
645636 ) );
646637
647638 global $wgOut;
648 - $wgOut->addHtml( "<!-- querying $searchUrl -->\n" );
 639+ $wgOut->addHtml( "<!-- querying $searchPath -->\n" );
649640
650641 // Cache results for fifteen minutes; they'll be read again
651642 // on reloads and paging.
652 - $key = $wgDBname.':lucene:' . md5( $searchUrl );
 643+ $key = $wgDBname.':lucene:' . md5( $searchPath );
653644 $expiry = 60 * 15;
654645 $resultSet = $wgMemc->get( $key );
655646 if( is_object( $resultSet ) ) {
@@ -657,17 +648,40 @@
658649 return $resultSet;
659650 }
660651
661 - wfDebug( "Fetching search data from $searchUrl\n" );
662 - wfProfileIn( $fname.'-contact-'.$host );
663 - $inputLines = explode( "\n", trim( wfGetHTTP( $searchUrl ) ) );
664 - wfProfileOut( $fname.'-contact-'.$host );
665 - //$inputLines = @file( $searchUrl );
 652+ if( is_array( $wgLuceneHost ) ) {
 653+ $hosts = $wgLuceneHost;
 654+ } else {
 655+ $hosts = array( $wgLuceneHost );
 656+ }
 657+ $remaining = count( $hosts );
 658+ $pick = mt_rand( 0, count( $hosts ) - 1 );
 659+ $data = false;
666660
667 - if( $inputLines === false || $inputLines === array('') ) {
 661+ while( $data === false && $remaining-- > 0 ) {
 662+ // Start at a random position in the list, and rotate through
 663+ // until we find a host that works or run out of hosts.
 664+ $pick = ($pick + 1) % count( $hosts );
 665+ $host = $hosts[$pick];
 666+ $searchUrl = "http://$host:$wgLucenePort$searchPath";
 667+
 668+ wfDebug( "Fetching search data from $searchUrl\n" );
 669+ wfSuppressWarnings();
 670+ wfProfileIn( $fname.'-contact-'.$host );
 671+ $data = wfGetHTTP( $searchUrl );
 672+ wfProfileOut( $fname.'-contact-'.$host );
 673+ wfRestoreWarnings();
 674+
 675+ if( $data === false ) {
 676+ wfDebug( "Failed on $searchUrl!\n" );
 677+ }
 678+ }
 679+
 680+ if( $data === false || $data === '' ) {
668681 // Network error or server error
669682 wfProfileOut( $fname );
670683 return false;
671684 } else {
 685+ $inputLines = explode( "\n", trim( $data ) );
672686 $resultLines = array_map( 'trim', $inputLines );
673687 }
674688
@@ -786,7 +800,10 @@
787801 Search in namespaces:\n
788802 $1\n
789803 Search for $3 $9");
790 -$wgMessageCache->addMessage("lucenefailure", "Internal error: no valid response from search server ($1)\n");
 804+$wgMessageCache->addMessage( "lucenefallback",
 805+"There was a problem with the wiki search.
 806+This is probably temporary; try again in a few moments,
 807+or you can search the wiki through an external search service:\n");
791808
792809 } # End of extension function
793810 } # End of invocation guard

Status & tagging log