What’s Ultrasphinx ? Ultrasphinx is ruby on rails plugin that utilize Sphinx, the open source Full text search engine, why we need another 3rd party library to query our database ?, it’s because Ultrasphinx fairly fast and easy to use, last week i’ve tried to install it on My lovely Werewolf, then here it is :
Install mysql server and mysql devel
sudo yum install mysql-server mysql-devel
some note : sphinx use mysql-devel to interfacing with mysql databases, for first time, i am very frustrating to compile it on my werewolf and people got the same problem like me too, so after hours + cofeemix and searching on the internet, fortunately i got the saviour, … mysql-devel of course
download sphinx
wget http://www.sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz
configure and install it
tar -xzf sphinx-0.9.8-rc2.tar.gz
cd sphinx-0.9.8-rc2
./configure
make
make install
create log folder
mkdir -p /var/db/sphinx/log
chmod -R 777 /var/db/
install chronic gem
gem install chronic
go to your RAILS_ROOT directory and install ultrasphinx plugin
ruby script/plugin install svn://rubyforge.org/var/svn/fauna/ultrasphinx/trunk
congratz, ultrasphinx already installed on your rails application, then after this i will show you a little example how to implement that
say you have User model and you want the app be able to search name, email and address easily
class User< ActiveRecord::Base is_indexed :fields => [’name’, ‘email’,'address’] end
configure and start ultrasphinx daemon
rake ultrasphinx:bootstrap
or
rake ultrasphinx:configure
rake ultrasphinx:daemon:start
run the indexer
rake ultrasphinx:index
note : Sphinx is a asynchronous search engine, so it is necessary to reindex your data periodically, so perhaps you need to re-index that 10-20 minutes a time, you can make cronjob for this
execute rails console and ultrasphinx on user model
ruby script/console
@search_user = Ultrasphinx::Search.new(:query => “aditya”)
@search_user.run
@search_user.results
DONE and for your reference, here i put rake command that related to ultrasphinx
rake ultrasphinx:bootstrap = Bootstrap a full Sphinx environment
rake ultrasphinx:configure = Rebuild the configuration file for the first time
rake ultrasphinx:daemon:restart = Restart the search daemon
rake ultrasphinx:daemon:start = Start the search daemon
rake ultrasphinx:daemon:status = Check if the search daemon is running
rake ultrasphinx:daemon:stop = Stop the search daemon
rake ultrasphinx:index = Reindex and rotate all indexes.
rake ultrasphinx:index:delta = Reindex and rotate the delta index.
rake ultrasphinx:index:main = Reindex and rotate the main index.
rake ultrasphinx:index:merge = Merge the delta index into the main index.
rake ultrasphinx:spelling:build # Rebuild the custom spelling dictionary.
Credit :
thank’s to Nikada team for the help