MediaWiki  master
Go to the documentation of this file.
1 <?php
32 abstract class SearchDatabase extends SearchEngine {
34  protected $lb;
36  protected $db;
41  protected $searchTerms = [];
46  public function __construct( ILoadBalancer $lb ) {
47  $this->lb = $lb;
48  // @TODO: remove this deprecated field in 1.35
49  $this->db = $lb->getLazyConnectionRef( DB_REPLICA ); // b/c
50  }
56  final public function doSearchText( $term ) {
57  return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) );
58  }
66  abstract protected function doSearchTextInDB( $term );
72  final public function doSearchTitle( $term ) {
73  return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) );
74  }
82  abstract protected function doSearchTitleInDB( $term );
90  protected function filter( $text ) {
91  // List of chars allowed in the search query.
92  // This must include chars used in the search syntax.
93  // Usually " (phrase) or * (wildcards) if supported by the engine
94  $lc = $this->legalSearchChars( self::CHARS_ALL );
95  return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
96  }
104  final protected function extractNamespacePrefix( $term ) {
105  $queryAndNs = self::parseNamespacePrefixes( $term );
106  if ( $queryAndNs === false ) {
107  return $term;
108  }
109  $this->namespaces = $queryAndNs[1];
110  return $queryAndNs[0];
111  }
112 }
IDatabase $db
(backwards compatibility)
whereas SearchGetNearMatch runs after $term
Definition: hooks.txt:2862
to move a page</td >< td > &*You are moving the page across namespaces
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
doSearchText( $term)
getLazyConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index...
doSearchTitle( $term)
__construct(ILoadBalancer $lb)
legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search.
string [] $searchTerms
search terms
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.
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
Definition: injection.txt:35
Database cluster connection, tracking, load balancing, and transaction manager interface.
filter( $text)
Return a &#39;cleaned up&#39; search string.
extractNamespacePrefix( $term)
Extract the optional namespace prefix and set self::namespaces accordingly and return the query strin...
Base search engine base class for database-backed searches.
Definition: defines.php:25
ILoadBalancer $lb