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
{
28 protected $containedSyntax = false;
30 public function __construct( $containedSyntax = false ) {
31 $this->containedSyntax
= $containedSyntax;
35 * Fetch an array of regular expression fragments for matching
36 * the search terms as parsed by this engine in a text extract.
41 function termMatches() {
50 * Some search modes return a total hit count for the query
51 * in the entire article database. This may include pages
52 * in namespaces that would not be matched on the given
55 * Return null if no total hits number is supported.
59 function getTotalHits() {
64 * Some search modes return a suggested alternate term if there are
65 * no exact hits. Returns true if there is one on this set.
69 function hasSuggestion() {
74 * @return string Suggested query, null if none
76 function getSuggestionQuery() {
81 * @return string HTML highlighted suggested query, '' if none
83 function getSuggestionSnippet() {
88 * Return a result set of hits on other (multiple) wikis associated with this one
90 * @return SearchResultSet
92 function getInterwikiResults() {
97 * Check if there are results on other wikis
101 function hasInterwikiResults() {
102 return $this->getInterwikiResults() != null;
106 * Fetches next search result, or false.
109 * @return SearchResult
116 * Frees the result set, if applicable.
123 * Did the search contain search syntax? If so, Special:Search won't offer
124 * the user a link to a create a page named by the search string because the
125 * name would contain the search syntax.
128 public function searchContainedSyntax() {
129 return $this->containedSyntax
;
134 * This class is used for different SQL-based search engines shipped with MediaWiki
137 class SqlSearchResultSet
extends SearchResultSet
{
138 protected $resultSet;
140 protected $totalHits;
142 function __construct( $resultSet, $terms, $total = null ) {
143 $this->resultSet
= $resultSet;
144 $this->terms
= $terms;
145 $this->totalHits
= $total;
148 function termMatches() {
153 if ( $this->resultSet
=== false ) {
157 return $this->resultSet
->numRows();
161 if ( $this->resultSet
=== false ) {
165 $row = $this->resultSet
->fetchObject();
166 if ( $row === false ) {
170 return SearchResult
::newFromTitle(
171 Title
::makeTitle( $row->page_namespace
, $row->page_title
)
176 if ( $this->resultSet
=== false ) {
180 $this->resultSet
->free();
183 function getTotalHits() {
184 if ( !is_null( $this->totalHits
) ) {
185 return $this->totalHits
;
187 // Special:Search expects a number here.
188 return $this->numRows();
194 * A SearchResultSet wrapper for SearchEngine::getNearMatch
196 class SearchNearMatchResultSet
extends SearchResultSet
{
197 private $fetched = false;
200 * @param Title|null $match Title if matched, else null
202 public function __construct( $match ) {
203 $this->result
= $match;
206 public function numRows() {
207 return $this->result ?
1 : 0;
210 public function next() {
211 if ( $this->fetched ||
!$this->result
) {
214 $this->fetched
= true;
215 return SearchResult
::newFromTitle( $this->result
);