r80982 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80981‎ | r80982 | r80983 >
Date:19:56, 25 January 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Followup r80856, don't unconditionally add the "AND" as if '' is returned by a function, we can get some silly errors (Yay for crappily built SQL strings)

Remove trailing whitespace
Modified paths:
  • /trunk/phase3/includes/search/SearchMySQL.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/search/SearchMySQL.php
@@ -56,7 +56,7 @@
5757 $filteredText, $m, PREG_SET_ORDER ) ) {
5858 foreach( $m as $bits ) {
5959 @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
60 -
 60+
6161 if( $nonQuoted != '' ) {
6262 $term = $nonQuoted;
6363 $quote = '';
@@ -64,13 +64,13 @@
6565 $term = str_replace( '"', '', $term );
6666 $quote = '"';
6767 }
68 -
 68+
6969 if( $searchon !== '' ) $searchon .= ' ';
7070 if( $this->strictMatching && ($modifier == '') ) {
7171 // If we leave this out, boolean op defaults to OR which is rarely helpful.
7272 $modifier = '+';
7373 }
74 -
 74+
7575 // Some languages such as Serbian store the input form in the search index,
7676 // so we may need to search for matches in multiple writing system variants.
7777 $convertedVariants = $wgContLang->autoConvertToAllVariants( $term );
@@ -79,7 +79,7 @@
8080 } else {
8181 $variants = array( $term );
8282 }
83 -
 83+
8484 // The low-level search index does some processing on input to work
8585 // around problems with minimum lengths and encoding in MySQL's
8686 // fulltext engine.
@@ -87,12 +87,12 @@
8888 $strippedVariants = array_map(
8989 array( $wgContLang, 'normalizeForSearch' ),
9090 $variants );
91 -
 91+
9292 // Some languages such as Chinese force all variants to a canonical
9393 // form when stripping to the low-level search index, so to be sure
9494 // let's check our variants list for unique items after stripping.
9595 $strippedVariants = array_unique( $strippedVariants );
96 -
 96+
9797 $searchon .= $modifier;
9898 if( count( $strippedVariants) > 1 )
9999 $searchon .= '(';
@@ -108,7 +108,7 @@
109109 }
110110 if( count( $strippedVariants) > 1 )
111111 $searchon .= ')';
112 -
 112+
113113 // Match individual terms or quoted phrase in result highlighting...
114114 // Note that variants will be introduced in a later stage for highlighting!
115115 $regexp = $this->regexTerm( $term, $wildcard );
@@ -124,10 +124,10 @@
125125 $field = $this->getIndexField( $fulltext );
126126 return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) ";
127127 }
128 -
 128+
129129 function regexTerm( $string, $wildcard ) {
130130 global $wgContLang;
131 -
 131+
132132 $regex = preg_quote( $string, '/' );
133133 if( $wgContLang->hasWordBreaks() ) {
134134 if( $wildcard ) {
@@ -167,13 +167,13 @@
168168 function searchTitle( $term ) {
169169 return $this->searchInternal( $term, false );
170170 }
171 -
 171+
172172 protected function searchInternal( $term, $fulltext ) {
173173 global $wgCountTotalSearchHits;
174 -
 174+
175175 $filteredTerm = $this->filter( $term );
176176 $resultSet = $this->db->query( $this->getQuery( $filteredTerm, $fulltext ) );
177 -
 177+
178178 $total = null;
179179 if( $wgCountTotalSearchHits ) {
180180 $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) );
@@ -183,7 +183,7 @@
184184 }
185185 $totalResult->free();
186186 }
187 -
 187+
188188 return new MySQLSearchResultSet( $resultSet, $this->searchTerms, $total );
189189 }
190190
@@ -239,13 +239,26 @@
240240 * @param $fulltext Boolean
241241 */
242242 function getQuery( $filteredTerm, $fulltext ) {
243 - return $this->queryMain( $filteredTerm, $fulltext ) . ' ' .
244 - 'AND ' . $this->queryRedirect() . ' ' .
245 - 'AND ' . $this->queryNamespaces() . ' ' .
246 - $this->queryRanking( $filteredTerm, $fulltext ) . ' ' .
 243+ $query = $this->queryMain( $filteredTerm, $fulltext ) . ' ';
 244+
 245+ $redir = $this->queryRedirect();
 246+
 247+ if ( $redir ) {
 248+ $query .= 'AND ' . $redir . ' ';
 249+ }
 250+
 251+ $namespace = $this->queryNamespaces();
 252+
 253+ if ( $namespace ) {
 254+ $query .= 'AND ' . $namespace . ' ';
 255+ }
 256+
 257+ $query .= $this->queryRanking( $filteredTerm, $fulltext ) . ' ' .
247258 $this->queryLimit();
 259+
 260+ return $query;
248261 }
249 -
 262+
250263 /**
251264 * Picks which field to index on, depending on what type of query.
252265 * @param $fulltext Boolean
@@ -271,7 +284,7 @@
272285 $searchindex = $this->db->tableName( 'searchindex' );
273286 return 'SELECT page_id, page_namespace, page_title ' .
274287 "FROM $page,$searchindex " .
275 - 'WHERE page_id=si_page AND ' . $match;
 288+ 'WHERE page_id=si_page ' . $match;
276289 }
277290
278291 function getCountQuery( $filteredTerm, $fulltext ) {
@@ -315,7 +328,7 @@
316329 * @param $id Integer
317330 * @param $title String
318331 */
319 - function updateTitle( $id, $title ) {
 332+ function updateTitle( $id, $title ) {
320333 $dbw = wfGetDB( DB_MASTER );
321334
322335 $dbw->update( 'searchindex',
@@ -333,7 +346,7 @@
334347 global $wgContLang;
335348
336349 wfProfileIn( __METHOD__ );
337 -
 350+
338351 $out = parent::normalizeText( $string );
339352
340353 // MySQL fulltext index doesn't grok utf-8, so we
@@ -367,7 +380,7 @@
368381 $out );
369382
370383 wfProfileOut( __METHOD__ );
371 -
 384+
372385 return $out;
373386 }
374387

Follow-up revisions

RevisionCommit summaryAuthorDate
r80983Fix r80982, re-add accidental removed AND during debuggingreedy19:58, 25 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r80856Start another attack on raw sql queriesreedy13:59, 24 January 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   20:08, 25 January 2011

Resolves bugzilla:26940

Note for future -- watch out for stray whitespace changes that make commits harder to check.

Status & tagging log