]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/search/SqlSearchResultSet.php
MediaWiki 1.30.2-scripts2
[autoinstalls/mediawiki.git] / includes / search / SqlSearchResultSet.php
1 <?php
2
3 use Wikimedia\Rdbms\ResultWrapper;
4
5 /**
6  * This class is used for different SQL-based search engines shipped with MediaWiki
7  * @ingroup Search
8  */
9 class SqlSearchResultSet extends SearchResultSet {
10         protected $resultSet;
11         protected $terms;
12         protected $totalHits;
13
14         function __construct( ResultWrapper $resultSet, $terms, $total = null ) {
15                 $this->resultSet = $resultSet;
16                 $this->terms = $terms;
17                 $this->totalHits = $total;
18         }
19
20         function termMatches() {
21                 return $this->terms;
22         }
23
24         function numRows() {
25                 if ( $this->resultSet === false ) {
26                         return false;
27                 }
28
29                 return $this->resultSet->numRows();
30         }
31
32         function next() {
33                 if ( $this->resultSet === false ) {
34                         return false;
35                 }
36
37                 $row = $this->resultSet->fetchObject();
38                 if ( $row === false ) {
39                         return false;
40                 }
41
42                 return SearchResult::newFromTitle(
43                         Title::makeTitle( $row->page_namespace, $row->page_title ), $this
44                 );
45         }
46
47         function rewind() {
48                 if ( $this->resultSet ) {
49                         $this->resultSet->rewind();
50                 }
51         }
52
53         function free() {
54                 if ( $this->resultSet === false ) {
55                         return false;
56                 }
57
58                 $this->resultSet->free();
59         }
60
61         function getTotalHits() {
62                 if ( !is_null( $this->totalHits ) ) {
63                         return $this->totalHits;
64                 } else {
65                         // Special:Search expects a number here.
66                         return $this->numRows();
67                 }
68         }
69 }