MediaWiki REL1_35
SearchDatabase.php
Go to the documentation of this file.
1<?php
26
33abstract 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}
Base search engine base class for database-backed searches Stable to extend.
__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 Stable to extend.
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