MediaWiki  master
SearchDatabase.php
Go to the documentation of this file.
1 <?php
26 
32 abstract class SearchDatabase extends SearchEngine {
34  protected $lb;
36  protected $db;
37 
41  protected $searchTerms = [];
42 
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  }
51 
56  final public function doSearchText( $term ) {
57  return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) );
58  }
59 
66  abstract protected function doSearchTextInDB( $term );
67 
72  final public function doSearchTitle( $term ) {
73  return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) );
74  }
75 
82  abstract protected function doSearchTitleInDB( $term );
83 
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  }
97 
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)
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.
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.
const DB_REPLICA
Definition: defines.php:25
ILoadBalancer $lb