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->getLazyConnectionRef( 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 }
SearchDatabase\__construct
__construct(ILoadBalancer $lb)
Definition: SearchDatabase.php:47
Wikimedia\Rdbms\ILoadBalancer\getLazyConnectionRef
getLazyConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index.
SearchEngine\legalSearchChars
legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search.
Definition: SearchEngine.php:286
SearchEngine\parseNamespacePrefixes
static parseNamespacePrefixes( $query, $withAllKeyword=true, $withPrefixSearchExtractNamespaceHook=false)
Parse some common prefixes: all (search everything) or namespace names.
Definition: SearchEngine.php:399
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
SearchDatabase\$searchTerms
string[] $searchTerms
search terms
Definition: SearchDatabase.php:42
SearchDatabase
Base search engine base class for database-backed searches Stable to extend.
Definition: SearchDatabase.php:33
SearchDatabase\doSearchTitle
doSearchTitle( $term)
Definition: SearchDatabase.php:73
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
SearchDatabase\extractNamespacePrefix
extractNamespacePrefix( $term)
Extract the optional namespace prefix and set self::namespaces accordingly and return the query strin...
Definition: SearchDatabase.php:105
SearchDatabase\doSearchText
doSearchText( $term)
Definition: SearchDatabase.php:57
SearchEngine
Contain a class for special pages Stable to extend.
Definition: SearchEngine.php:37
SearchDatabase\$db
IDatabase $db
(backwards compatibility)
Definition: SearchDatabase.php:37
SearchDatabase\doSearchTextInDB
doSearchTextInDB( $term)
Perform a full text search query and return a result set.
SearchDatabase\$lb
ILoadBalancer $lb
Definition: SearchDatabase.php:35
SearchDatabase\doSearchTitleInDB
doSearchTitleInDB( $term)
Perform a title-only search query and return a result set.
SearchDatabase\filter
filter( $text)
Return a 'cleaned up' search string.
Definition: SearchDatabase.php:91
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81