Merge "Don't suggest if the search term is a known title"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 8 Jan 2014 18:19:33 +0000 (18:19 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 8 Jan 2014 18:19:33 +0000 (18:19 +0000)
includes/search/SearchEngine.php
includes/specials/SpecialSearch.php

index 1556961..94d39a5 100644 (file)
@@ -36,6 +36,7 @@ class SearchEngine {
        var $searchTerms = array();
        var $namespaces = array( NS_MAIN );
        var $showRedirects = false;
+       protected $showSuggestion = true;
 
        /// Feature values
        protected $features = array();
@@ -304,6 +305,17 @@ class SearchEngine {
                $this->namespaces = $namespaces;
        }
 
+       /**
+        * Set whether the searcher should try to build a suggestion.  Note: some searchers
+        * don't support building a suggestion in the first place and others don't respect
+        * this flag.
+        *
+        * @param boolean $showSuggestion should the searcher try to build suggestions
+        */
+       function setShowSuggestion( $showSuggestion ) {
+               $this->showSuggestion = $showSuggestion;
+       }
+
        /**
         * Parse some common prefixes: all (search everything)
         * or namespace names
index 62eeb40..9bacc8f 100644 (file)
@@ -253,6 +253,8 @@ class SpecialSearch extends SpecialPage {
                }
 
                $t = Title::newFromText( $term );
+               $showSuggestion = $t === null || !$t->isKnown();
+               $search->setShowSuggestion( $showSuggestion );
 
                // fetch search results
                $rewritten = $search->replacePrefixes( $term );
@@ -269,7 +271,7 @@ class SpecialSearch extends SpecialPage {
                }
 
                // did you mean... suggestions
-               if ( $textMatches && !$textStatus && $textMatches->hasSuggestion() ) {
+               if ( $showSuggestion && $textMatches && !$textStatus && $textMatches->hasSuggestion() ) {
                        $st = SpecialPage::getTitleFor( 'Search' );
 
                        # mirror Go/Search behavior of original request ..