Merge "Bump wikimedia/parsoid to 0.21.0-a11"
[mediawiki.git] / includes / search / SqlSearchResultSet.php
blobd08220904538660451d9327318f6aaf34f4ab7ec
1 <?php
3 use MediaWiki\MediaWikiServices;
4 use MediaWiki\Title\Title;
5 use Wikimedia\Rdbms\IResultWrapper;
7 /**
8 * This class is used for different SQL-based search engines shipped with MediaWiki
9 * @ingroup Search
11 class SqlSearchResultSet extends SearchResultSet {
12 /** @noinspection PhpMissingParentConstructorInspection */
14 /** @var IResultWrapper Result object from database */
15 protected $resultSet;
16 /** @var string[] Requested search query */
17 protected $terms;
18 /** @var int|null Total number of hits for $terms */
19 protected $totalHits;
21 /**
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;
33 /**
34 * @return string[]
35 * @deprecated since 1.34
37 public function termMatches() {
38 return $this->terms;
41 public function numRows() {
42 if ( $this->resultSet === false ) {
43 return 0;
46 return $this->resultSet->numRows();
49 public function extractResults() {
50 if ( $this->resultSet === false ) {
51 return [];
54 if ( $this->results === null ) {
55 $this->results = [];
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 ),
62 $terms
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;
74 } else {
75 // Special:Search expects a number here.
76 return $this->numRows();