Sphinx安装配置应用(2)

log = /usr/local/sphinx/var/log/searchd.log #### 服务进程日志 ,一旦sphinx出现异常,基本上可以从这里查询有效信息,轮换(rotate)出的问题一般可在此寻到答案
query_log = /usr/local/sphinx/var/log/query.log ### 客户端查询日志,笔者注:若欲对一些关键词进行统计,可以分析此日志文件
read_timeout = 5 ## 请求超时
max_children = 30 ### 同时可执行的最大searchd 进程数
pid_file = /usr/local/sphinx/var/log/searchd.pid #######进程ID文件
max_matches = 1000 ### 查询结果的最大返回数
seamless_rotate = 1 ### 是否支持无缝切换,做增量索引时通常需要
}

4、建索引

[root@localhost sphinx]# bin/indexer -c etc/sphinx.conf article ### 建立索引文件的命令,article替换成 --all可以建配置文件的所有索引
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file ‘etc/sphinx.conf’…
indexing index ‘article’…
collected 1000 docs, 0.2 MB
sorted 0.4 Mhits, 99.6% done
total 1000 docs, 210559 bytes
total 3.585 sec, 58723 bytes/sec, 278.89 docs/sec
total 2 reads, 0.031 sec, 1428.8 kb/call avg, 15.6 msec/call avg
total 11 writes, 0.032 sec, 671.6 kb/call avg, 2.9 msec/call avg

5、应用

在上一步中,我们建立了索引,现在我们对刚建立的索引进行测试。测试有两种方式:CLI端和API调用

(1)在CLI端上命令测试是使用sphinx自带的搜索命令:search

[root@localhost sphinx]# bin/search -c etc/sphinx.conf 刘利
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file ‘etc/sphinx.conf’…

index 'mdmLoginLog': query '刘利 ': returned 6 matches of 6 total in 0.000 sec

displaying matches:
1. document=2, weight=2
2. document=3, weight=2
3. document=4, weight=2
4. document=5, weight=2
5. document=7, weight=2
6. document=8, weight=2

words:
1. '刘': 6 documents, 6 hits
2. '利': 6 documents, 6 hits

(2)使用PHP的api来测试,在测试前,先启动sphinx服务进程,并对centos的防火墙做好9312端口的开放

[root@localhost sphinx]# bin/searchd -c etc/sphinx.conf & ### 使sphinx在后台运行
[1] 5759
[root@localhost sphinx]# Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file ‘etc/sphinx.conf’…
listening on all interfaces, port=9312

[1]+ Done bin/searchd -c etc/sphinx.conf

Sphinx+MySQL+PHP 12亿DNS数据秒查 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/23e751ea436c86c5dd451e85900f229c.html