标签:
1.在http://sphinxsearch.com/downloads/release/下载32位版本(先是试了下64位版本,运行searchd的时候出错,不知道怎么解决,32位版本的不报错)。
2.压缩包解压。将sphinx-min.conf.in复制一份副本并改名为sphinx.conf,并且新建两个文件夹,分别为data和log
3.sphinx.conf里面的配置参数要改的地方如下(按照自己的环境进行修改):
# # Minimal Sphinx configuration sample (clean, simple, functional) # source src1 { type = mysql sql_host = localhost sql_user = test sql_pass = 1234 sql_db = test sql_port = 3306 # optional, default is 3306 sql_query = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents sql_attr_uint = group_id sql_attr_timestamp = date_added } index test1 { source = src1 path = D:/program/sphinx-2.2.6-release-win32/data/ } #index testrt #{ # type = rt # rt_mem_limit = 128M # # path = @CONFDIR@/data/testrt # # rt_field = title # rt_field = content # rt_attr_uint = gid #} indexer { mem_limit = 128M } searchd { listen = 9312 listen = 9306:mysql41 log = D:/program/sphinx-2.2.6-release-win32/log/searchd.log query_log = D:/program/sphinx-2.2.6-release-win32/log/query.log read_timeout = 5 max_children = 30 pid_file = D:/program/sphinx-2.2.6-release-win32/log/searchd.pid seamless_rotate = 1 preopen_indexes = 1 unlink_old = 1 workers = threads # for RT to work binlog_path = D:/program/sphinx-2.2.6-release-win32/data/ }
4.可以将sphinx压缩包内自带的example.sql导入进本地mysql中,以便测试:
>mysql -utest -p test < example.sql
5.命令行切换到sphinx的根目录下面,执行以下命令建立索引:
>bin\indexer.exe test1
6.执行以下命令建立搜索服务:
>sc delete searchd
>bin\searchd.exe --install --config D:/program/sphinx-2.2.6-release-win32/sphinx.conf
7.利用sphinxapi.php进行测试,在web目录下面新建一个php测试文件:
<?php require(‘sphinxapi.php‘); $s=new SphinxClient(); $s->SetServer(‘localhost‘, ‘9312‘); $result=$s->Query(‘test‘, ‘test1‘); echo ‘<pre>‘; print_r($result); echo ‘</pre>‘; ?>
以下是浏览器输出:
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => title [1] => content ) [attrs] => Array ( [group_id] => 1 [date_added] => 2 ) [matches] => Array ( [1] => Array ( [weight] => 2421 [attrs] => Array ( [group_id] => 1 [date_added] => 1419180445 ) ) [2] => Array ( [weight] => 2421 [attrs] => Array ( [group_id] => 1 [date_added] => 1419180445 ) ) [4] => Array ( [weight] => 1442 [attrs] => Array ( [group_id] => 2 [date_added] => 1419180445 ) ) ) [total] => 3 [total_found] => 3 [time] => 0.000 [words] => Array ( [test] => Array ( [docs] => 3 [hits] => 5 ) ) )
标签:
原文地址:http://www.cnblogs.com/yxzblue/p/4177388.html