User:Dan Nessett/Technical/Notes on setting up Sphinx Search Engine
Installing Sphinx Search Engine Daemon
Installing on Ubuntu
http://www.postneo.com/2009/02/06/sphinx-search-with-postgresql
From this URL (modified to work properly):
Install build toolchain:
sudo aptitude install build-essential checkinstall
Install Postgres:
sudo aptitude install postgresql postgresql-client \ postgresql-client-common postgresql-contrib \ postgresql-server-dev-8.3
Note to self: The first two shouldn't be necessary, since postgresql should already be installed. However, the last one probably is required:
sudo aptitude install postgresql-server-dev-8.3
Get Sphinx source:
cd /usr/local/src sudo mkdir sphinx cd sphinx sudo wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz sudo tar xzvf sphinx-0.9.9.tar.gz cd sphinx-0.9.9
Configure and make:
sudo ./configure --without-mysql --with-pgsql \ --with-pgsql-includes=/usr/include/postgresql/ \ --with-pgsql-lib=/usr/lib/postgresql/8.3/lib/ sudo make
Run checkinstall:
sudo mkdir /usr/local/var sudo checkinstall
Sphinx is now installed in /usr/local. Check out /usr/local/etc/ for configuration info.
Installing on CentOS 5.4
Installing Sphinx Search Extension
http://www.mediawiki.org/wiki/Extension:SphinxSearch#Step_1_-_Install_Sphinx
Configure Sphinx
Download and extract the extension to a temporary directory. Copy the sphinx.conf file from this download to some directory (we will refer to this file as "/path/to/sphinx.conf" below.) 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: 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/data/sphinx/..., /var/log/sphinx/...) 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.
Note: To give credit where credit is due, we must thank the author of this excellent article for providing an excellent starting point on configuring this file.
Run Sphinx Indexer
Run the sphinx indexer to prepare for searching:
/usr/local/bin/indexer --config /usr/local/etc/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.
Test Out Sphinx
When the indexer is finished, test that sphinx searching is actually working:
/usr/local/bin/search --config /usr/local/etc/sphinx.conf "search string"
You will see the result stats immediately (Sphinx is FAST.) Note that the article data you see at this point comes from the sql_query_info in sphinx.conf file. In the extension we can get to the actual article content because we have text old_id available as an extra attribute. It would be slow to fetch article content on the command line (we would have to join page, revision, and text tables,) so we just fetch page_title and page_namespace at this point.
Start Sphinx Daemon
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. /etc/rc.local):
/usr/local/bin/searchd --config /usr/local/etc/sphinx.conf &
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. Please Refer http://www.mediawiki.org/wiki/Extension_talk:SphinxSearch#More_Windows_Install_Issues for help for Windows Users
Configure Incremental Updates
To keep the index for the search engine up to date, the indexer must be scheduled to run at a regular interval. On most UNIX systems edit your crontab file by running the command: crontab -e
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
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.
Extension Preparation - Sphinx PHP API
Create extensions/SphinxSearch directory and copy the Sphinx API file, sphinxapi.php there. This file is part of the sphinx download, under the api/ directory. You will need to copy this file again each time you update the Sphinx engine.
Extension Installation - PHP Files
Copy all remaining files (SphinxSearch.php, SphinxSearch_body.php, etc.) from the temporary directory you extracted the code to in #Step 2 to your extensions/SphinxSearch directory.
Extension Installation - Local Settings
Add the following text to your LocalSettings.php require_once( "$IP/extensions/SphinxSearch/SphinxSearch.php" );