After some significant problems using acts_as_ferret (for some unknown reason, it absolutely will not run on my deployment server; the models will load in test but not in development or production if they use acts_as_ferret), I decided to try sphinx on the recommendation of Michael Hartl. Unfortunately, I had some problems there too: sphinx would not compile on my development workstation, a Dual G5 mac running OS X 10.4.
I did manage to solve it, though, by switching from the package-installed version of MySQL to a compiled-from-source copy. In case anyone else runs into the problem, here's a record of how I solved it.
Symptoms of the problem
Sphinx would not compile on my mac. The error seemed to be a complaint about the header libraries, certain MySQL symbols were not getting correctly defined:
[20:05:10] sphinx-0.9.8-rc2$ make
Making all in src
g++ -o indexer indexer.o libsphinx.a -L/usr/local/mysql/lib -lmysqlclient -lz
/usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: Undefined symbols:
collect2: ld returned 1 exit status
make: * [indexer] Error 1
make: * [all-recursive] Error 1
It also fail to build with MacPorts (
port install sphinx), with similar errors. So, after some digging I decided to try swapping out MySQL, which I'd installed from the .dmg package installer, to a copy compiled from source, hoping that this would get the header libraries set up correctly. It worked, and in the process I upgraded from 5.0.45 to the current 5.0.51b. Here's the sequence:
First, upgrade mysql to a hand-built one.
These instructions are straight from the HiveLogic instructions on building MySQL on OS X. All I've added is the backup and restore of databases plus a newer URLs for the most recent MySQL 5.0 release (as of May 16, 2008).
Back up and turn off the old server:
First, back up all your existing databases using mysqldump. I did it to a bzipped file in my home directory.
[11:39:03] evan$ mysqldump --all-databases -p | bzip2 -c > databasebackup.sql.bz2
This could take a while, depending on how many databases you have, and how large. About ten minutes, for me. Now, shut down the server and remove the symlink /usr/local/mysql:
[11:49:13] evan$ sudo mysqladmin shutdown
[11:51:56] bin$ cd /usr/local
[11:52:14] local$ sudo rm mysql
Now download and build the new mysql:
[11:47:10] evan$ cd ~/src
[11:47:23] src$ wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51b.tar.gz/from/http://mysql.he.net/
[11:48:09] src$ tar xzf mysql-5.0.51b.tar.gz
[11:48:25] src$ cd mysql-5.0.51b
Configure and compile:
[11:49:10] mysql-5.0.51b$ CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
-fno-exceptions -fno-rtti" \
[11:49:32] mysql-5.0.51b$ ./configure --prefix=/usr/local/mysql \
--with-extra-charsets=complex --enable-thread-safe-client \
[11:49:32] mysql-5.0.51b$ make; sudo make install;
This takes a while. I went to take a shower. Fortunately, for me, it worked the first time and required no hackery, which is a pleasant surprise when building OSS software. Now setup the initial directories and databases:
[12:10:17] mysql-5.0.51b$ cd /usr/local/mysql
[12:10:21] mysql-5.0.51b$ sudo ./bin/mysql_install_db --user=mysql
[12:10:28] mysql-5.0.51b$ sudo chown -R mysql ./var
And finally start the new server and import the backed-up databases:
sudo ./mysqld_safe &
bzcat ~/databasebackup.sql.bz2 | mysql
After another ten-minute import, I'm back up and running with a fresh build of MySQL.
After that, sphinx (0.9.8-rc2) compiled normally:
[13:20:51] src$ wget http://www.sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz
[13:20:56] src$ tar xzf sphinx-0.9.8-rc2.tar.gz
[13:21:09] src$ cd sphinx-0.9.8-rc2
[13:21:12] sphinx-0.9.8-rc2$ ./configure; make
[13:23:30] sphinx-0.9.8-rc2$ make install
... success ...