MediaWiki master
SearchDatabase.php
Go to the documentation of this file.
1<?php
27
34abstract class SearchDatabase extends SearchEngine {
38 protected $searchTerms = [];
40
45 $this->dbProvider = $dbProvider;
46 }
47
52 final public function doSearchText( $term ) {
53 return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) );
54 }
55
62 abstract protected function doSearchTextInDB( $term );
63
68 final public function doSearchTitle( $term ) {
69 try {
70 return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) );
71 } catch ( DBQueryError $dqe ) {
72 if ( $dqe->errno == 1064 ) {
73 throw new DBQueryError(
74 $dqe->db,
75 "Query incompatible with database engine. For more information: " .
76 "https://bugs.mysql.com/bug.php?id=78485 https://jira.mariadb.org/browse/MDEV-21750 / " .
77 "https://phabricator.wikimedia.org/T355096",
78 1064, $dqe->sql, __METHOD__
79 );
80 } else {
81 throw $dqe;
82 }
83 }
84 }
85
92 abstract protected function doSearchTitleInDB( $term );
93
100 protected function filter( $text ) {
101 // List of chars allowed in the search query.
102 // This must include chars used in the search syntax.
103 // Usually " (phrase) or * (wildcards) if supported by the engine
104 $lc = $this->legalSearchChars( self::CHARS_ALL );
105 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
106 }
107
114 final protected function extractNamespacePrefix( $term ) {
115 $queryAndNs = self::parseNamespacePrefixes( $term );
116 if ( $queryAndNs === false ) {
117 return $term;
118 }
119 $this->namespaces = $queryAndNs[1];
120 return $queryAndNs[0];
121 }
122}
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.