From 85b6e95beae0e37f65e39015d94df832ce1bde80 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 20 Sep 2006 14:38:32 +0000 Subject: [PATCH] merge r16576 from SerbianVariants branch; should fix 'go' variant search on non-default search (Lucene) --- includes/SearchEngine.php | 86 +++++++++++++++++++++----------------- includes/SpecialSearch.php | 13 ------ 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index 6af1e41596..5e598883fe 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -50,62 +50,72 @@ class SearchEngine { * @return Title * @private */ - function getNearMatch( $term ) { + function getNearMatch( $searchterm ) { global $wgContLang; - # Exact match? No need to look further. - $title = Title::newFromText( $term ); - if (is_null($title)) - return NULL; - if ( $title->getNamespace() == NS_SPECIAL || $title->exists() ) { - return $title; - } + $allSearchTerms = array($searchterm); - # Now try all lower case (i.e. first letter capitalized) - # - $title = Title::newFromText( $wgContLang->lc( $term ) ); - if ( $title->exists() ) { - return $title; + if($wgContLang->hasVariants()){ + $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm)); } - # Now try capitalized string - # - $title = Title::newFromText( $wgContLang->ucwords( $term ) ); - if ( $title->exists() ) { - return $title; - } + foreach($allSearchTerms as $term){ - # Now try all upper case - # - $title = Title::newFromText( $wgContLang->uc( $term ) ); - if ( $title->exists() ) { - return $title; - } + # Exact match? No need to look further. + $title = Title::newFromText( $term ); + if (is_null($title)) + return NULL; - # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc - $title = Title::newFromText( $wgContLang->ucwordbreaks($term) ); - if ( $title->exists() ) { - return $title; - } + if ( $title->getNamespace() == NS_SPECIAL || $title->exists() ) { + return $title; + } - global $wgCapitalLinks, $wgContLang; - if( !$wgCapitalLinks ) { - // Catch differs-by-first-letter-case-only - $title = Title::newFromText( $wgContLang->ucfirst( $term ) ); + # Now try all lower case (i.e. first letter capitalized) + # + $title = Title::newFromText( $wgContLang->lc( $term ) ); if ( $title->exists() ) { return $title; } - $title = Title::newFromText( $wgContLang->lcfirst( $term ) ); + + # Now try capitalized string + # + $title = Title::newFromText( $wgContLang->ucwords( $term ) ); + if ( $title->exists() ) { + return $title; + } + + # Now try all upper case + # + $title = Title::newFromText( $wgContLang->uc( $term ) ); if ( $title->exists() ) { return $title; } + + # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc + $title = Title::newFromText( $wgContLang->ucwordbreaks($term) ); + if ( $title->exists() ) { + return $title; + } + + global $wgCapitalLinks, $wgContLang; + if( !$wgCapitalLinks ) { + // Catch differs-by-first-letter-case-only + $title = Title::newFromText( $wgContLang->ucfirst( $term ) ); + if ( $title->exists() ) { + return $title; + } + $title = Title::newFromText( $wgContLang->lcfirst( $term ) ); + if ( $title->exists() ) { + return $title; + } + } } - $title = Title::newFromText( $term ); + $title = Title::newFromText( $searchterm ); # Entering an IP address goes to the contributions page if ( ( $title->getNamespace() == NS_USER && User::isIP($title->getText() ) ) - || User::isIP( trim( $term ) ) ) { + || User::isIP( trim( $searchterm ) ) ) { return Title::makeTitle( NS_SPECIAL, "Contributions/" . $title->getDbkey() ); } @@ -116,7 +126,7 @@ class SearchEngine { } # Quoted term? Try without the quotes... - if( preg_match( '/^"([^"]+)"$/', $term, $matches ) ) { + if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) { return SearchEngine::getNearMatch( $matches[1] ); } diff --git a/includes/SpecialSearch.php b/includes/SpecialSearch.php index a479182fad..057b487cae 100644 --- a/includes/SpecialSearch.php +++ b/includes/SpecialSearch.php @@ -97,19 +97,6 @@ class SpecialSearch { return; } - # if language supports variants, search in all variants - if($wgContLang->hasVariants()){ - $allTermVariants = $wgContLang->convertLinkToAllVariants($term); - - foreach($allTermVariants as $termVariant){ - $t = SearchEngine::getNearMatch( $termVariant ); - if( !is_null( $t ) ) { - $wgOut->redirect( $t->getFullURL() ); - return; - } - } - } - # No match, generate an edit URL $t = Title::newFromText( $term ); if( is_null( $t ) ) { -- 2.20.1