Pages

Sunday, February 13, 2011

sphinx search config scripts

I just finished converting the bikesoup search to use the sphinx search engine instead of a simple doctrine fulltext search with filters.
One thing I found helpful are sphinx config scripts. Instead of hard-coding the configuration you can use any scripting language to produce the sphinx configuration. The just have to start with '#!' and sphinx will execute them and use the output as the configuration.
This is the simplified version of my main config file /etc/sphinx/sphinx.conf :
#!/bin/bash 
for i in /etc/sphinx.d/*.conf; do
 cat $i
done
for i in /etc/sphinx.d/*.conf.sh; do 
 $i
done
Then I have a /etc/sphinx.d/searchd.conf which just contains the "searchd {}" section.
And various symlinks like /etc/sphinx.d/bikesoup_dev.conf.sh into the project directories of the site.
Those scripts then create the correct configuration, they figure out the index names from the local configuration and start symfony tasks to create the xmlpipe2 output.
Nice and simple.

No comments:

Post a Comment