MediaWiki  1.34.0
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 }
SqlSearchResult
Definition: SqlSearchResult.php:25
SqlSearchResultSet\$totalHits
int null $totalHits
Total number of hits for $terms.
Definition: SqlSearchResultSet.php:17
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:47
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
SearchResultSet
Definition: SearchResultSet.php:27
SqlSearchResultSet
This class is used for different SQL-based search engines shipped with MediaWiki.
Definition: SqlSearchResultSet.php:9
SqlSearchResultSet\__construct
__construct(IResultWrapper $resultSet, array $terms, $total=null)
Definition: SqlSearchResultSet.php:24
SqlSearchResultSet\termMatches
termMatches()
Definition: SqlSearchResultSet.php:35
SqlSearchResultSet\numRows
numRows()
Definition: SqlSearchResultSet.php:39
SqlSearchResultSet\$terms
string[] $terms
Requested search query.
Definition: SqlSearchResultSet.php:15
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:13
SqlSearchResultSet\getTotalHits
getTotalHits()
Some search modes return a total hit count for the query in the entire article database.
Definition: SqlSearchResultSet.php:69