* Whether fulltext search is supported by current schema
* @return bool
*/
- function fulltextSearchSupported() {
- return $this->db->checkForEnabledSearch();
+ private function fulltextSearchSupported() {
+ $dbr = $this->lb->getMaintenanceConnectionRef( DB_REPLICA );
+ $sql = (string)$dbr->selectField(
+ $dbr->addIdentifierQuotes( 'sqlite_master' ),
+ 'sql',
+ [ 'tbl_name' => $dbr->tableName( 'searchindex', 'raw' ) ],
+ __METHOD__
+ );
+
+ return ( stristr( $sql, 'fts' ) !== false );
}
/**
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 ";
}
* Perform a full text search query and return a result set.
*
* @param string $term Raw search term
- * @return SqlSearchResultSet
+ * @return SqlSearchResultSet|null
*/
protected function doSearchTextInDB( $term ) {
return $this->searchInternal( $term, true );
* Perform a title-only search query and return a result set.
*
* @param string $term Raw search term
- * @return SqlSearchResultSet
+ * @return SqlSearchResultSet|null
*/
protected function doSearchTitleInDB( $term ) {
return $this->searchInternal( $term, false );
$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 ( $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 " .
* @param string $title
* @param string $text
*/
- function update( $id, $title, $text ) {
+ public function update( $id, $title, $text ) {
if ( !$this->fulltextSearchSupported() ) {
return;
}
// @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,
* @param int $id
* @param string $title
*/
- function updateTitle( $id, $title ) {
+ public function updateTitle( $id, $title ) {
if ( !$this->fulltextSearchSupported() ) {
return;
}
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->lb->getConnectionRef( DB_MASTER );
$dbw->update( 'searchindex',
[ 'si_title' => $title ],
[ 'rowid' => $id ],