47 private function parseQuery( $filteredText, $fulltext ) {
50 $this->searchTerms = [];
52 # @todo FIXME: This doesn't handle parenthetical expressions.
54 if ( preg_match_all(
'/([-+<>~]?)(([' . $lc .
']+)(\*?)|"[^"]*")/',
55 $filteredText, $m, PREG_SET_ORDER ) ) {
56 foreach ( $m as $bits ) {
57 Wikimedia\suppressWarnings();
58 list( , $modifier,
$term, $nonQuoted, $wildcard ) = $bits;
59 Wikimedia\restoreWarnings();
61 if ( $nonQuoted !=
'' ) {
69 if ( $searchon !==
'' ) {
72 if ( $this->strictMatching && ( $modifier ==
'' ) ) {
79 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
80 $convertedVariants = $contLang->autoConvertToAllVariants(
$term );
81 if ( is_array( $convertedVariants ) ) {
82 $variants = array_unique( array_values( $convertedVariants ) );
84 $variants = [
$term ];
91 $strippedVariants = array_map( [ $contLang,
'normalizeForSearch' ], $variants );
96 $strippedVariants = array_unique( $strippedVariants );
98 $searchon .= $modifier;
99 if ( count( $strippedVariants ) > 1 ) {
102 foreach ( $strippedVariants as $stripped ) {
104 if ( $nonQuoted && strpos( $stripped,
' ' ) !==
false ) {
108 $stripped =
'"' . trim( $stripped ) .
'"';
110 $searchon .=
"$quote$stripped$quote$wildcard ";
112 if ( count( $strippedVariants ) > 1 ) {
119 $this->searchTerms[] = $regexp;
121 wfDebug( __METHOD__ .
": Would search with '$searchon'\n" );
122 wfDebug( __METHOD__ .
': Match with /' . implode(
'|', $this->searchTerms ) .
"/\n" );
124 wfDebug( __METHOD__ .
": Can't understand search query '{$filteredText}'\n" );
127 $searchon = $this->db->addQuotes( $searchon );
130 " MATCH($field) AGAINST($searchon IN BOOLEAN MODE) ",
131 " MATCH($field) AGAINST($searchon IN NATURAL LANGUAGE MODE) DESC "
136 $regex = preg_quote( $string,
'/' );
137 if ( MediaWikiServices::getInstance()->getContentLanguage()->hasWordBreaks() ) {
142 $regex =
"\b$regex\b";
153 $searchChars = parent::legalSearchChars(
$type );
154 if (
$type === self::CHARS_ALL ) {
156 $searchChars =
"\"*" . $searchChars;
183 if ( trim(
$term ) ===
'' ) {
189 $resultSet = $this->db->select(
196 $totalResult = $this->db->select(
201 $row = $totalResult->fetchObject();
203 $total = intval( $row->c );
205 $totalResult->free();
211 switch ( $feature ) {
212 case 'title-suffix-filter':
215 return parent::supports( $feature );
225 foreach ( $this->features as $feature =>
$value ) {
226 if ( $feature ===
'title-suffix-filter' &&
$value ) {
227 $query[
'conds'][] =
'page_title' . $this->db->buildLike( $this->db->anyString(),
$value );
264 private function getQuery( $filteredTerm, $fulltext ) {
287 return $fulltext ?
'si_text' :
'si_title';
299 $match = $this->
parseQuery( $filteredTerm, $fulltext );
300 $query[
'tables'][] =
'page';
301 $query[
'tables'][] =
'searchindex';
302 $query[
'fields'][] =
'page_id';
303 $query[
'fields'][] =
'page_namespace';
304 $query[
'fields'][] =
'page_title';
305 $query[
'conds'][] =
'page_id=si_page';
306 $query[
'conds'][] = $match[0];
307 $query[
'options'][
'ORDER BY'] = $match[1];
317 $match = $this->
parseQuery( $filteredTerm, $fulltext );
320 'tables' => [
'page',
'searchindex' ],
321 'fields' => [
'COUNT(*) as c' ],
322 'conds' => [
'page_id=si_page', $match[0] ],
343 $dbw->replace(
'searchindex',
362 $dbw->update(
'searchindex',
364 [
'si_page' => $id ],
366 [ $dbw->lowPriorityOption() ] );
379 $dbw->delete(
'searchindex', [
'si_page' => $id ], __METHOD__ );
389 $out = parent::normalizeText( $string );
393 $out = preg_replace_callback(
394 "/([\\xc0-\\xff][\\x80-\\xbf]*)/",
395 [ $this,
'stripForSearchCallback' ],
396 MediaWikiServices::getInstance()->getContentLanguage()->lc(
$out ) );
402 if ( $minLength > 1 ) {
431 return 'u8' . bin2hex(
$matches[1] );
441 if ( is_null( self::$mMinSearchLength ) ) {
442 $sql =
"SHOW GLOBAL VARIABLES LIKE 'ft\\_min\\_word\\_len'";
445 $result =
$dbr->query( $sql, __METHOD__ );
446 $row = $result->fetchObject();
449 if ( $row && $row->Variable_name ==
'ft_min_word_len' ) {
450 self::$mMinSearchLength = intval( $row->Value );
452 self::$mMinSearchLength = 0;
to move a page</td >< td > &*You are moving the page across namespaces
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Base search engine base class for database-backed searches.
filter( $text)
Return a 'cleaned up' search string.
Search engine hook for MySQL 4+.
parseQuery( $filteredText, $fulltext)
Parse the user's query and transform it into two SQL fragments: a WHERE condition and an ORDER BY exp...
queryMain(&$query, $filteredTerm, $fulltext)
Get the base part of the search query.
static legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search NOTE: usage as static is deprecated and preserved only as BC measure.
updateTitle( $id, $title)
Update a search index record's title only.
doSearchTitleInDB( $term)
Perform a title-only search query and return a result set.
getQuery( $filteredTerm, $fulltext)
Construct the SQL query to do the search.
stripForSearchCallback( $matches)
Armor a case-folded UTF-8 string to get through MySQL's fulltext search without being mucked up by fu...
getIndexField( $fulltext)
Picks which field to index on, depending on what type of query.
queryFeatures(&$query)
Add special conditions.
update( $id, $title, $text)
Create or update the search index record for the given page.
searchInternal( $term, $fulltext)
limitResult(&$query)
Add limit options.
regexTerm( $string, $wildcard)
queryNamespaces(&$query)
Add namespace conditions.
getCountQuery( $filteredTerm, $fulltext)
normalizeText( $string)
Converts some characters for MySQL's indexing to grok it correctly, and pads short words to overcome ...
minSearchLength()
Check MySQL server's ft_min_word_len setting so we know if we need to pad short words....
doSearchTextInDB( $term)
Perform a full text search query and return a result set.
This class is used for different SQL-based search engines shipped with MediaWiki.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
For QUnit the mediawiki tests qunit testrunner dependency will be added to any module whereas SearchGetNearMatch runs after $term
namespace and then decline to actually register it file or subcat img or subcat $title
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query