Turn $wgSearchRunSuggestedQueryPercent into $wgSearchRunSuggestedQuery
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index af2dc94..3f67e93 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 );
                        }
@@ -369,14 +366,14 @@ class SpecialSearch extends SpecialPage {
                                $out->wrapWikiMsg( "==$1==\n", 'textmatches' );
                        }
 
-                       // show interwiki results if any
-                       if ( $textMatches->hasInterwikiResults() ) {
-                               $out->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
-                       }
                        // show results
                        if ( $numTextMatches > 0 ) {
                                $out->addHTML( $this->showMatches( $textMatches ) );
                        }
+                       // show interwiki results if any
+                       if ( $textMatches->hasInterwikiResults() ) {
+                               $out->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
+                       }
 
                        $textMatches->free();
                }
@@ -391,6 +388,7 @@ class SpecialSearch extends SpecialPage {
                        }
                }
 
+               $out->addHTML( '<div class="visualClear"></div>' );
                if ( $prevnext ) {
                        $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
                }
@@ -417,10 +415,7 @@ class SpecialSearch extends SpecialPage {
                        return false;
                }
 
-               // 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 $this->getConfig()->get( 'SearchRunSuggestedQueryPercent' ) > $rand;
+               return $this->getConfig()->get( 'SearchRunSuggestedQuery' );
        }
 
        /**
@@ -438,7 +433,7 @@ class SpecialSearch extends SpecialPage {
                $suggest = Linker::linkKnown(
                        $this->getPageTitle(),
                        $textMatches->getSuggestionSnippet() ?: null,
-                       array(),
+                       array( 'id' => 'mw-search-DYM-suggestion' ),
                        $stParams
                );
 
@@ -463,7 +458,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;
                }
@@ -471,8 +466,8 @@ class SpecialSearch extends SpecialPage {
 
                $rewritten = Linker::linkKnown(
                        $this->getPageTitle(),
-                       $textMatches->getSuggestionSnippet() ?: null,
-                       array(),
+                       $textMatches->getQueryAfterRewriteSnippet() ?: null,
+                       array( 'id' => 'mw-search-DYM-rewritten' ),
                        $stParams
                );
 
@@ -481,7 +476,7 @@ class SpecialSearch extends SpecialPage {
                $original = Linker::linkKnown(
                        $this->getPageTitle(),
                        htmlspecialchars( $term ),
-                       array(),
+                       array( 'id' => 'mw-search-DYM-original' ),
                        $stParams
                );