MediaWiki  master
SqlSearchResultSet.php
Go to the documentation of this file.
1 <?php
2 
6 
15  protected $resultSet;
17  protected $terms;
19  protected $totalHits;
20 
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 
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  while ( ( $row = $this->resultSet->fetchObject() ) !== false ) {
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 }
Service locator for MediaWiki core services.
Represents a title within MediaWiki.
Definition: Title.php:82
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.