Manual:Enabling autocomplete in search box

From MediaWiki.org
Jump to: navigation, search

Autocomplete or Search suggestions is a feature that displays a drop-down list of suggestions below the Search box while text is being typed. On the MediaWiki platform, this feature is provided by Ajax asynchronous queries to the database. Although the basic feature is quite limited, it can be greatly enhanced with the addition of extensions.

Contents

Using the basic feature [edit]

Example of a case-insensitive autocomplete

Edit the file LocalSettings.php and add the following entries:

MediaWiki versions 1.6 and 1.7:

$wgUseAjax = true;


MediaWiki version 1.8 to 1.12:

$wgUseAjax = true;
$wgAjaxSearch = true;


MediaWiki version 1.13 to 1.19:

$wgUseAjax = true; // (optional; default is now true)
$wgEnableMWSuggest = true;


Notes:

  • The basic feature is case-sensitive, i.e, with the exception of the first letter which is always treated as an upper case, all other letters must be typed with exactly the same case of the searched item;
  • $wgUseAjax defaulted to false until MW 1.10, when it was changed to true;
  • $wgAjaxSearch was introduced in MW 1.8 and replaced by $wgEnableMWSuggest in MW 1.13;
  • $wgEnableMWSuggest was removed entirely in 1.20 and was broken before then;

Using advanced features [edit]

The advanced features require the installation of one or more extensions.

Adding case-insensitivity [edit]

Since the introduction of the auto autocomplete feature, one of the main requests was to make it case-insensitive. It was finally accomplished via a third-party extension, TitleKey, still in use by Wikipedia. Configure the basic settings above according to your version of the MediaWiki. and then install the TitleKey extension.

Extending the search capabilities [edit]

Example of an advanced feature of search suggestions

If you want a more powerful search suggestion feature, similar to the one seen in the image beside, you will have to resort to other extensions that enhance the searching capabilities of the MediaWiki:

1. Lucene-search [edit]

One such extension is Lucene-search, a search engine back-end for large MediaWiki websites which allows for distributed search and indexing, accentless search, stemmers for 12+ languages, link analysis for ranking, and namespace-prefixed queries. It is the search engine used by Wikimedia wikis.

Lucene-search requires a front-end extension to fetch the results from the search engine:

MediaWiki versions prior to 1.13:

MediaWiki version 1.13 and above:

2. SphinxSearch [edit]

Smaller sites might want to consider using SphinxSearch instead of Lucene-search. It uses the Sphinx Search Engine as the back-end. As-you-type suggestions are available in version 0.8.2 (svn r9671) and above.

After installation, the following settings are required in LocalSettings.php:

$wgEnableMWSuggest = true;
$wgEnableSphinxPrefixSearch = true;

Note: This will only work in Mediawiki Version 1.18

See also [edit]