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
27 class SearchResultSet
{
29 * Fetch an array of regular expression fragments for matching
30 * the search terms as parsed by this engine in a text extract.
35 function termMatches() {
44 * Some search modes return a total hit count for the query
45 * in the entire article database. This may include pages
46 * in namespaces that would not be matched on the given
49 * Return null if no total hits number is supported.
53 function getTotalHits() {
58 * Some search modes return a suggested alternate term if there are
59 * no exact hits. Returns true if there is one on this set.
63 function hasSuggestion() {
68 * @return string Suggested query, null if none
70 function getSuggestionQuery() {
75 * @return string HTML highlighted suggested query, '' if none
77 function getSuggestionSnippet() {
82 * Return a result set of hits on other (multiple) wikis associated with this one
84 * @return SearchResultSet
86 function getInterwikiResults() {
91 * Check if there are results on other wikis
95 function hasInterwikiResults() {
96 return $this->getInterwikiResults() != null;
100 * Fetches next search result, or false.
103 * @return SearchResult
110 * Frees the result set, if applicable.
117 * Did the search contain search syntax? If so, Special:Search won't offer
118 * the user a link to a create a page named by the search string because the
119 * name would contain the search syntax.
122 public function searchContainedSyntax() {
128 * This class is used for different SQL-based search engines shipped with MediaWiki
131 class SqlSearchResultSet
extends SearchResultSet
{
132 protected $resultSet;
134 protected $totalHits;
136 function __construct( $resultSet, $terms, $total = null ) {
137 $this->resultSet
= $resultSet;
138 $this->terms
= $terms;
139 $this->totalHits
= $total;
142 function termMatches() {
147 if ( $this->resultSet
=== false ) {
151 return $this->resultSet
->numRows();
155 if ( $this->resultSet
=== false ) {
159 $row = $this->resultSet
->fetchObject();
160 if ( $row === false ) {
164 return SearchResult
::newFromRow( $row );
168 if ( $this->resultSet
=== false ) {
172 $this->resultSet
->free();
175 function getTotalHits() {
176 if ( !is_null( $this->totalHits
) ) {
177 return $this->totalHits
;
179 // Special:Search expects a number here.
180 return $this->numRows();
186 * A SearchResultSet wrapper for SearchEngine::getNearMatch
188 class SearchNearMatchResultSet
extends SearchResultSet
{
189 private $fetched = false;
192 * @param Title|null $match Title if matched, else null
194 public function __construct( $match ) {
195 $this->result
= $match;
198 public function numRows() {
199 return $this->result ?
1 : 0;
202 public function next() {
203 if ( $this->fetched ||
!$this->result
) {
206 $this->fetched
= true;
207 return SearchResult
::newFromTitle( $this->result
);