devbox@COMPUTEC The Computec development blog

5May/102

Full-text search with ColdFusion using Sphinx

Setup

Sphinx is made up of three parts - the Sphinx API client library (which we have now already installed), an indexer component, which will be run as a cronjob, and a search daemon, which actually answers requests from the client returning document ids of the matching results along with meta data such as the total number of matches in the index. On startup, the search daemon loads the indexes built by the indexer in memory. The indexer can tell the daemon to reload the index on refresh.

It is currently not really possible to update an index once it is in place. You can however have several indexes queried at once, which allows us to define a base index which is rarely rebuild and a delta index with all the changes since the last full index run. You can also tell the indexer to merge two indexes, though I won't be going into detail on that matter - please refer to the documentation.

Now we'll have to get everything in place to allow the Sphinx daemon to actually run. It's generally not wise to have any daemon run with root privileges, so we'll create a new unprivileged account and set up some directories:

adduser --no-create-home --uid 999 --disabled-password sphinx
cd /var/run
mkdir -p sphinx
chown sphinx.sphinx sphinx
cd /var/lib/
mkdir -p sphinx
chown -R sphinx.sphinx sphinx
cd /var/log/
mkdir -p sphinx/crashlogs
chown -R sphinx.sphinx sphinx

To make sphinx start up and shut down automatically, you can use this sphinx-startup script (click to download).

Save that under /etc/init.d/sphinx. Now you can make it executable and add the appropriate symlinks to the rc.d directories to make it start/stop with the OS:

chmod +x /etc/init.d/sphinx
update-rc.d sphinx defaults

Next page: Sphinx configuration (1/3)

« »

Comments (2) Trackbacks (1)

Leave a comment

(required)