From 6e63f4cbad2a4a3d6a49fc8bfb5fcd32167a888f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 31 Jan 2008 20:51:42 +0000 Subject: [PATCH] Add SearchGetNearMatch hook, have TitleKey provide a case-insensitive exact match for "go" searches. --- docs/hooks.txt | 4 ++++ includes/SearchEngine.php | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index bca4439da9..fb9517a268 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -844,6 +844,10 @@ $namespace : Page namespace $title : Page title $text : Current text being indexed +'SearchGetNearMatch': An extra chance for exact-title-matches in "go" searches +$term : Search term string +&$title : Outparam; set to $title object and return false for a match + 'ShowRawCssJs': Customise the output of raw CSS and JavaScript in page views $text: Text being shown $title: Title of the custom script/stylesheet page diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index 9120da5312..c25b9bdb28 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -51,7 +51,7 @@ class SearchEngine { if($wgContLang->hasVariants()){ $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm)); } - + foreach($allSearchTerms as $term){ # Exact match? No need to look further. @@ -102,6 +102,12 @@ class SearchEngine { return $title; } } + + // Give hooks a chance at better match variants + $title = null; + if( !wfRunHooks( 'SearchGetNearMatch', array( $term, &$title ) ) ) { + return $title; + } } $title = Title::newFromText( $searchterm ); -- 2.20.1