| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MediaWikiServices; |
| 4 |
use MediaWiki\Title\Title; |
| 5 |
use Wikimedia\Rdbms\IResultWrapper; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class SqlSearchResultSet extends SearchResultSet { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
protected $resultSet; |
| 16 |
|
| 17 |
protected $terms; |
| 18 |
|
| 19 |
protected $totalHits; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 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; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function termMatches() { |
| 38 |
return $this->terms; |
| 39 |
} |
| 40 |
|
| 41 |
public function numRows() { |
| 42 |
if ( $this->resultSet === false ) { |
| 43 |
return 0; |
| 44 |
} |
| 45 |
|
| 46 |
return $this->resultSet->numRows(); |
| 47 |
} |
| 48 |
|
| 49 |
public function extractResults() { |
| 50 |
if ( $this->resultSet === false ) { |
| 51 |
return []; |
| 52 |
} |
| 53 |
|
| 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 |
| 63 |
); |
| 64 |
$this->augmentResult( $result ); |
| 65 |
$this->results[] = $result; |
| 66 |
} |
| 67 |
} |
| 68 |
return $this->results; |
| 69 |
} |
| 70 |
|
| 71 |
public function getTotalHits() { |
| 72 |
if ( $this->totalHits !== null ) { |
| 73 |
return $this->totalHits; |
| 74 |
} else { |
| 75 |
|
| 76 |
return $this->numRows(); |
| 77 |
} |
| 78 |
} |
| 79 |
} |