MediaWiki REL1_34
SearchResultSet.php
Go to the documentation of this file.
1<?php
29
30 protected $containedSyntax = false;
31
37 private $titles;
38
44 protected $results;
45
50
57 public function __construct( $containedSyntax = false, $hasMoreResults = false ) {
58 if ( static::class === self::class ) {
59 // This class will eventually be abstract. SearchEngine implementations
60 // already have to extend this class anyways to provide the actual
61 // search results.
62 wfDeprecated( __METHOD__, '1.32' );
63 }
64 $this->containedSyntax = $containedSyntax;
66 }
67
68 public function numRows() {
69 return $this->count();
70 }
71
72 final public function count() {
73 return count( $this->extractResults() );
74 }
75
86 public function getTotalHits() {
87 return null;
88 }
89
97 public function hasRewrittenQuery() {
98 return false;
99 }
100
105 public function getQueryAfterRewrite() {
106 return null;
107 }
108
113 public function getQueryAfterRewriteSnippet() {
114 return null;
115 }
116
123 public function hasSuggestion() {
124 return false;
125 }
126
130 public function getSuggestionQuery() {
131 return null;
132 }
133
137 public function getSuggestionSnippet() {
138 return '';
139 }
140
147 public function getInterwikiResults( $type = self::SECONDARY_RESULTS ) {
148 return null;
149 }
150
157 public function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) {
158 return false;
159 }
160
167 public function searchContainedSyntax() {
169 }
170
174 public function hasMoreResults() {
176 }
177
182 public function shrink( $limit ) {
183 if ( $this->count() > $limit ) {
184 $this->hasMoreResults = true;
185 // shrinking result set for implementations that
186 // have not implemented extractResults and use
187 // the default cache location. Other implementations
188 // must override this as well.
189 if ( is_array( $this->results ) ) {
190 $this->results = array_slice( $this->results, 0, $limit );
191 } else {
192 throw new \UnexpectedValueException(
193 "When overriding result store extending classes must "
194 . " also override " . __METHOD__ );
195 }
196 }
197 }
198
203 public function extractResults() {
204 if ( is_null( $this->results ) ) {
205 $this->results = [];
206 if ( $this->numRows() == 0 ) {
207 // Don't bother if we've got empty result
208 return $this->results;
209 }
210 $this->rewind();
211 while ( ( $result = $this->next() ) != false ) {
212 $this->results[] = $result;
213 }
214 $this->rewind();
215 }
216 return $this->results;
217 }
218
223 public function extractTitles() {
224 if ( is_null( $this->titles ) ) {
225 if ( $this->numRows() == 0 ) {
226 // Don't bother if we've got empty result
227 $this->titles = [];
228 } else {
229 $this->titles = array_map(
230 function ( SearchResult $result ) {
231 return $result->getTitle();
232 },
233 $this->extractResults() );
234 }
235 }
236 return $this->titles;
237 }
238}
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
BaseSearchResultSet is the base class that must be extended by SearchEngine search result set impleme...
next()
Fetches next search result, or false.
rewind()
Rewind result set back to beginning.
hasInterwikiResults( $type=self::SECONDARY_RESULTS)
Check if there are results on other wikis.
getTotalHits()
Some search modes return a total hit count for the query in the entire article database.
getInterwikiResults( $type=self::SECONDARY_RESULTS)
Return a result set of hits on other (multiple) wikis associated with this one.
boolean $hasMoreResults
True when there are more pages of search results available.
searchContainedSyntax()
Did the search contain search syntax? If so, Special:Search won't offer the user a link to a create a...
hasRewrittenQuery()
Some search modes will run an alternative query that it thinks gives a better result than the provide...
Title[] $titles
Cache of titles.
__construct( $containedSyntax=false, $hasMoreResults=false)
extractResults()
Extract all the results in the result set as array.
hasSuggestion()
Some search modes return a suggested alternate term if there are no exact hits.
extractTitles()
Extract all the titles in the result set.
SearchResult[] $results
Cache of results - serialization of the result iterator as an array.
NOTE: this class is being refactored into an abstract base class.
Represents a title within MediaWiki.
Definition Title.php:42
trait SearchResultSetTrait
Trait useful for SearchResultSet implementations.