MediaWiki REL1_39
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 0;
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}
Service locator for MediaWiki core services.
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.