MediaWiki master
SqlSearchResultSet.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Search;
4
8
17 protected $resultSet;
19 protected $terms;
21 protected $totalHits;
22
28 public function __construct( IResultWrapper $resultSet, array $terms, $total = null ) {
29 parent::__construct();
30 $this->resultSet = $resultSet;
31 $this->terms = $terms;
32 $this->totalHits = $total;
33 }
34
39 public function termMatches() {
40 return $this->terms;
41 }
42
44 public function numRows() {
45 if ( $this->resultSet === false ) {
46 return 0;
47 }
48
49 return $this->resultSet->numRows();
50 }
51
53 public function extractResults() {
54 if ( $this->resultSet === false ) {
55 return [];
56 }
57
58 if ( $this->results === null ) {
59 $this->results = [];
60 $this->resultSet->rewind();
61 $terms = MediaWikiServices::getInstance()->getContentLanguage()
62 ->convertForSearchResult( $this->terms );
63 foreach ( $this->resultSet as $row ) {
64 $result = new SqlSearchResult(
65 Title::makeTitle( $row->page_namespace, $row->page_title ),
66 $terms
67 );
68 $this->augmentResult( $result );
69 $this->results[] = $result;
70 }
71 }
72 return $this->results;
73 }
74
76 public function getTotalHits() {
77 if ( $this->totalHits !== null ) {
78 return $this->totalHits;
79 } else {
80 // Special:Search expects a number here.
81 return $this->numRows();
82 }
83 }
84}
85
87class_alias( SqlSearchResultSet::class, 'SqlSearchResultSet' );
makeTitle( $linkId)
Convert a link ID to a Title.to override Title
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
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....
string[] $terms
Requested search query.
int null $totalHits
Total number of hits for $terms.
__construct(IResultWrapper $resultSet, array $terms, $total=null)
IResultWrapper $resultSet
@noinspection PhpMissingParentConstructorInspection
extractResults()
Extract all the results in the result set as array.SearchResult[]
Represents a title within MediaWiki.
Definition Title.php:69
Result wrapper for grabbing data queried from an IDatabase object.
Definition of a mapping for the search index field.
augmentResult(SearchResult $result)
Returns extra data for specific result and store it in SearchResult object.