From: Sam Reed Date: Tue, 25 Jan 2011 19:56:58 +0000 (+0000) Subject: Followup r80856, don't unconditionally add the "AND" as if '' is returned by a functi... X-Git-Tag: 1.31.0-rc.0~32365 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=5bdf93c6bc98d069a1fc9a5850137b397e2e0a14;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php index 447b35b8e9..1e35bc0747 100644 --- a/includes/search/SearchMySQL.php +++ b/includes/search/SearchMySQL.php @@ -56,7 +56,7 @@ class SearchMySQL extends SearchEngine { $filteredText, $m, PREG_SET_ORDER ) ) { foreach( $m as $bits ) { @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits; - + if( $nonQuoted != '' ) { $term = $nonQuoted; $quote = ''; @@ -64,13 +64,13 @@ class SearchMySQL extends SearchEngine { $term = str_replace( '"', '', $term ); $quote = '"'; } - + if( $searchon !== '' ) $searchon .= ' '; if( $this->strictMatching && ($modifier == '') ) { // If we leave this out, boolean op defaults to OR which is rarely helpful. $modifier = '+'; } - + // Some languages such as Serbian store the input form in the search index, // so we may need to search for matches in multiple writing system variants. $convertedVariants = $wgContLang->autoConvertToAllVariants( $term ); @@ -79,7 +79,7 @@ class SearchMySQL extends SearchEngine { } else { $variants = array( $term ); } - + // The low-level search index does some processing on input to work // around problems with minimum lengths and encoding in MySQL's // fulltext engine. @@ -87,12 +87,12 @@ class SearchMySQL extends SearchEngine { $strippedVariants = array_map( array( $wgContLang, 'normalizeForSearch' ), $variants ); - + // Some languages such as Chinese force all variants to a canonical // form when stripping to the low-level search index, so to be sure // let's check our variants list for unique items after stripping. $strippedVariants = array_unique( $strippedVariants ); - + $searchon .= $modifier; if( count( $strippedVariants) > 1 ) $searchon .= '('; @@ -108,7 +108,7 @@ class SearchMySQL extends SearchEngine { } if( count( $strippedVariants) > 1 ) $searchon .= ')'; - + // Match individual terms or quoted phrase in result highlighting... // Note that variants will be introduced in a later stage for highlighting! $regexp = $this->regexTerm( $term, $wildcard ); @@ -124,10 +124,10 @@ class SearchMySQL extends SearchEngine { $field = $this->getIndexField( $fulltext ); return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) "; } - + function regexTerm( $string, $wildcard ) { global $wgContLang; - + $regex = preg_quote( $string, '/' ); if( $wgContLang->hasWordBreaks() ) { if( $wildcard ) { @@ -167,13 +167,13 @@ class SearchMySQL extends SearchEngine { function searchTitle( $term ) { return $this->searchInternal( $term, false ); } - + protected function searchInternal( $term, $fulltext ) { global $wgCountTotalSearchHits; - + $filteredTerm = $this->filter( $term ); $resultSet = $this->db->query( $this->getQuery( $filteredTerm, $fulltext ) ); - + $total = null; if( $wgCountTotalSearchHits ) { $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) ); @@ -183,7 +183,7 @@ class SearchMySQL extends SearchEngine { } $totalResult->free(); } - + return new MySQLSearchResultSet( $resultSet, $this->searchTerms, $total ); } @@ -239,13 +239,26 @@ class SearchMySQL extends SearchEngine { * @param $fulltext Boolean */ function getQuery( $filteredTerm, $fulltext ) { - return $this->queryMain( $filteredTerm, $fulltext ) . ' ' . - 'AND ' . $this->queryRedirect() . ' ' . - 'AND ' . $this->queryNamespaces() . ' ' . - $this->queryRanking( $filteredTerm, $fulltext ) . ' ' . + $query = $this->queryMain( $filteredTerm, $fulltext ) . ' '; + + $redir = $this->queryRedirect(); + + if ( $redir ) { + $query .= 'AND ' . $redir . ' '; + } + + $namespace = $this->queryNamespaces(); + + if ( $namespace ) { + $query .= 'AND ' . $namespace . ' '; + } + + $query .= $this->queryRanking( $filteredTerm, $fulltext ) . ' ' . $this->queryLimit(); + + return $query; } - + /** * Picks which field to index on, depending on what type of query. * @param $fulltext Boolean @@ -271,7 +284,7 @@ class SearchMySQL extends SearchEngine { $searchindex = $this->db->tableName( 'searchindex' ); return 'SELECT page_id, page_namespace, page_title ' . "FROM $page,$searchindex " . - 'WHERE page_id=si_page AND ' . $match; + 'WHERE page_id=si_page ' . $match; } function getCountQuery( $filteredTerm, $fulltext ) { @@ -315,7 +328,7 @@ class SearchMySQL extends SearchEngine { * @param $id Integer * @param $title String */ - function updateTitle( $id, $title ) { + function updateTitle( $id, $title ) { $dbw = wfGetDB( DB_MASTER ); $dbw->update( 'searchindex', @@ -333,7 +346,7 @@ class SearchMySQL extends SearchEngine { global $wgContLang; wfProfileIn( __METHOD__ ); - + $out = parent::normalizeText( $string ); // MySQL fulltext index doesn't grok utf-8, so we @@ -367,7 +380,7 @@ class SearchMySQL extends SearchEngine { $out ); wfProfileOut( __METHOD__ ); - + return $out; }