MediaWiki  master
SqlSearchResultSet.php
Go to the documentation of this file.
1 <?php
2 
4 
13  protected $resultSet;
15  protected $terms;
17  protected $totalHits;
18 
24  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  function termMatches() {
36  return $this->terms;
37  }
38 
39  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  function getTotalHits() {
70  if ( !is_null( $this->totalHits ) ) {
71  return $this->totalHits;
72  } else {
73  // Special:Search expects a number here.
74  return $this->numRows();
75  }
76  }
77 }
string [] $terms
Requested search query.
augmentResult(SearchResult $result)
Returns extra data for specific result and store it in SearchResult object.
int null $totalHits
Total number of hits for $terms.
extractResults()
Extract all the results in the result set as array.
IResultWrapper $resultSet
PhpMissingParentConstructorInspection
SearchResult [] $results
Cache of results - serialization of the result iterator as an array.
getTotalHits()
Some search modes return a total hit count for the query in the entire article database.
This class is used for different SQL-based search engines shipped with MediaWiki. ...
Result wrapper for grabbing data queried from an IDatabase object.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:584
__construct(IResultWrapper $resultSet, array $terms, $total=null)