wiki.techinc.nl/includes/search/SqlSearchResultSet.php
Umherirrender 0688dd7c6d Set method visibility for various constructors
Change-Id: Id3c88257e866923b06e878ccdeddded7f08f2c98
2019-12-03 20:17:30 +01:00

77 lines
1.8 KiB
PHP

<?php
use Wikimedia\Rdbms\IResultWrapper;
/**
* This class is used for different SQL-based search engines shipped with MediaWiki
* @ingroup Search
*/
class SqlSearchResultSet extends SearchResultSet {
/** @noinspection PhpMissingParentConstructorInspection */
/** @var IResultWrapper Result object from database */
protected $resultSet;
/** @var string[] Requested search query */
protected $terms;
/** @var int|null Total number of hits for $terms */
protected $totalHits;
/**
* @param IResultWrapper $resultSet
* @param string[] $terms
* @param int|null $total
*/
public function __construct( IResultWrapper $resultSet, array $terms, $total = null ) {
parent::__construct();
$this->resultSet = $resultSet;
$this->terms = $terms;
$this->totalHits = $total;
}
/**
* @return string[]
* @deprecated since 1.34
*/
function termMatches() {
return $this->terms;
}
function numRows() {
if ( $this->resultSet === false ) {
return false;
}
return $this->resultSet->numRows();
}
public function extractResults() {
if ( $this->resultSet === false ) {
return [];
}
if ( $this->results === null ) {
$this->results = [];
$this->resultSet->rewind();
$terms = \MediaWiki\MediaWikiServices::getInstance()->getContentLanguage()
->convertForSearchResult( $this->terms );
while ( ( $row = $this->resultSet->fetchObject() ) !== false ) {
$result = new SqlSearchResult(
Title::makeTitle( $row->page_namespace, $row->page_title ),
$terms
);
$this->augmentResult( $result );
$this->results[] = $result;
}
}
return $this->results;
}
function getTotalHits() {
if ( !is_null( $this->totalHits ) ) {
return $this->totalHits;
} else {
// Special:Search expects a number here.
return $this->numRows();
}
}
}