Merge "Update html5 specs link in comment"
[mediawiki.git] / includes / search / SearchResultSet.php
blobf753e3d190d2675d0707a1c0a1e5ab4f196fa073
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 {
28 /**
29 * Fetch an array of regular expression fragments for matching
30 * the search terms as parsed by this engine in a text extract.
31 * STUB
33 * @return array
35 function termMatches() {
36 return array();
39 function numRows() {
40 return 0;
43 /**
44 * Return true if results are included in this result set.
45 * STUB
47 * @return bool
49 function hasResults() {
50 return false;
53 /**
54 * Some search modes return a total hit count for the query
55 * in the entire article database. This may include pages
56 * in namespaces that would not be matched on the given
57 * settings.
59 * Return null if no total hits number is supported.
61 * @return int
63 function getTotalHits() {
64 return null;
67 /**
68 * Some search modes return a suggested alternate term if there are
69 * no exact hits. Returns true if there is one on this set.
71 * @return bool
73 function hasSuggestion() {
74 return false;
77 /**
78 * @return string Suggested query, null if none
80 function getSuggestionQuery() {
81 return null;
84 /**
85 * @return string HTML highlighted suggested query, '' if none
87 function getSuggestionSnippet() {
88 return '';
91 /**
92 * Return a result set of hits on other (multiple) wikis associated with this one
94 * @return SearchResultSet
96 function getInterwikiResults() {
97 return null;
101 * Check if there are results on other wikis
103 * @return bool
105 function hasInterwikiResults() {
106 return $this->getInterwikiResults() != null;
110 * Fetches next search result, or false.
111 * STUB
113 * @return SearchResult
115 function next() {
116 return false;
120 * Frees the result set, if applicable.
122 function free() {
123 // ...
127 * Did the search contain search syntax? If so, Special:Search won't offer
128 * the user a link to a create a page named by the search string because the
129 * name would contain the search syntax.
130 * @return bool
132 public function searchContainedSyntax() {
133 return false;
138 * This class is used for different SQL-based search engines shipped with MediaWiki
139 * @ingroup Search
141 class SqlSearchResultSet extends SearchResultSet {
142 protected $resultSet;
143 protected $terms;
144 protected $totalHits;
146 function __construct( $resultSet, $terms, $total = null ) {
147 $this->resultSet = $resultSet;
148 $this->terms = $terms;
149 $this->totalHits = $total;
152 function termMatches() {
153 return $this->terms;
156 function numRows() {
157 if ( $this->resultSet === false ) {
158 return false;
161 return $this->resultSet->numRows();
164 function next() {
165 if ( $this->resultSet === false ) {
166 return false;
169 $row = $this->resultSet->fetchObject();
170 if ( $row === false ) {
171 return false;
174 return SearchResult::newFromRow( $row );
177 function free() {
178 if ( $this->resultSet === false ) {
179 return false;
182 $this->resultSet->free();
185 function getTotalHits() {
186 return $this->totalHits;
191 * A SearchResultSet wrapper for SearchEngine::getNearMatch
193 class SearchNearMatchResultSet extends SearchResultSet {
194 private $fetched = false;
197 * @param Title|null $match Title if matched, else null
199 public function __construct( $match ) {
200 $this->result = $match;
203 public function hasResult() {
204 return (bool)$this->result;
207 public function numRows() {
208 return $this->hasResults() ? 1 : 0;
211 public function next() {
212 if ( $this->fetched || !$this->result ) {
213 return false;
215 $this->fetched = true;
216 return SearchResult::newFromTitle( $this->result );