Merge "Drop zh-tw message "saveprefs""
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index e9c4042..6606c7f 100644 (file)
@@ -216,6 +216,7 @@ class SpecialSearch extends SpecialPage {
                global $wgContLang;
 
                $search = $this->getSearchEngine();
+               $search->setFeatureData( 'rewrite', $this->runSuggestion );
                $search->setLimitOffset( $this->limit, $this->offset );
                $search->setNamespaces( $this->namespaces );
                $search->prefix = $this->mPrefix;
@@ -272,12 +273,8 @@ class SpecialSearch extends SpecialPage {
                // did you mean... suggestions
                $didYouMeanHtml = '';
                if ( $showSuggestion && $textMatches && !$textStatus ) {
-                       if ( $this->shouldRunSuggestedQuery( $textMatches ) ) {
-                               $newMatches = $search->searchText( $textMatches->getSuggestionQuery() );
-                               if ( $newMatches instanceof SearchResultSet && $newMatches->numRows() > 0 ) {
-                                       $didYouMeanHtml = $this->getDidYouMeanRewrittenHtml( $term, $textMatches );
-                                       $textMatches = $newMatches;
-                               }
+                       if ( $textMatches->hasRewrittenQuery() ) {
+                               $didYouMeanHtml = $this->getDidYouMeanRewrittenHtml( $term, $textMatches );
                        } elseif ( $textMatches->hasSuggestion() ) {
                                $didYouMeanHtml = $this->getDidYouMeanHtml( $textMatches );
                        }
@@ -390,12 +387,13 @@ class SpecialSearch extends SpecialPage {
                                $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
                        }
                }
-               $out->addHtml( "</div>" );
 
                if ( $prevnext ) {
                        $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
                }
 
+               $out->addHtml( "</div>" );
+
                Hooks::run( 'SpecialSearchResultsAppend', array( $this, $out ) );
 
        }
@@ -408,8 +406,6 @@ class SpecialSearch extends SpecialPage {
         * @return bool
         */
        protected function shouldRunSuggestedQuery( SearchResultSet $textMatches ) {
-               global $wgSearchRunSuggestedQueryPercent;
-
                if ( !$this->runSuggestion ||
                        !$textMatches->hasSuggestion() ||
                        $textMatches->numRows() > 0 ||
@@ -421,7 +417,7 @@ class SpecialSearch extends SpecialPage {
                // Generate a random number between 0 and 1. If the
                // number is less than the desired percentages run it.
                $rand = rand( 0, getrandmax() ) / getrandmax();
-               return $wgSearchRunSuggestedQueryPercent > $rand;
+               return $this->getConfig()->get( 'SearchRunSuggestedQueryPercent' ) > $rand;
        }
 
        /**
@@ -464,7 +460,7 @@ class SpecialSearch extends SpecialPage {
                // Showing results for '$rewritten'
                // Search instead for '$orig'
 
-               $params = array( 'search' => $textMatches->getSuggestionQuery() );
+               $params = array( 'search' => $textMatches->getQueryAfterRewrite() );
                if ( $this->fulltext != null ) {
                        $params['fulltext'] = $this->fulltext;
                }
@@ -472,7 +468,7 @@ class SpecialSearch extends SpecialPage {
 
                $rewritten = Linker::linkKnown(
                        $this->getPageTitle(),
-                       $textMatches->getSuggestionSnippet() ?: null,
+                       $textMatches->getQueryAfterRewriteSnippet() ?: null,
                        array(),
                        $stParams
                );
@@ -489,7 +485,7 @@ class SpecialSearch extends SpecialPage {
                return Html::rawElement(
                        'div',
                        array( 'class' => 'searchdidyoumean' ),
-                       $this->msg( 'search-rewritten')->rawParams( $rewritten, $original )->escaped()
+                       $this->msg( 'search-rewritten' )->rawParams( $rewritten, $original )->escaped()
                );
        }