From: Brion Vibber Date: Sun, 27 Jul 2008 21:31:11 +0000 (+0000) Subject: * API search now falls back to fulltext search by default when using Lucene X-Git-Tag: 1.31.0-rc.0~46344 X-Git-Url: https://git.cyclocoop.org/%27%20.%20%24this-%3EgetSkin%28%29-%3EescapeSearchLink%28%29%20.%20%27?a=commitdiff_plain;h=c85a7e6c83c786c2655ce548ab328434fc48476d;p=lhc%2Fweb%2Fwiklou.git * API search now falls back to fulltext search by default when using Lucene or other engine which doesn't support a separate title search function. This means you can use API search on Wikipedia without explicitly adding &srwhat=text to the query. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index dcfb640441..4e74b24190 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -45,6 +45,11 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Registration time of users registered before the DB field was created is now shown as empty instead of the current time. +* API search now falls back to fulltext search by default when using Lucene + or other engine which doesn't support a separate title search function. + This means you can use API search on Wikipedia without explicitly adding + &srwhat=text to the query. + === Languages updated in 1.14 === diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 693d621b4b..932ca5055d 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -53,6 +53,7 @@ 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'); @@ -61,13 +62,27 @@ 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. + $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; @@ -109,7 +124,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',