MediaWiki REL1_34
SearchDatabase.php
Go to the documentation of this file.
1<?php
26
32abstract 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}
Base search engine base class for database-backed searches.
__construct(ILoadBalancer $lb)
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...
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:38
Database cluster connection, tracking, load balancing, and transaction manager interface.
getLazyConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index.
const DB_REPLICA
Definition defines.php:25