From cf14ee4acc63ca5481434b919ea1cf03bf36f6e9 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 6 Jan 2014 11:57:08 -0500 Subject: [PATCH] Don't suggest if the search term is a known title Also tell the SearchEngine that we don't *need* the suggestion. Some will make it any way and we'll ignore it. Cirrus will be able to save some time by not building the suggestion. Bug: 59666 Change-Id: Ifd5bafe25a715db9d44cf0fee2ba2607f6c270a2 --- includes/search/SearchEngine.php | 12 ++++++++++++ includes/specials/SpecialSearch.php | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 15569612aa..94d39a576f 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -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 diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 62eeb403c3..9bacc8fd6a 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -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 .. -- 2.20.1