Sphinx的Searchd守护进程__解决PHP调用Sphinx
Post by
yaohuaq
  2009-02-15 11:55:36 Sunday Tags:sphinx,searchd,php,进程

Sphinx是一个基于SQL的全文检索引擎,可以结合MySQL,PostgreSQL做全文搜索,它可以提供比数据库本身更专业的搜索功能.

Sphinx,建立好索引后在命令行 search -c e:\sphinx\sphinx.conf key
这样是可以搜索出Key的索引,但是在PHP的WEB界面是不能用命令行进行搜索吧~~
Sphinx有现成的PHP的API,但是在调用时,老是出错,出错在两个方面,
一:索引没配置好(针对Windows系统)
sql_attr_uint 得配置完整

二:Searchd没有成功开启
在命令行下 searchd -config e:\sphinx\sphinx.conf
提示seamless_rotate得设置为0
重新配置下sphinx.conf
重新生成索引,indexer --config e:\sphinx\sphinx.conf --all 重新生成索引后,
再次启动Searchd进程,监听3312端口
E:\Sphinx\bin>searchd --config e:\sphinx\sphinx.conf
Sphinx 0.9.8-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff
WARNING: forcing --console mode on Windows
using config file 'e:\sphinx\sphinx.conf'...
creating server socket on 0.0.0.0:3312
accepting connections
---------------------------------------------
OK ,基本上可以在PHP的WEB界面调用Sphinx搜索引擎了
搜索后返回
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => author [1] => title [2] => content [3] => image ) [attrs] => Array ( [cid] => 1 [time] => 2 ) [matches] => Array ( [7] => Array ( [weight] => 1 [attrs] => Array ( [cid] => 8 [time] => 2009 ) ) [13] => Array ( [weight] => 1 [attrs] => Array ( [cid] => 8 [time] => 2009 ) ) [14] => Array ( [weight] => 1 [attrs] => Array ( [cid] => 8 [time] => 2009 ) ) [15] => Array ( [weight] => 1 [attrs] => Array ( [cid] => 8 [time] => 2009 ) ) [16] => Array ( [weight] => 1 [attrs] => Array ( [cid] => 8 [time] => 2009 ) ) [21] => Array ( [weight] => 1 [attrs] => Array ( [cid] => 6 [time] => 2009 ) ) [22] => Array ( [weight] => 1 [attrs] => Array ( [cid] => 4 [time] => 2009 ) ) [23] => Array ( [weight] => 1 [attrs] => Array ( [cid] => 12 [time] => 2009 ) ) [24] => Array ( [weight] => 1 [attrs] => Array ( [cid] => 8 [time] => 2009 ) ) ) [total] => 9 [total_found] => 9 [time] => 0.000 [words] => Array ( [admin] => Array ( [docs] => 9 [hits] => 61 ) ) )
取其中的CID,对MYSQL数据库进行查询,条件就为where cid=$cid;
调用API的BuildExcerpts方法,对返回的数据进行过滤,筛选,截取,就是一个类似百度的很强大的WEB界面搜索引擎了。

这两天的时间花在了解决PHP和Sphinx的API上了,其实主要还是Searchd进程没有成功开启~
找到原因,问题马上就解决了~~

评论:
发表评论:
姓名:
联系方法:(选填)
评论内容:
个人信息
欠X的生活
昵称:c77cc
QQ:
Email:yaohuaq#gmail.com
居住地:北京 海淀
星座:
毕业院校:
工作点:lighthonor.com