3 use Wikimedia\Rdbms\ResultWrapper
;
6 * This class is used for different SQL-based search engines shipped with MediaWiki
9 class SqlSearchResultSet
extends SearchResultSet
{
10 /** @var ResultWrapper Result object from database */
12 /** @var string Requested search query */
14 /** @var int|null Total number of hits for $terms */
17 function __construct( ResultWrapper
$resultSet, $terms, $total = null ) {
18 $this->resultSet
= $resultSet;
19 $this->terms
= $terms;
20 $this->totalHits
= $total;
23 function termMatches() {
28 if ( $this->resultSet
=== false ) {
32 return $this->resultSet
->numRows();
35 public function extractResults() {
36 if ( $this->resultSet
=== false ) {
40 if ( $this->results
=== null ) {
42 $this->resultSet
->rewind();
43 while ( ( $row = $this->resultSet
->fetchObject() ) !== false ) {
44 $this->results
[] = SearchResult
::newFromTitle(
45 Title
::makeTitle( $row->page_namespace
, $row->page_title
), $this
49 return $this->results
;
53 if ( $this->resultSet
=== false ) {
57 $this->resultSet
->free();
60 function getTotalHits() {
61 if ( !is_null( $this->totalHits
) ) {
62 return $this->totalHits
;
64 // Special:Search expects a number here.
65 return $this->numRows();