`

sphinx-0.99 + ultrasphinx

 
阅读更多

一、Installing Sphinx

1.Extract everything from the distribution tarball (haven't you already?) and go to the sphinx subdirectory:
$ tar xzvf sphinx-0.9.9.tar.gz
$ cd sphinx

2.Run the configuration program:
$ ./configure
There's a number of options to configure. The complete listing may be obtained by using --help switch. The most important ones are:
    * --prefix, which specifies where to install Sphinx;
    * --with-mysql, which specifies where to look for MySQL include and library files, if auto-detection fails;
    * --with-pgsql, which specifies where to look for PostgreSQL include and library files.

3.Build the binaries:
$ make

4.Install the binaries in the directory of your choice:
$ make install

after successfully install:
[/usr/local]whereis searchd
searchd: /usr/local/bin/searchd
[/usr/local]
[/usr/local]which is searchd
/usr/local/bin/searchd

二、install dependencies and config

1.install ultrasphinx
cd rails_app
script/plugin install git://github.com/fauna/ultrasphinx.git
#script/plugin install svn://rubyforge.org/var/svn/fauna/ultrasphinx/trunk


2. 修改Sphinx配置文件并创建索引
安装完Ultrasphinx之后,将:vendor/plugins/ultrasphinx/examples/default.base
复制到:config/ultrasphinx/default.base

修改Model代码,加入全文检索支持:
假设我有一个Model叫做Project,其中有一个属性叫做name,我希望对这个属性做全文检索,我在project.rb中加入一行:is_indexed :fields => ['created_at', 'name']
For more index options, see ActiveRecord::Base .is_indexed.
/home/simon/NetBeansProjects/my_sphinx/vendor/plugins/ultrasphinx/lib/ultrasphinx/is_indexed.rb



生成配置文件:rake ultrasphinx:configure
这条命令执行后,在config/ultrasphinx下创建了一个development.conf,这个文件就是Sphinx的配置文件。

创建索引:rake ultrasphinx:index
索引相关的文件创建在base指定的目录


3. 启动Sphinx的searchd服务:
rake ultrasphinx:daemon:start

这个时候会在3313端口启动一个searchd,搜索请求将会全部发送到这个端口来执行。
也可以自己手工来启动searchd
searchd


4. 测试
script/console
search = Ultrasphinx::Search.new(:class_names => 'Project')
search.run
search.results

如果执行这几条语句都没有报错,那么安装就成功了。

more about Ultrasphinx::Search.new see:
/home/simon/NetBeansProjects/my_sphinx/vendor/plugins/ultrasphinx/lib/ultrasphinx/search.rb


rake ultrasphinx:configure
rake ultrasphinx:index
rake ultrasphinx:daemon:start




分享到:
评论
1 楼 songfantasy 2012-05-25  
great

相关推荐

Global site tag (gtag.js) - Google Analytics