* API search now falls back to fulltext search by default when using Lucene
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 27 Jul 2008 21:31:11 +0000 (21:31 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 27 Jul 2008 21:31:11 +0000 (21:31 +0000)
  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.

RELEASE-NOTES
includes/api/ApiQuerySearch.php

index dcfb640..4e74b24 100644 (file)
@@ -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 ===
 
index 693d621..932ca50 100644 (file)
@@ -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',