Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
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 | use MediaWiki\MediaWikiServices; |
4 | use MediaWiki\Title\Title; |
5 | use Wikimedia\Rdbms\IResultWrapper; |
6 | |
7 | /** |
8 | * This class is used for different SQL-based search engines shipped with MediaWiki |
9 | * @ingroup Search |
10 | */ |
11 | class SqlSearchResultSet extends SearchResultSet { |
12 | /** @noinspection PhpMissingParentConstructorInspection */ |
13 | |
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; |
20 | |
21 | /** |
22 | * @param IResultWrapper $resultSet |
23 | * @param string[] $terms |
24 | * @param int|null $total |
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 | * @return string[] |
35 | * @deprecated since 1.34 |
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 | // Special:Search expects a number here. |
76 | return $this->numRows(); |
77 | } |
78 | } |
79 | } |