Index: trunk/phase3/includes/api/ApiQuerySearch.php |
— | — | @@ -53,6 +53,7 @@ |
54 | 54 | |
55 | 55 | $limit = $params['limit']; |
56 | 56 | $query = $params['search']; |
| 57 | + $what = $params['what']; |
57 | 58 | if (is_null($query) || empty($query)) |
58 | 59 | $this->dieUsage("empty search string is not allowed", 'param-search'); |
59 | 60 | |
— | — | @@ -61,13 +62,27 @@ |
62 | 63 | $search->setNamespaces( $params['namespace'] ); |
63 | 64 | $search->showRedirects = $params['redirects']; |
64 | 65 | |
65 | | - if ($params['what'] == 'text') |
| 66 | + if ($what == 'text') { |
66 | 67 | $matches = $search->searchText( $query ); |
67 | | - else |
| 68 | + } elseif( $what == 'title' ) { |
68 | 69 | $matches = $search->searchTitle( $query ); |
| 70 | + } else { |
| 71 | + // We default to title searches; this is a terrible legacy |
| 72 | + // of the way we initially set up the MySQL fulltext-based |
| 73 | + // search engine with separate title and text fields. |
| 74 | + // In the future, the default should be for a combined index. |
| 75 | + $matches = $search->searchTitle( $query ); |
| 76 | + |
| 77 | + // Not all search engines support a separate title search, |
| 78 | + // for instance the Lucene-based engine we use on Wikipedia. |
| 79 | + // In this case, fall back to full-text search (which will |
| 80 | + // include titles in it!) |
| 81 | + if( is_null( $matches ) ) |
| 82 | + $matches = $search->searchText( $query ); |
| 83 | + } |
69 | 84 | if (is_null($matches)) |
70 | | - $this->dieUsage("{$params['what']} search is disabled", |
71 | | - "search-{$params['what']}-disabled"); |
| 85 | + $this->dieUsage("{$what} search is disabled", |
| 86 | + "search-{$what}-disabled"); |
72 | 87 | |
73 | 88 | $data = array (); |
74 | 89 | $count = 0; |
— | — | @@ -109,7 +124,7 @@ |
110 | 125 | ApiBase :: PARAM_ISMULTI => true, |
111 | 126 | ), |
112 | 127 | 'what' => array ( |
113 | | - ApiBase :: PARAM_DFLT => 'title', |
| 128 | + ApiBase :: PARAM_DFLT => null, |
114 | 129 | ApiBase :: PARAM_TYPE => array ( |
115 | 130 | 'title', |
116 | 131 | 'text', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -45,7 +45,12 @@ |
46 | 46 | |
47 | 47 | * Registration time of users registered before the DB field was created is now |
48 | 48 | shown as empty instead of the current time. |
| 49 | +* API search now falls back to fulltext search by default when using Lucene |
| 50 | + or other engine which doesn't support a separate title search function. |
| 51 | + This means you can use API search on Wikipedia without explicitly adding |
| 52 | + &srwhat=text to the query. |
49 | 53 | |
| 54 | + |
50 | 55 | === Languages updated in 1.14 === |
51 | 56 | |
52 | 57 | MediaWiki supports over 300 languages. Many localisations are updated |