MediaWiki fundraising/REL1_35
SqlSearchResultSet.php
Go to the documentation of this file.
1<?php
2
4
13 protected $resultSet;
15 protected $terms;
17 protected $totalHits;
18
24 public function __construct( IResultWrapper $resultSet, array $terms, $total = null ) {
25 parent::__construct();
26 $this->resultSet = $resultSet;
27 $this->terms = $terms;
28 $this->totalHits = $total;
29 }
30
35 public function termMatches() {
36 return $this->terms;
37 }
38
39 public function numRows() {
40 if ( $this->resultSet === false ) {
41 return false;
42 }
43
44 return $this->resultSet->numRows();
45 }
46
47 public function extractResults() {
48 if ( $this->resultSet === false ) {
49 return [];
50 }
51
52 if ( $this->results === null ) {
53 $this->results = [];
54 $this->resultSet->rewind();
55 $terms = \MediaWiki\MediaWikiServices::getInstance()->getContentLanguage()
56 ->convertForSearchResult( $this->terms );
57 while ( ( $row = $this->resultSet->fetchObject() ) !== false ) {
58 $result = new SqlSearchResult(
59 Title::makeTitle( $row->page_namespace, $row->page_title ),
60 $terms
61 );
62 $this->augmentResult( $result );
63 $this->results[] = $result;
64 }
65 }
66 return $this->results;
67 }
68
69 public function getTotalHits() {
70 if ( $this->totalHits !== null ) {
71 return $this->totalHits;
72 } else {
73 // Special:Search expects a number here.
74 return $this->numRows();
75 }
76 }
77}
SearchResult[] $results
Cache of results - serialization of the result iterator as an array.
This class is used for different SQL-based search engines shipped with MediaWiki.
getTotalHits()
Some search modes return a total hit count for the query in the entire article database.
__construct(IResultWrapper $resultSet, array $terms, $total=null)
int null $totalHits
Total number of hits for $terms.
IResultWrapper $resultSet
@noinspection PhpMissingParentConstructorInspection
string[] $terms
Requested search query.
extractResults()
Extract all the results in the result set as array.
augmentResult(SearchResult $result)
Returns extra data for specific result and store it in SearchResult object.
Result wrapper for grabbing data queried from an IDatabase object.