*/
use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\DatabaseSqlite;
/**
* Search engine hook for SQLite
* @return bool
*/
function fulltextSearchSupported() {
- return $this->db->checkForEnabledSearch();
+ /** @var DatabaseSqlite $dbr */
+ $dbr = $this->lb->getConnection( DB_REPLICA );
+
+ return $dbr->checkForEnabledSearch();
}
/**
wfDebug( __METHOD__ . ": Can't understand search query '{$filteredText}'\n" );
}
- $searchon = $this->db->addQuotes( $searchon );
+ $dbr = $this->lb->getConnectionRef( DB_REPLICA );
+ $searchon = $dbr->addQuotes( $searchon );
$field = $this->getIndexField( $fulltext );
+
return " $field MATCH $searchon ";
}
} else {
// For Chinese, words may legitimately abut other words in the text literal.
// Don't add \b boundary checks... note this could cause false positives
- // for latin chars.
+ // for Latin chars.
}
return $regex;
}
- public static function legalSearchChars( $type = self::CHARS_ALL ) {
+ public function legalSearchChars( $type = self::CHARS_ALL ) {
$searchChars = parent::legalSearchChars( $type );
if ( $type === self::CHARS_ALL ) {
// " for phrase, * for wildcard
$filteredTerm =
$this->filter( MediaWikiServices::getInstance()->getContentLanguage()->lc( $term ) );
- $resultSet = $this->db->query( $this->getQuery( $filteredTerm, $fulltext ) );
+ $dbr = $this->lb->getConnectionRef( DB_REPLICA );
+ $resultSet = $dbr->query( $this->getQuery( $filteredTerm, $fulltext ) );
$total = null;
- $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) );
+ $totalResult = $dbr->query( $this->getCountQuery( $filteredTerm, $fulltext ) );
$row = $totalResult->fetchObject();
if ( $row ) {
$total = intval( $row->c );
if ( is_null( $this->namespaces ) ) {
return ''; # search all
}
- if ( !count( $this->namespaces ) ) {
+ if ( $this->namespaces === [] ) {
$namespaces = '0';
} else {
- $namespaces = $this->db->makeList( $this->namespaces );
+ $dbr = $this->lb->getConnectionRef( DB_REPLICA );
+ $namespaces = $dbr->makeList( $this->namespaces );
}
return 'AND page_namespace IN (' . $namespaces . ')';
}
* @return string
*/
private function limitResult( $sql ) {
- return $this->db->limitResult( $sql, $this->limit, $this->offset );
+ $dbr = $this->lb->getConnectionRef( DB_REPLICA );
+
+ return $dbr->limitResult( $sql, $this->limit, $this->offset );
}
/**
*/
private function queryMain( $filteredTerm, $fulltext ) {
$match = $this->parseQuery( $filteredTerm, $fulltext );
- $page = $this->db->tableName( 'page' );
- $searchindex = $this->db->tableName( 'searchindex' );
+ $dbr = $this->lb->getMaintenanceConnectionRef( DB_REPLICA );
+ $page = $dbr->tableName( 'page' );
+ $searchindex = $dbr->tableName( 'searchindex' );
return "SELECT $searchindex.rowid, page_namespace, page_title " .
"FROM $page,$searchindex " .
"WHERE page_id=$searchindex.rowid AND $match";
private function getCountQuery( $filteredTerm, $fulltext ) {
$match = $this->parseQuery( $filteredTerm, $fulltext );
- $page = $this->db->tableName( 'page' );
- $searchindex = $this->db->tableName( 'searchindex' );
+ $dbr = $this->lb->getMaintenanceConnectionRef( DB_REPLICA );
+ $page = $dbr->tableName( 'page' );
+ $searchindex = $dbr->tableName( 'searchindex' );
return "SELECT COUNT(*) AS c " .
"FROM $page,$searchindex " .
"WHERE page_id=$searchindex.rowid AND $match " .
}
// @todo find a method to do it in a single request,
// couldn't do it so far due to typelessness of FTS3 tables.
- $dbw = wfGetDB( DB_MASTER );
-
+ $dbw = $this->lb->getConnectionRef( DB_MASTER );
$dbw->delete( 'searchindex', [ 'rowid' => $id ], __METHOD__ );
-
$dbw->insert( 'searchindex',
[
'rowid' => $id,
if ( !$this->fulltextSearchSupported() ) {
return;
}
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->lb->getConnectionRef( DB_MASTER );
$dbw->update( 'searchindex',
[ 'si_title' => $title ],
[ 'rowid' => $id ],