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 */
20 * @param IResultWrapper $resultSet
21 * @param string[] $terms
22 * @param int|null $total
24 function __construct( IResultWrapper
$resultSet, array $terms, $total = null ) {
25 parent
::__construct();
26 $this->resultSet
= $resultSet;
27 $this->terms
= $terms;
28 $this->totalHits
= $total;
33 * @deprecated since 1.34
35 function termMatches() {
40 if ( $this->resultSet
=== false ) {
44 return $this->resultSet
->numRows();
47 public function extractResults() {
48 if ( $this->resultSet
=== false ) {
52 if ( $this->results
=== null ) {
54 $this->resultSet
->rewind();
55 $terms = \MediaWiki\MediaWikiServices
::getInstance()->getContentLanguage()
56 ->convertForSearchResult( $this->terms
);
57 while ( ( $row = $this->resultSet
->fetchObject() ) !== false ) {
58 $result = new SqlSearchResult(
59 Title
::makeTitle( $row->page_namespace
, $row->page_title
),
62 $this->augmentResult( $result );
63 $this->results
[] = $result;
66 return $this->results
;
69 function getTotalHits() {
70 if ( !is_null( $this->totalHits
) ) {
71 return $this->totalHits
;
73 // Special:Search expects a number here.
74 return $this->numRows();