36 return $this->db->checkForEnabledSearch();
47 private function parseQuery( $filteredText, $fulltext ) {
50 $this->searchTerms = [];
53 if ( preg_match_all(
'/([-+<>~]?)(([' . $lc .
']+)(\*?)|"[^"]*")/',
54 $filteredText, $m, PREG_SET_ORDER ) ) {
55 foreach ( $m
as $bits ) {
56 Wikimedia\suppressWarnings();
57 list( , $modifier,
$term, $nonQuoted, $wildcard ) = $bits;
58 Wikimedia\restoreWarnings();
60 if ( $nonQuoted !=
'' ) {
68 if ( $searchon !==
'' ) {
74 $convertedVariants = MediaWikiServices::getInstance()->getContentLanguage()->
75 autoConvertToAllVariants(
$term );
76 if ( is_array( $convertedVariants ) ) {
77 $variants = array_unique( array_values( $convertedVariants ) );
79 $variants = [
$term ];
86 $strippedVariants = array_map(
87 [ MediaWikiServices::getInstance()->getContentLanguage(),
88 'normalizeForSearch' ],
94 $strippedVariants = array_unique( $strippedVariants );
96 $searchon .= $modifier;
97 if ( count( $strippedVariants ) > 1 ) {
100 foreach ( $strippedVariants
as $stripped ) {
101 if ( $nonQuoted && strpos( $stripped,
' ' ) !==
false ) {
105 $stripped =
'"' . trim( $stripped ) .
'"';
107 $searchon .=
"$quote$stripped$quote$wildcard ";
109 if ( count( $strippedVariants ) > 1 ) {
116 $this->searchTerms[] = $regexp;
120 wfDebug( __METHOD__ .
": Can't understand search query '{$filteredText}'\n" );
123 $searchon = $this->db->addQuotes( $searchon );
125 return " $field MATCH $searchon ";
129 $regex = preg_quote( $string,
'/' );
130 if ( MediaWikiServices::getInstance()->getContentLanguage()->hasWordBreaks() ) {
135 $regex =
"\b$regex\b";
146 $searchChars = parent::legalSearchChars(
$type );
147 if (
$type === self::CHARS_ALL ) {
149 $searchChars =
"\"*" . $searchChars;
180 $this->
filter( MediaWikiServices::getInstance()->getContentLanguage()->lc(
$term ) );
181 $resultSet = $this->db->query( $this->
getQuery( $filteredTerm, $fulltext ) );
184 $totalResult = $this->db->query( $this->
getCountQuery( $filteredTerm, $fulltext ) );
185 $row = $totalResult->fetchObject();
187 $total = intval( $row->c );
189 $totalResult->free();
200 return ''; # search all
207 return 'AND page_namespace IN (' .
$namespaces .
')';
216 return $this->db->limitResult( $sql, $this->limit, $this->offset );
226 private function getQuery( $filteredTerm, $fulltext ) {
228 $this->
queryMain( $filteredTerm, $fulltext ) .
' ' .
239 return $fulltext ?
'si_text' :
'si_title';
249 private function queryMain( $filteredTerm, $fulltext ) {
250 $match = $this->
parseQuery( $filteredTerm, $fulltext );
251 $page = $this->db->tableName(
'page' );
252 $searchindex = $this->db->tableName(
'searchindex' );
253 return "SELECT $searchindex.rowid, page_namespace, page_title " .
254 "FROM $page,$searchindex " .
255 "WHERE page_id=$searchindex.rowid AND $match";
259 $match = $this->
parseQuery( $filteredTerm, $fulltext );
260 $page = $this->db->tableName(
'page' );
261 $searchindex = $this->db->tableName(
'searchindex' );
262 return "SELECT COUNT(*) AS c " .
263 "FROM $page,$searchindex " .
264 "WHERE page_id=$searchindex.rowid AND $match " .
284 $dbw->delete(
'searchindex', [
'rowid' => $id ], __METHOD__ );
286 $dbw->insert(
'searchindex',
307 $dbw->update(
'searchindex',
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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 SQLite.
getIndexField( $fulltext)
Picks which field to index on, depending on what type of query.
searchInternal( $term, $fulltext)
parseQuery( $filteredText, $fulltext)
Parse the user's query and transform it into an SQL fragment which will become part of a WHERE clause...
fulltextSearchSupported()
Whether fulltext search is supported by current schema.
static legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search NOTE: usage as static is deprecated and preserved only as BC measure.
limitResult( $sql)
Returns a query with limit for number of results set.
update( $id, $title, $text)
Create or update the search index record for the given page.
updateTitle( $id, $title)
Update a search index record's title only.
getCountQuery( $filteredTerm, $fulltext)
doSearchTitleInDB( $term)
Perform a title-only search query and return a result set.
doSearchTextInDB( $term)
Perform a full text search query and return a result set.
queryNamespaces()
Return a partial WHERE clause to limit the search to the given namespaces.
regexTerm( $string, $wildcard)
queryMain( $filteredTerm, $fulltext)
Get the base part of the search query.
getQuery( $filteredTerm, $fulltext)
Construct the full SQL query to do the search.
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php