MediaWiki  master
SearchDatabase.php
Go to the documentation of this file.
1 <?php
26 
33 abstract class SearchDatabase extends SearchEngine {
37  protected $searchTerms = [];
39 
44  $this->dbProvider = $dbProvider;
45  }
46 
51  final public function doSearchText( $term ) {
52  return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) );
53  }
54 
61  abstract protected function doSearchTextInDB( $term );
62 
67  final public function doSearchTitle( $term ) {
68  return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) );
69  }
70 
77  abstract protected function doSearchTitleInDB( $term );
78 
85  protected function filter( $text ) {
86  // List of chars allowed in the search query.
87  // This must include chars used in the search syntax.
88  // Usually " (phrase) or * (wildcards) if supported by the engine
89  $lc = $this->legalSearchChars( self::CHARS_ALL );
90  return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
91  }
92 
99  final protected function extractNamespacePrefix( $term ) {
100  $queryAndNs = self::parseNamespacePrefixes( $term );
101  if ( $queryAndNs === false ) {
102  return $term;
103  }
104  $this->namespaces = $queryAndNs[1];
105  return $queryAndNs[0];
106  }
107 }
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:58
Base search engine base class for database-backed searches.
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)
__construct(IConnectionProvider $dbProvider)
IConnectionProvider $dbProvider
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.
Provide primary and replica IDatabase connections.