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