MediaWiki master
SearchDatabase.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Search;
11
15
22abstract class SearchDatabase extends SearchEngine {
26 protected $searchTerms = [];
28
30 $this->dbProvider = $dbProvider;
31 }
32
37 final public function doSearchText( $term ) {
38 return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) );
39 }
40
47 abstract protected function doSearchTextInDB( $term );
48
53 final public function doSearchTitle( $term ) {
54 try {
55 return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) );
56 } catch ( DBQueryError $dqe ) {
57 if ( $dqe->errno == 1064 ) {
58 throw new DBQueryError(
59 $dqe->db,
60 "Query incompatible with database engine. For more information: " .
61 "https://bugs.mysql.com/bug.php?id=78485 https://jira.mariadb.org/browse/MDEV-21750 / " .
62 "https://phabricator.wikimedia.org/T355096",
63 1064, $dqe->sql, __METHOD__
64 );
65 } else {
66 throw $dqe;
67 }
68 }
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}
108
110class_alias( SearchDatabase::class, 'SearchDatabase' );
Base search engine base class for database-backed searches.
extractNamespacePrefix( $term)
Extract the optional namespace prefix and set self::namespaces accordingly and return the query strin...
doSearchTextInDB( $term)
Perform a full text search query and return a result set.
doSearchTitleInDB( $term)
Perform a title-only search query and return a result set.
__construct(IConnectionProvider $dbProvider)
string[] $searchTerms
search terms
filter( $text)
Return a 'cleaned up' search string.
Contain a class for special pages.
legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search.
static parseNamespacePrefixes( $query, $withAllKeyword=true, $withPrefixSearchExtractNamespaceHook=false)
Parse some common prefixes: all (search everything) or namespace names.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44
Provide primary and replica IDatabase connections.
Definition of a mapping for the search index field.