Release status: beta
|Description||Replaces built-in MediaWiki search with Sphinx|
|Author(s)||Svemir Brkic, Paul Grinberg|
|Latest version||0.9.1 (2019-09-17)|
|Compatibility policy||release branches|
|MediaWiki||1.19 to 1.33|
|License||GNU General Public License 2.0|
|Example||New World Encyclopedia|
$wgSphinxSearch_host, $wgSphinxSearch_port, $wgSphinxSearch_index, $wgSphinxSearch_index_list, $wgSphinxSearch_index_weights, $wgSphinxSearch_mode, $wgSphinxSearch_sortmode, $wgSphinxSearch_sortby, $wgSphinxSuggestMode, $wgSphinxSearchAspellPath, $wgSphinxSearchPersonalDictionary, $wgSphinxSearch_maxmatches, $wgSphinxSearch_cutoff, $wgSphinxSearch_weights, $wgSphinxSearchMWHighlighter,$wgSearchType, $wgAdvancedSearchHighlighting, $wgEnableMWSuggest
|Translate the SphinxSearch extension if it is available at translatewiki.net|
|Check usage and version matrix.|
|Issues||Open tasks · Report a bug|
One of the most common complaints MediaWiki-based site administrators receive is that the default search engine is far from excellent. The Sphinx Search Engine provides a full text search engine that is both flexible and fast. This extension incorporates the Sphinx engine into MediaWiki to provide a better alternative for searching.
Sphinx operates as a standalone server. It creates an index which is based on a SQL query that retrieves documents from a database (Mediawiki MySQL etc.), stores indices and at a later stage returns corresponding rows that match the search.
Two separate software components are necessary, first you need the Sphinx Search Engine (hereafter called Sphinx) and second the SphinxSearch Extension (hereafter called extension).
Instructions on how to install Sphinx on Windows or Linux are similar but for a more comprehensive view on Windows and Sphinx see:
If you are running SQLite instead of MySQL, you might have a look at
Step 1 - Install SphinxEdit
Follow the installation instructions. You do not need to do the "Quick Sphinx usage tour". Note: if installing on a Windows server, you do not need to compile anything; just download the Win32 release binaries.
A more detailed description about the Sphinx Search Engine installation process can be found in Sphinx Search Beginner's Guide.
Step 2 - Configure SphinxEdit
Extract and copy the file sphinx.conf from the
extensions/SphinxSearch directory into the Sphinx installation directory (we will refer to this file as
/path/to/sphinx.conf hereafter) This directory should not be web-accessible, so you should not use the extensions folder. Make sure to adjust all values to suit your setup:
- If you are using PostgreSQL, you should copy sphinx.conf.postgres to
- Set correct database, username, and password for your MediaWiki database
- Update table names in SQL queries if your MediaWiki installation uses a prefix (backslash line breaks may need to be removed if the indexer step below fails)
- Update the file paths (
/var/log/sphinxsearch/...) and create folders as necessary.
- If your wiki is very large, you may want to consider specifying a query range in the conf file.
- If your wiki is not in English, you will need to change (or remove) the morphology attribute.
Step 3 - Run Sphinx IndexerEdit
Run the sphinx indexer to prepare for searching:
/path/to/sphinx/installation/bin/indexer --config /path/to/sphinx.conf --all
Once again, make sure to replace the paths to match your installation. This process is actually pretty fast, but clearly depends on how large your wiki is. Just be patient and watch the screen for updates.
Step 4 - Start Sphinx DaemonEdit
In order to speed up the searching capability for the wiki, we must run the sphinx in daemon mode. Add the following to whatever server startup script you have access (i.e.
/path/to/sphinx/installation/bin/searchd --config /path/to/sphinx.conf >> /var/log/sphinx/sphinx-startup.log 2>&1
Note: without the daemon running, searching will not work. That is why it is critical to make sure the daemon process is started every time the server is restarted.
For Windows see ...
Step 5 - Configure Incremental UpdatesEdit
To keep the index for the search engine up to date, the indexer must be scheduled to run at a regular interval. If your wiki is small, it's best to comment out wiki_incremental in sphinx.conf and just run the indexer for wiki_main. The reason is that wiki_main and wiki_incremental are additive only. Words that have been removed since wiki_main was updated will still appear even after wiki_incremental is run.
On most UNIX systems edit your crontab file by running the command:
Add this line to set up a cron job for the full index - for example once every night:
0 3 * * * /path/to/sphinx/installation/indexer --quiet --config /path/to/sphinx.conf wiki_main --rotate >/dev/null\ 2>&1; /path/to/sphinx/installation/indexer --quiet --config /path/to/sphinx.conf wiki_incremental --rotate >/dev/null\ 2>&1
Add this line to set up a more frequent cron to update the smaller index regularly:
0 9,15,21 * * * /path/to/sphinx/installation/indexer --quiet --config /path/to/sphinx.conf wiki_incremental --rotate >/dev/null 2>&1
As before, make sure to adjust the paths to suit your configuration. Note that --rotate option is needed if searchd deamon is already running, so that the indexer does not modify the index file while it is being used. It creates a new file and copies it over the existing one when it is done.
On Windows, commands like these inside a batch file should do the trick, provided you previously created the .CMD files running the indexer:
at 23:00 /INTERACTIVE /every:M,T,W,TH,F,S,Su "%~dp0%__IndexMain__.cmd" at 08:00 /INTERACTIVE /every:M,T,W,TH,F,S,Su "%~dp0%__IndexIncr__.cmd"
Note that those tasks will only be manageable by the "at" command, and not through the control panel "Scheduled tasks" interface.
Also, adjust the SQL query for src_wiki_incremental source in sphinx.conf to match the time in the crontab for wiki_main, keeping in mind that MediaWiki may be storing the times in UTC while server that runs the cron may be using a different time zone.
Step 6 - Extension Preparation - SphinxSearch FolderEdit
Create a 'SphinxSearch' folder, either by extracting a compressed file or downloading via GIT and place the SphinxSearch folder within the main MediaWiki 'extensions' folder.
Step 6.1 - Extension Preparation - Sphinx PHP APIEdit
If you downloaded a recent packaged version of the extension from this page, you probably already have a "vendor" folder in your extension subfolder, and you can skip the rest of this step.
If you fetched the latest version from git, run composer inside the extension folder to fetch sphinxapi.php. See Composer if not sure how to setup composer.
cd SphinxSearch composer install
If you are unable to run a composer install, or you have an old version before composer.json was added, you may also get the sphinxapi.php from this github repository and save it to the main SphinxSearch extensions folder.
Step 6.2 - Extension Installation - PHP Module (optional)Edit
There is also a sphinx extension that can be used instead of the sphinx library described in the previous step. One way to install that is:
pecl install sphinx
After the module is compiled, add it to your php configuration along other extensions, and restart your web server.
Step 7 - Extension Installation - Local SettingsEdit
In the file LocalSettings.php (for more help, please see the LocalSettings.php manual) in the main MediaWiki directory, add the following line below the:
$wgSearchType = 'SphinxMWSearch'; require_once "$IP/extensions/SphinxSearch/SphinxSearch.php";
Step 8 Show Sphinx Search SupportEdit
If you want the general public let know that you are using Sphinx as back-end search engine you might want to add the following lines to your SphinxSearch.php. The logo can be downloaded from  and be copied in the directory folder .../extensions/SphinxSearch/skins/images/
$wgFooterIcons['poweredby']['sphinxsearch'] = array( 'src' => "$wgScriptPath/extensions/SphinxSearch/skins/images/Powered_by_sphinx.png", 'url' => 'http://www.mediawiki.org/wiki/Extension:SphinxSearch', 'alt' => 'Search Powered by Sphinx', );
What can I do when it doesn't seemed to work? What should I check first? Is there a way to switch to some kind of debug mode?
For those and other questions, please consult the troubleshooting page, which is a collection of some of the more common issues that might happen during an installation.
For the most part, the extension's default options do not need any modification. However, if tweaking is needed/desired, there are a number of configuration options that could be configured from LocalSettings.php after the above require_once line. Those are:
- $wgSphinxSearch_host - the hostname on which sphinx's searchd daemon is running (defaults to localhost)
- $wgSphinxSearch_port - the port number on which sphinx's searchd daemon is running (defaults to 9312)
- $wgSphinxSearch_mode - the Sphinx search mode. The default mode is the most intuitive. See Sphinx documentation for other valid options.
- $wgSphinxSearch_matches - the number of search hits to display per result page.
- $wgSphinxSearch_weights - the way Sphinx orders the results. The default is pretty good. See Sphinx documentation for other valid options.
- $wgSphinxSearch_groupby, $wgSphinxSearch_groupsort - define how to group the results. See Sphinx documentation for other valid options.
- $wgSphinxSearch_sortby - set matches sorting mode (default to SPH_SORT_RELEVANCE). See Sphinx documentation for other valid options.
Search Box "As-You-Type" SuggestionsEdit
- $wgEnableSphinxPrefixSearch - set to true to return suggestions from sphinx index by matching the query against the beginning of page titles.
Note: If you are using an older version of MW, you may need to set $wgEnableMWSuggest to true to enable search box suggestions.
A description on how to change the default namespaces can be found here.
Did You MeanEdit
When performing a search and the search query is misspelled, the search results could be greatly impaired. Without knowing about the misspelling, it may take the user a while to figure out why their search results are not very good. That is why this extension has an optional "Did You Mean" support. When enabled, this feature will suggest a properly spelled search query for the user in case of a spelling mistake. Also, since many wikis utilize their own jargon, in order to make the "Did You Mean" suggestions more reasonable, this extension can optionally utilize a personalized dictionary.
This section is being updated. In the meantime, please see: Extension:SphinxSearch/Search suggestions
When modifying the sphinx.conf file (see #Step 2 - Configure Sphinx), there is an option for specifying a file containing search stop words. Stop words are those common words like 'a' and 'the' that appear commonly in text and should really be ignored from searching. A somewhat complete list of English stop words can be found ,  and  here. Simply copy those words into a text file, and modify your sphinx.conf to point to that file with
stopwords = /path/to/stopwords.txt
Sphinx Indexing PerformanceEdit
Please, have a look at How To Improve Sphinx Indexing Performance for more details.
Charsets for all languagesEdit
Copy the charset you need from here to the end of the definition of the charset_table in the sphinx.conf file. After doing so you need to run a full index and restart the service. See Sphinx forum or How to tell Sphinx that your document has CJK characters? for additional details.
MediaWiki prior to 1.16 is not supported.
|MW||Sphinx engine||MW Sphinx Search||Status||Description|
|1.16||?||?||works on CentOS 5.5 LAMP server (contact:email@example.com)|
|Sphinx Search 0.7.2|
|1.16.5||1.10-beta (r2420)||0.7.2||PHP 5.2.13 (apache2handler), MySQL 5.1.44-community, Windows Vista --MWJames 18:35, 3 June 2011 (UTC)|
|1.17.0||1.10-beta (r2420)||0.7.2||PHP 5.2.13 (apache2handler), MySQL 5.1.44-community, Windows Vista --MWJames 18:35, 3 June 2011 (UTC)|
|1.19alpha (r92860)||0.9.9-6||0.7.2 (r92860)||PHP 5.3.5-1ubuntu7.2 (apache2handler), MySQL 5.1.54-1ubuntu4, --Jeroen De Dauw 17:05, 22 July 2011 (UTC)|
|Sphinx Search 0.8+|
|1.16.5||2.0.5-release (r3308)||0.8.5||PHP 5.2.17 (cli), MySQL 4.1.22-community-nt, Server 2008 R2 Datacenter --Steevie (talk) 16:26, 5 August 2012 (UTC)|
|1.17.0||1.10-beta (r2420)||0.8.2||PHP 5.3.5 (apache2handler), MySQL 5.5.8, Windows Vista --MWJames 03:39, 10 September 2011 (UTC)|
|1.18.0||2.0.3-release (Dec 2011)||0.8.5||PHP 5.3.8 (apache2handler) MySQL 5.5.16, Windows Vista --MWJames 01:38, 4 January 2012 (UTC)|
|1.18.0||2.0.4-release (r3135)||0.8.5||PHP 5.3.8 (apache2handler) MySQL 5.5.16, Windows Vista --MWJames (talk) 00:17, 6 May 2012 (UTC)|
|1.19.0||2.0.4-0ubuntu1 release||0.8.5||PHP 5.3.10, Apache 2.2.22, MySQL-Client-Version: 5.5.24, Linux Ubuntu 12.04 --SmartK (talk) 12:43, 16 August 2012 (UTC)|
|1.19.2||2.0.5-release||0.8.5||PHP 5.4.6, Apache 2.2.14, Oracle Client 10.2.0 + sqlrelay-0.46, Solaris 2.10 David Taylor (talk) 18:33, 16 September 2012 (UTC)|
|1.20.2||2.0.4-0ubuntu1 release||0.8.5||PHP 5.3.10, Apache 2.2.22, MySQL-Client-Version: 5.5.28, Linux Ubuntu 12.04 --SmartK (talk) 16:11, 2 January 2013 (UTC)|
|1.22.5||2.1.1-beta Win64 w/MySQL (30-08-2013)||0.8.5||PHP 5.5.13 TS (Win64, Apache 2.0 Handler, Zend OPcache), Apache 2.4.9 (Win64), MySQL Server 5.6.11 (64 bit), Windows Server 2008 SP1 64-bit. --Felipe (talk) 08:13, 17 June 2014 (UTC)|
|1.21.1||2.0.4-0ubuntu1 release||0.8.5||PHP 5.3.10-1ubuntu3.7 (apache2handler), Apache 2.2.22, MySQL-Client-Version: 5.5.32-0ubuntu0.12.04.1, Linux Ubuntu 12.04 --SmartK (talk)|
|1.22.1||2.1.3-release||0.8.5||PHP 5.4.22, Apache 2.2.24, MySQL 5.6.14, OSX 10.9.1 --Svemir Brkic (talk) 00:45, 27 January 2014 (UTC))|
|1.23.0||2.1.8-release||0.8.5||PHP 5.4.4, Apache 2.2.22 (Debian), MySQL 5.5.37, Debian GNU/Linux 7.5 Wheezy --kraba (talk) 16:57, 25 June 2014 (UTC))|
|Sphinx Search 0.9+|
|1.24.2||2.3.1-beta Win64 (r4926)||0.9.0||PHP 5.5.24 TS (Win64, Apache 2.0 Handler, Zend OPcache), Apache 2.4.12 (Win64), MySQL Server 5.6.11 (64-bit), Windows Server 2008 SP1 64-bit. Note: Works with |
|1.29.2||2.2.9-id64-release (rel22-r5006)||0.9.0||PHP 7.0.28-0ubuntu0.16.04.1, Apache 2.4.18, MySQL 15.1 (MariaDB), Ubuntu 16.04. Note: Same warning as Felipe, managed to disable it with |
|1.33.0||2.2.11-id64-release (95ae9a6)||0.9.1||PHP 7.2.19, Lighttpd, MySQL (10.1.41-MariaDB), Ubuntu 18.04. --Svemir Brkic (talk) 20:46, 17 September 2019 (UTC)|
The extension has been shown to work with the following languages. See below for #Charsets for all languages
|English||Works||all versions - (Alpha3)|
|German||Works||W2k3 and IIS - (22.214.171.124)|
|German||Works||apache2 on Ubuntu 12.04 - (SmartK)|
|Chinese||Works||MW1.15 + XAMPP + SphinxSearch 0.7 (MarkYin)|
|Chinese||Works||Win2003 wamp 1.7.3 - (Alpha3)|
|Chinese||Works||RHEL 5.4 + Nginx + Mediawiki With HTTPS -(atyu30)|
|Chinese||Works||OpenBSD 4.5 -(atyu30)|
|Russian||Works||(XAMPP, Debian) - StasFomin.|
|Hebrew||Works||W2K3 and IIS - CrushKing.|
|Japanese||Works||MediaWiki 1.16.5, PHP 5.2.13 (apache2handler), MySQL 5.1.44-community, SphinxSearch (Version 0.7.2), Sphinx 1.10-beta (r2420), Windows Vista --MWJames 18:35, 3 June 2011 (UTC)|
The following are some links for comparing different search engines:
- "Why MediaWiki Site Search Stinks" (2008)
- Choosing a stand-alone full-text search server: Sphinx or SOLR? (2009)
- Sphinx Search Engine Comparative Benchmarks (2011)
- "A Comparison of Open Source Search Engines", Christian Middleton and Ricardo Baeza-Yates
- Assign weights to namespaces
Sort the results in SPH_SORT_EXTENDED mode by @relevance and by number of times the page has been viewed (available from wiki database). The idea behind this is that given two pages that have the same relevance to the search, if one has been viewed more times, there is probably a reason for that. Number of links to each page could also be included in the calculation.(Not official yet, but see Extension:SphinxSearch/Page rank)
- If originally "Go" was clicked, and "did you mean" link results in a direct match, redirect to that page.
- Show categories in result list
Exclude selected categories from search(done in 0.8.4)
- Support for $wgCompressRevisions
- Using the search function in templates
- Use updateAttributes call to update categories and other attributes as soon as the page is updated (at least until RT indexes become stable.)
- Bugzilla 30839 Real-time indexes (Sphinx 2.0.1)
- Bugzilla 30869 Display of relevance ranking (search confidence) within search results
- Bugzilla 32203 Support of faceted search, browsing
- Other discussions on feature requests can be found here.
- Add the ability to search multiple databases simultaneously (see also Search separate databases and display combined results)
- Support MVA (multi-valued attributes) to be able to store additional meta information (semantic properties, wikidata properties etc.) and provide a MW search profile to search for those attributes.
- Searching in files, with plugin structure to add more filetypes
For general inquiries, you might consult the SphinxSearch talk page or Troubleshooting page, while for errors appearing in connection with the extension one should file a bug report. Questions related to the Sphinxsearch software, Sphinxsearch API, Sphinxsearch indexer itself should be directed to Sphinxsearch forum.
By reporting problems or issues one should always include information about the Sphinxsearch software version, Mediawiki version and extension version to help track down possible areas of impact.
Prior to version 0.8, revisions can be downloaded at SourceForge
- v0.8 - September 7, 2011
- Use of standard MW search interface
- Support of individual indexed columns weight
- Support of three different suggestion mode (enchant, soundex, aspell)
- Still updating the documenation
Wikis that use SphinxSearchEdit
- New World Encyclopedia is an excellent example of this extension in use.
- Rhea/Assimi is a visual search engine using the SphinxSearch extension to MediaWiki.
- despite-behavior.com is a French installation guide.
- Mars Tekkom DK is a site using an older version of this extension, and it has good installation instructions
- IEEE Global History Network uses SphinxSearch to search documentation, analysis and explanation of the history of electrical, electronic, and computer technologies of its Global History Network wiki.