3 use Wikimedia\Rdbms\IResultWrapper
;
6 * This class is used for different SQL-based search engines shipped with MediaWiki
9 class SqlSearchResultSet
extends SearchResultSet
{
10 /** @noinspection PhpMissingParentConstructorInspection */
12 /** @var IResultWrapper Result object from database */
14 /** @var string[] Requested search query */
16 /** @var int|null Total number of hits for $terms */
19 function __construct( IResultWrapper
$resultSet, $terms, $total = null ) {
20 $this->resultSet
= $resultSet;
21 $this->terms
= $terms;
22 $this->totalHits
= $total;
25 function termMatches() {
30 if ( $this->resultSet
=== false ) {
34 return $this->resultSet
->numRows();
37 public function extractResults() {
38 if ( $this->resultSet
=== false ) {
42 if ( $this->results
=== null ) {
44 $this->resultSet
->rewind();
45 while ( ( $row = $this->resultSet
->fetchObject() ) !== false ) {
46 $this->results
[] = SearchResult
::newFromTitle(
47 Title
::makeTitle( $row->page_namespace
, $row->page_title
), $this
51 return $this->results
;
55 if ( $this->resultSet
=== false ) {
59 $this->resultSet
->free();
62 function getTotalHits() {
63 if ( !is_null( $this->totalHits
) ) {
64 return $this->totalHits
;
66 // Special:Search expects a number here.
67 return $this->numRows();