Index: trunk/extensions/LuceneSearch.php |
— | — | @@ -198,8 +198,7 @@ |
199 | 199 | if ( $wgDisableTextSearch ) { |
200 | 200 | $wgOut->addHTML(wfMsg('searchdisabled')); |
201 | 201 | } else { |
202 | | - global $wgLastLuceneHost; |
203 | | - $wgOut->addWikiText(wfMsg('lucenefailure', $wgLastLuceneHost)); |
| 202 | + $wgOut->addWikiText(wfMsg('lucenefallback')); |
204 | 203 | } |
205 | 204 | $wgOut->addHTML(wfMsg('googlesearch', |
206 | 205 | htmlspecialchars($q), |
— | — | @@ -622,21 +621,13 @@ |
623 | 622 | $fname = 'LuceneSearchSet::newFromQuery'; |
624 | 623 | wfProfileIn( $fname ); |
625 | 624 | |
626 | | - global $wgLuceneHost, $wgLucenePort, $wgDBname, $wgMemc, $wgLastLuceneHost; |
| 625 | + global $wgLuceneHost, $wgLucenePort, $wgDBname, $wgMemc; |
627 | 626 | |
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 | | - |
636 | 627 | global $wgUseLatin1, $wgContLang, $wgInputEncoding; |
637 | 628 | $enctext = rawurlencode( trim( $wgUseLatin1 |
638 | 629 | ? $wgContLang->iconv( $wgInputEncoding, 'utf-8', $query ) |
639 | 630 | : $query ) ); |
640 | | - $searchUrl = "http://$host:$wgLucenePort/$method/$wgDBname/$enctext?" . |
| 631 | + $searchPath = "/$method/$wgDBname/$enctext?" . |
641 | 632 | wfArrayToCGI( array( |
642 | 633 | 'namespaces' => implode( ',', $namespaces ), |
643 | 634 | 'offset' => $offset, |
— | — | @@ -644,11 +635,11 @@ |
645 | 636 | ) ); |
646 | 637 | |
647 | 638 | global $wgOut; |
648 | | - $wgOut->addHtml( "<!-- querying $searchUrl -->\n" ); |
| 639 | + $wgOut->addHtml( "<!-- querying $searchPath -->\n" ); |
649 | 640 | |
650 | 641 | // Cache results for fifteen minutes; they'll be read again |
651 | 642 | // on reloads and paging. |
652 | | - $key = $wgDBname.':lucene:' . md5( $searchUrl ); |
| 643 | + $key = $wgDBname.':lucene:' . md5( $searchPath ); |
653 | 644 | $expiry = 60 * 15; |
654 | 645 | $resultSet = $wgMemc->get( $key ); |
655 | 646 | if( is_object( $resultSet ) ) { |
— | — | @@ -657,17 +648,40 @@ |
658 | 649 | return $resultSet; |
659 | 650 | } |
660 | 651 | |
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; |
666 | 660 | |
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 === '' ) { |
668 | 681 | // Network error or server error |
669 | 682 | wfProfileOut( $fname ); |
670 | 683 | return false; |
671 | 684 | } else { |
| 685 | + $inputLines = explode( "\n", trim( $data ) ); |
672 | 686 | $resultLines = array_map( 'trim', $inputLines ); |
673 | 687 | } |
674 | 688 | |
— | — | @@ -786,7 +800,10 @@ |
787 | 801 | Search in namespaces:\n |
788 | 802 | $1\n |
789 | 803 | 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"); |
791 | 808 | |
792 | 809 | } # End of extension function |
793 | 810 | } # End of invocation guard |