summaryrefslogtreecommitdiff
path: root/includes/api/ApiQuerySearch.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQuerySearch.php')
-rw-r--r--includes/api/ApiQuerySearch.php37
1 files changed, 28 insertions, 9 deletions
diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php
index 84a2ec63..cb020fff 100644
--- a/includes/api/ApiQuerySearch.php
+++ b/includes/api/ApiQuerySearch.php
@@ -53,7 +53,8 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
$limit = $params['limit'];
$query = $params['search'];
- if (is_null($query) || empty($query))
+ $what = $params['what'];
+ if (strval($query) === '')
$this->dieUsage("empty search string is not allowed", 'param-search');
$search = SearchEngine::create();
@@ -61,13 +62,30 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
$search->setNamespaces( $params['namespace'] );
$search->showRedirects = $params['redirects'];
- if ($params['what'] == 'text')
+ if ($what == 'text') {
$matches = $search->searchText( $query );
- else
+ } elseif( $what == 'title' ) {
$matches = $search->searchTitle( $query );
+ } else {
+ // We default to title searches; this is a terrible legacy
+ // of the way we initially set up the MySQL fulltext-based
+ // search engine with separate title and text fields.
+ // In the future, the default should be for a combined index.
+ $what = 'title';
+ $matches = $search->searchTitle( $query );
+
+ // Not all search engines support a separate title search,
+ // for instance the Lucene-based engine we use on Wikipedia.
+ // In this case, fall back to full-text search (which will
+ // include titles in it!)
+ if( is_null( $matches ) ) {
+ $what = 'text';
+ $matches = $search->searchText( $query );
+ }
+ }
if (is_null($matches))
- $this->dieUsage("{$params['what']} search is disabled",
- "search-{$params['what']}-disabled");
+ $this->dieUsage("{$what} search is disabled",
+ "search-{$what}-disabled");
$data = array ();
$count = 0;
@@ -78,8 +96,9 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
break;
}
- // Silently skip broken titles
- if ($result->isBrokenTitle()) continue;
+ // Silently skip broken and missing titles
+ if ($result->isBrokenTitle() || $result->isMissingRevision())
+ continue;
$title = $result->getTitle();
if (is_null($resultPageSet)) {
@@ -109,7 +128,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
ApiBase :: PARAM_ISMULTI => true,
),
'what' => array (
- ApiBase :: PARAM_DFLT => 'title',
+ ApiBase :: PARAM_DFLT => null,
ApiBase :: PARAM_TYPE => array (
'title',
'text',
@@ -151,6 +170,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
}
public function getVersion() {
- return __CLASS__ . ': $Id: ApiQuerySearch.php 35098 2008-05-20 17:13:28Z ialex $';
+ return __CLASS__ . ': $Id: ApiQuerySearch.php 44186 2008-12-03 19:33:57Z catrope $';
}
}