Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| SqlSearchResultSet | |
0.00% |
0 / 26 |
|
0.00% |
0 / 5 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| termMatches | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| numRows | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| extractResults | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
| getTotalHits | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Search; |
| 4 | |
| 5 | use MediaWiki\MediaWikiServices; |
| 6 | use MediaWiki\Title\Title; |
| 7 | use Wikimedia\Rdbms\IResultWrapper; |
| 8 | |
| 9 | /** |
| 10 | * This class is used for different SQL-based search engines shipped with MediaWiki |
| 11 | * @ingroup Search |
| 12 | */ |
| 13 | class SqlSearchResultSet extends SearchResultSet { |
| 14 | /** @noinspection PhpMissingParentConstructorInspection */ |
| 15 | |
| 16 | /** @var IResultWrapper Result object from database */ |
| 17 | protected $resultSet; |
| 18 | /** @var string[] Requested search query */ |
| 19 | protected $terms; |
| 20 | /** @var int|null Total number of hits for $terms */ |
| 21 | protected $totalHits; |
| 22 | |
| 23 | /** |
| 24 | * @param IResultWrapper $resultSet |
| 25 | * @param string[] $terms |
| 26 | * @param int|null $total |
| 27 | */ |
| 28 | public function __construct( IResultWrapper $resultSet, array $terms, $total = null ) { |
| 29 | parent::__construct(); |
| 30 | $this->resultSet = $resultSet; |
| 31 | $this->terms = $terms; |
| 32 | $this->totalHits = $total; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @return string[] |
| 37 | * @deprecated since 1.34 |
| 38 | */ |
| 39 | public function termMatches() { |
| 40 | return $this->terms; |
| 41 | } |
| 42 | |
| 43 | /** @inheritDoc */ |
| 44 | public function numRows() { |
| 45 | if ( $this->resultSet === false ) { |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | return $this->resultSet->numRows(); |
| 50 | } |
| 51 | |
| 52 | /** @inheritDoc */ |
| 53 | public function extractResults() { |
| 54 | if ( $this->resultSet === false ) { |
| 55 | return []; |
| 56 | } |
| 57 | |
| 58 | if ( $this->results === null ) { |
| 59 | $this->results = []; |
| 60 | $this->resultSet->rewind(); |
| 61 | $terms = MediaWikiServices::getInstance()->getContentLanguage() |
| 62 | ->convertForSearchResult( $this->terms ); |
| 63 | foreach ( $this->resultSet as $row ) { |
| 64 | $result = new SqlSearchResult( |
| 65 | Title::makeTitle( $row->page_namespace, $row->page_title ), |
| 66 | $terms |
| 67 | ); |
| 68 | $this->augmentResult( $result ); |
| 69 | $this->results[] = $result; |
| 70 | } |
| 71 | } |
| 72 | return $this->results; |
| 73 | } |
| 74 | |
| 75 | /** @inheritDoc */ |
| 76 | public function getTotalHits() { |
| 77 | if ( $this->totalHits !== null ) { |
| 78 | return $this->totalHits; |
| 79 | } else { |
| 80 | // Special:Search expects a number here. |
| 81 | return $this->numRows(); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** @deprecated class alias since 1.46 */ |
| 87 | class_alias( SqlSearchResultSet::class, 'SqlSearchResultSet' ); |