MediaWiki  master
SearchDatabase.php
Go to the documentation of this file.
1 <?php
26 
33 abstract class SearchDatabase extends SearchEngine {
35  protected $lb;
37  protected $db;
38 
42  protected $searchTerms = [];
43 
47  public function __construct( ILoadBalancer $lb ) {
48  $this->lb = $lb;
49  // @TODO: remove this deprecated field in 1.35
50  $this->db = $lb->getConnectionRef( DB_REPLICA ); // b/c
51  }
52 
57  final public function doSearchText( $term ) {
58  return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) );
59  }
60 
67  abstract protected function doSearchTextInDB( $term );
68 
73  final public function doSearchTitle( $term ) {
74  return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) );
75  }
76 
83  abstract protected function doSearchTitleInDB( $term );
84 
91  protected function filter( $text ) {
92  // List of chars allowed in the search query.
93  // This must include chars used in the search syntax.
94  // Usually " (phrase) or * (wildcards) if supported by the engine
95  $lc = $this->legalSearchChars( self::CHARS_ALL );
96  return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
97  }
98 
105  final protected function extractNamespacePrefix( $term ) {
106  $queryAndNs = self::parseNamespacePrefixes( $term );
107  if ( $queryAndNs === false ) {
108  return $term;
109  }
110  $this->namespaces = $queryAndNs[1];
111  return $queryAndNs[0];
112  }
113 }
Base search engine base class for database-backed searches.
__construct(ILoadBalancer $lb)
doSearchTitle( $term)
doSearchTextInDB( $term)
Perform a full text search query and return a result set.
string[] $searchTerms
search terms
filter( $text)
Return a 'cleaned up' search string.
doSearchTitleInDB( $term)
Perform a title-only search query and return a result set.
extractNamespacePrefix( $term)
Extract the optional namespace prefix and set self::namespaces accordingly and return the query strin...
doSearchText( $term)
IDatabase $db
(backwards compatibility)
ILoadBalancer $lb
Contain a class for special pages.
static parseNamespacePrefixes( $query, $withAllKeyword=true, $withPrefixSearchExtractNamespaceHook=false)
Parse some common prefixes: all (search everything) or namespace names.
legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
Create and track the database connections and transactions for a given database cluster.
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)
const DB_REPLICA
Definition: defines.php:26