devbox@COMPUTEC The Computec development blog

5May/102

Full-text search with ColdFusion using Sphinx

Compiling Sphinx

First we'll need to download the source tarball from sphinxsearch.com along with client libraries for PostgreSQL and MySQL and the Stemmer and unpack everything; for PostgreSQL I always roll my own, whereas for MySQL I use what Debian has to offer. If you stumple over any configure errors, please resolve those dependencies by installing the required packages first (aptitude is your friend).

aptitude install make g++ libmysqlclient-dev libexpat-dev flex bison libreadline-dev libxml2-dev libxslt-dev
mkdir -p /usr/src/postgresql
cd /usr/src/postgresql/
wget "http://ftp.de.postgresql.org/packages/databases/PostgreSQL/v8.4.3/postgresql-8.4.3.tar.bz2"
tar -jxvf postgresql-8.4.3.tar.bz2
cd postgresql-8.4.3
./configure --prefix=/opt/pgsql --datadir=/opt/pgsql/share --with-perl --with-libxml --with-libxslt
make
make install
mkdir -p /usr/src/sphinx
cd /usr/src/sphinx
wget "http://sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz"
tar -zxvf sphinx-0.9.9.tar.gz
cd sphinx-0.9.9
wget http://snowball.tartarus.org/dist/libstemmer_c.tgz
tar -zxvf libstemmer_c.tgz

Almost ready to compile now. There is an annoying little locking problem even in this final 0.9.9 version however; you'll need to make a small adjustment to the file src/sphinx.cpp before compiling - just add the line m_iLockFD = -1; after the ::close ( m_iLockFD ); on line 14388 - here's the diff to show the change:

--- sphinx.cpp.bak        2009-11-30 03:13:28.000000000 +0100
+++ sphinx.cpp  2010-04-23 09:19:54.000000000 +0200
@@ -14386,6 +14386,7 @@
        {
                m_sLastError.SetSprintf ( "failed to lock %s: %s", sName, strerror(errno) );
                ::close ( m_iLockFD );
+               m_iLockFD = -1;
                return false;
        }

Now that's done you can go ahead with compilation and installation:

./configure --prefix=/opt/sphinx --sysconfdir=/etc/sphinx --localstatedir=/var/lib/sphinx --with-mysql --with-pgsql --with-pgsql-includes=/opt/pgsql/include/ --with-pgsql-libs=/opt/pgsql/lib/ --with-libstemmer --with-iconv
make
make install

Now the server part is installed, you'll want to compile the Java client library (or download the sphinxapi.jar I already compiled):

aptitude install sun-java6-jdk
cd /usr/src/sphinx/sphinx-0.9.9/api/java
JAVA_HOME=/usr/lib/jvm/java-6-sun/
make

When this has completed you should find a shiny new sphinxapi.jar, which you should copy to your ColdFusion server's classpath before restarting ColdFusion. The target directory would be /opt/coldfusion8/lib/ for a standalone install. Check the classpath output on the info page of your ColdFusion Administrator after the restart to make sure that ColdFusion has discovered the jar-file.

Next page: Sphinx setup

« »

Comments (2) Trackbacks (1)

Leave a comment

(required)