/**
* Query module to perform full text search within wiki titles and content
*
- * @addtogroup API
+ * @ingroup API
*/
class ApiQuerySearch extends ApiQueryGeneratorBase {
$limit = $params['limit'];
$query = $params['search'];
+ $what = $params['what'];
if (is_null($query) || empty($query))
$this->dieUsage("empty search string is not allowed", 'param-search');
$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.
+ $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 ) )
+ $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;
break;
}
+ // Silently skip broken and missing titles
+ if ($result->isBrokenTitle() || $result->isMissingRevision())
+ continue;
+
$title = $result->getTitle();
if (is_null($resultPageSet)) {
$data[] = array(
ApiBase :: PARAM_ISMULTI => true,
),
'what' => array (
- ApiBase :: PARAM_DFLT => 'title',
+ ApiBase :: PARAM_DFLT => null,
ApiBase :: PARAM_TYPE => array (
'title',
'text',