$filteredText, $m, PREG_SET_ORDER ) ) {
foreach( $m as $bits ) {
@list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
-
+
if( $nonQuoted != '' ) {
$term = $nonQuoted;
$quote = '';
$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 );
} 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.
$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 .= '(';
}
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 );
$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 ) {
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 ) );
}
$totalResult->free();
}
-
+
return new MySQLSearchResultSet( $resultSet, $this->searchTerms, $total );
}
* @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
$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 ) {
* @param $id Integer
* @param $title String
*/
- function updateTitle( $id, $title ) {
+ function updateTitle( $id, $title ) {
$dbw = wfGetDB( DB_MASTER );
$dbw->update( 'searchindex',
global $wgContLang;
wfProfileIn( __METHOD__ );
-
+
$out = parent::normalizeText( $string );
// MySQL fulltext index doesn't grok utf-8, so we
$out );
wfProfileOut( __METHOD__ );
-
+
return $out;
}