MediaWiki master
SearchDatabase.php
Go to the documentation of this file.
1<?php
27
34abstract class SearchDatabase extends SearchEngine {
38 protected $searchTerms = [];
40
42 $this->dbProvider = $dbProvider;
43 }
44
49 final public function doSearchText( $term ) {
50 return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) );
51 }
52
59 abstract protected function doSearchTextInDB( $term );
60
65 final public function doSearchTitle( $term ) {
66 try {
67 return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) );
68 } catch ( DBQueryError $dqe ) {
69 if ( $dqe->errno == 1064 ) {
70 throw new DBQueryError(
71 $dqe->db,
72 "Query incompatible with database engine. For more information: " .
73 "https://bugs.mysql.com/bug.php?id=78485 https://jira.mariadb.org/browse/MDEV-21750 / " .
74 "https://phabricator.wikimedia.org/T355096",
75 1064, $dqe->sql, __METHOD__
76 );
77 } else {
78 throw $dqe;
79 }
80 }
81 }
82
89 abstract protected function doSearchTitleInDB( $term );
90
97 protected function filter( $text ) {
98 // List of chars allowed in the search query.
99 // This must include chars used in the search syntax.
100 // Usually " (phrase) or * (wildcards) if supported by the engine
101 $lc = $this->legalSearchChars( self::CHARS_ALL );
102 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
103 }
104
111 final protected function extractNamespacePrefix( $term ) {
112 $queryAndNs = self::parseNamespacePrefixes( $term );
113 if ( $queryAndNs === false ) {
114 return $term;
115 }
116 $this->namespaces = $queryAndNs[1];
117 return $queryAndNs[0];
118 }
119}
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Base search engine base class for database-backed searches.
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...
__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.