MediaWiki  1.34.0
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 }
SearchDatabase\__construct
__construct(ILoadBalancer $lb)
Definition: SearchDatabase.php:46
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:267
SearchEngine\parseNamespacePrefixes
static parseNamespacePrefixes( $query, $withAllKeyword=true, $withPrefixSearchExtractNamespaceHook=false)
Parse some common prefixes: all (search everything) or namespace names.
Definition: SearchEngine.php:378
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:41
SearchDatabase
Base search engine base class for database-backed searches.
Definition: SearchDatabase.php:32
SearchDatabase\doSearchTitle
doSearchTitle( $term)
Definition: SearchDatabase.php:72
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:104
SearchDatabase\doSearchText
doSearchText( $term)
Definition: SearchDatabase.php:56
SearchEngine
Contain a class for special pages.
Definition: SearchEngine.php:34
SearchDatabase\$db
IDatabase $db
(backwards compatibility)
Definition: SearchDatabase.php:36
SearchDatabase\doSearchTextInDB
doSearchTextInDB( $term)
Perform a full text search query and return a result set.
SearchDatabase\$lb
ILoadBalancer $lb
Definition: SearchDatabase.php:34
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:90
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81