wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / search / SearchResultSet.php
blob8fb04e4a910882da85be844808c3917bd913a0ae
1 <?php
2 /**
3 * Search result sets
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Search
24 /**
25 * @ingroup Search
27 class SearchResultSet {
29 /**
30 * Types of interwiki results
32 /**
33 * Results that are displayed only together with existing main wiki results
34 * @var int
36 const SECONDARY_RESULTS = 0;
37 /**
38 * Results that can displayed even if no existing main wiki results exist
39 * @var int
41 const INLINE_RESULTS = 1;
43 protected $containedSyntax = false;
45 public function __construct( $containedSyntax = false ) {
46 $this->containedSyntax = $containedSyntax;
49 /**
50 * Fetch an array of regular expression fragments for matching
51 * the search terms as parsed by this engine in a text extract.
52 * STUB
54 * @return array
56 function termMatches() {
57 return array();
60 function numRows() {
61 return 0;
64 /**
65 * Some search modes return a total hit count for the query
66 * in the entire article database. This may include pages
67 * in namespaces that would not be matched on the given
68 * settings.
70 * Return null if no total hits number is supported.
72 * @return int
74 function getTotalHits() {
75 return null;
78 /**
79 * Some search modes will run an alternative query that it thinks gives
80 * a better result than the provided search. Returns true if this has
81 * occured.
83 * @return bool
85 function hasRewrittenQuery() {
86 return false;
89 /**
90 * @return string|null The search the query was internally rewritten to,
91 * or null when the result of the original query was returned.
93 function getQueryAfterRewrite() {
94 return null;
97 /**
98 * @return string|null Same as self::getQueryAfterRewrite(), but in HTML
99 * and with changes highlighted. Null when the query was not rewritten.
101 function getQueryAfterRewriteSnippet() {
102 return null;
106 * Some search modes return a suggested alternate term if there are
107 * no exact hits. Returns true if there is one on this set.
109 * @return bool
111 function hasSuggestion() {
112 return false;
116 * @return string|null Suggested query, null if none
118 function getSuggestionQuery() {
119 return null;
123 * @return string HTML highlighted suggested query, '' if none
125 function getSuggestionSnippet() {
126 return '';
130 * Return a result set of hits on other (multiple) wikis associated with this one
132 * @return SearchResultSet
134 function getInterwikiResults( $type = self::SECONDARY_RESULTS ) {
135 return null;
139 * Check if there are results on other wikis
141 * @return bool
143 function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) {
144 return false;
148 * Fetches next search result, or false.
149 * STUB
151 * @return SearchResult
153 function next() {
154 return false;
158 * Frees the result set, if applicable.
160 function free() {
161 // ...
165 * Did the search contain search syntax? If so, Special:Search won't offer
166 * the user a link to a create a page named by the search string because the
167 * name would contain the search syntax.
168 * @return bool
170 public function searchContainedSyntax() {
171 return $this->containedSyntax;
176 * This class is used for different SQL-based search engines shipped with MediaWiki
177 * @ingroup Search
179 class SqlSearchResultSet extends SearchResultSet {
180 protected $resultSet;
181 protected $terms;
182 protected $totalHits;
184 function __construct( $resultSet, $terms, $total = null ) {
185 $this->resultSet = $resultSet;
186 $this->terms = $terms;
187 $this->totalHits = $total;
190 function termMatches() {
191 return $this->terms;
194 function numRows() {
195 if ( $this->resultSet === false ) {
196 return false;
199 return $this->resultSet->numRows();
202 function next() {
203 if ( $this->resultSet === false ) {
204 return false;
207 $row = $this->resultSet->fetchObject();
208 if ( $row === false ) {
209 return false;
212 return SearchResult::newFromTitle(
213 Title::makeTitle( $row->page_namespace, $row->page_title )
217 function free() {
218 if ( $this->resultSet === false ) {
219 return false;
222 $this->resultSet->free();
225 function getTotalHits() {
226 if ( !is_null( $this->totalHits ) ) {
227 return $this->totalHits;
228 } else {
229 // Special:Search expects a number here.
230 return $this->numRows();
236 * A SearchResultSet wrapper for SearchEngine::getNearMatch
238 class SearchNearMatchResultSet extends SearchResultSet {
239 private $fetched = false;
242 * @param Title|null $match Title if matched, else null
244 public function __construct( $match ) {
245 $this->result = $match;
248 public function numRows() {
249 return $this->result ? 1 : 0;
252 public function next() {
253 if ( $this->fetched || !$this->result ) {
254 return false;
256 $this->fetched = true;
257 return SearchResult::newFromTitle( $this->result );