3 use MediaWiki\MediaWikiServices
;
4 use MediaWiki\Title\Title
;
5 use Wikimedia\Rdbms\IResultWrapper
;
8 * This class is used for different SQL-based search engines shipped with MediaWiki
11 class SqlSearchResultSet
extends SearchResultSet
{
12 /** @noinspection PhpMissingParentConstructorInspection */
14 /** @var IResultWrapper Result object from database */
16 /** @var string[] Requested search query */
18 /** @var int|null Total number of hits for $terms */
22 * @param IResultWrapper $resultSet
23 * @param string[] $terms
24 * @param int|null $total
26 public function __construct( IResultWrapper
$resultSet, array $terms, $total = null ) {
27 parent
::__construct();
28 $this->resultSet
= $resultSet;
29 $this->terms
= $terms;
30 $this->totalHits
= $total;
35 * @deprecated since 1.34
37 public function termMatches() {
41 public function numRows() {
42 if ( $this->resultSet
=== false ) {
46 return $this->resultSet
->numRows();
49 public function extractResults() {
50 if ( $this->resultSet
=== false ) {
54 if ( $this->results
=== null ) {
56 $this->resultSet
->rewind();
57 $terms = MediaWikiServices
::getInstance()->getContentLanguage()
58 ->convertForSearchResult( $this->terms
);
59 foreach ( $this->resultSet
as $row ) {
60 $result = new SqlSearchResult(
61 Title
::makeTitle( $row->page_namespace
, $row->page_title
),
64 $this->augmentResult( $result );
65 $this->results
[] = $result;
68 return $this->results
;
71 public function getTotalHits() {
72 if ( $this->totalHits
!== null ) {
73 return $this->totalHits
;
75 // Special:Search expects a number here.
76 return $this->numRows();