r16578 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16577‎ | r16578 | r16579 >
Date:14:38, 20 September 2006
Author:brion
Status:old
Tags:
Comment:
merge r16576 from SerbianVariants branch; should fix 'go' variant search on non-default search (Lucene)
Modified paths:
  • /trunk/phase3/includes/SearchEngine.php (modified) (history)
  • /trunk/phase3/includes/SpecialSearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SearchEngine.php
@@ -50,62 +50,72 @@
5151 * @return Title
5252 * @private
5353 */
54 - function getNearMatch( $term ) {
 54+ function getNearMatch( $searchterm ) {
5555 global $wgContLang;
56 - # Exact match? No need to look further.
57 - $title = Title::newFromText( $term );
58 - if (is_null($title))
59 - return NULL;
6056
61 - if ( $title->getNamespace() == NS_SPECIAL || $title->exists() ) {
62 - return $title;
63 - }
 57+ $allSearchTerms = array($searchterm);
6458
65 - # Now try all lower case (i.e. first letter capitalized)
66 - #
67 - $title = Title::newFromText( $wgContLang->lc( $term ) );
68 - if ( $title->exists() ) {
69 - return $title;
 59+ if($wgContLang->hasVariants()){
 60+ $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm));
7061 }
7162
72 - # Now try capitalized string
73 - #
74 - $title = Title::newFromText( $wgContLang->ucwords( $term ) );
75 - if ( $title->exists() ) {
76 - return $title;
77 - }
 63+ foreach($allSearchTerms as $term){
7864
79 - # Now try all upper case
80 - #
81 - $title = Title::newFromText( $wgContLang->uc( $term ) );
82 - if ( $title->exists() ) {
83 - return $title;
84 - }
 65+ # Exact match? No need to look further.
 66+ $title = Title::newFromText( $term );
 67+ if (is_null($title))
 68+ return NULL;
8569
86 - # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
87 - $title = Title::newFromText( $wgContLang->ucwordbreaks($term) );
88 - if ( $title->exists() ) {
89 - return $title;
90 - }
 70+ if ( $title->getNamespace() == NS_SPECIAL || $title->exists() ) {
 71+ return $title;
 72+ }
9173
92 - global $wgCapitalLinks, $wgContLang;
93 - if( !$wgCapitalLinks ) {
94 - // Catch differs-by-first-letter-case-only
95 - $title = Title::newFromText( $wgContLang->ucfirst( $term ) );
 74+ # Now try all lower case (i.e. first letter capitalized)
 75+ #
 76+ $title = Title::newFromText( $wgContLang->lc( $term ) );
9677 if ( $title->exists() ) {
9778 return $title;
9879 }
99 - $title = Title::newFromText( $wgContLang->lcfirst( $term ) );
 80+
 81+ # Now try capitalized string
 82+ #
 83+ $title = Title::newFromText( $wgContLang->ucwords( $term ) );
10084 if ( $title->exists() ) {
10185 return $title;
10286 }
 87+
 88+ # Now try all upper case
 89+ #
 90+ $title = Title::newFromText( $wgContLang->uc( $term ) );
 91+ if ( $title->exists() ) {
 92+ return $title;
 93+ }
 94+
 95+ # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
 96+ $title = Title::newFromText( $wgContLang->ucwordbreaks($term) );
 97+ if ( $title->exists() ) {
 98+ return $title;
 99+ }
 100+
 101+ global $wgCapitalLinks, $wgContLang;
 102+ if( !$wgCapitalLinks ) {
 103+ // Catch differs-by-first-letter-case-only
 104+ $title = Title::newFromText( $wgContLang->ucfirst( $term ) );
 105+ if ( $title->exists() ) {
 106+ return $title;
 107+ }
 108+ $title = Title::newFromText( $wgContLang->lcfirst( $term ) );
 109+ if ( $title->exists() ) {
 110+ return $title;
 111+ }
 112+ }
103113 }
104114
105 - $title = Title::newFromText( $term );
 115+ $title = Title::newFromText( $searchterm );
106116
107117 # Entering an IP address goes to the contributions page
108118 if ( ( $title->getNamespace() == NS_USER && User::isIP($title->getText() ) )
109 - || User::isIP( trim( $term ) ) ) {
 119+ || User::isIP( trim( $searchterm ) ) ) {
110120 return Title::makeTitle( NS_SPECIAL, "Contributions/" . $title->getDbkey() );
111121 }
112122
@@ -116,7 +126,7 @@
117127 }
118128
119129 # Quoted term? Try without the quotes...
120 - if( preg_match( '/^"([^"]+)"$/', $term, $matches ) ) {
 130+ if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) {
121131 return SearchEngine::getNearMatch( $matches[1] );
122132 }
123133
Index: trunk/phase3/includes/SpecialSearch.php
@@ -97,19 +97,6 @@
9898 return;
9999 }
100100
101 - # if language supports variants, search in all variants
102 - if($wgContLang->hasVariants()){
103 - $allTermVariants = $wgContLang->convertLinkToAllVariants($term);
104 -
105 - foreach($allTermVariants as $termVariant){
106 - $t = SearchEngine::getNearMatch( $termVariant );
107 - if( !is_null( $t ) ) {
108 - $wgOut->redirect( $t->getFullURL() );
109 - return;
110 - }
111 - }
112 - }
113 -
114101 # No match, generate an edit URL
115102 $t = Title::newFromText( $term );
116103 if( is_null( $t ) ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r16576Moved variant search magic to getNearMatch().rainman12:04, 20 September 2006