Chinaunix首页 | 论坛 | 博客
  • 博客访问: 88940
  • 博文数量: 31
  • 博客积分: 886
  • 博客等级: 准尉
  • 技术积分: 245
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-02 10:45
文章分类

全部博文(31)

文章存档

2011年(31)

我的朋友

分类: 系统运维

2011-01-23 17:56:37

Sphinx配置文件+Discuz补充文件下载: http://sphinx-for-discuz.googlecode.com/files/sphinx_for_discuz7.zip

这篇文章主要介绍用sphinx(csft)做discuz论坛的全文搜索,操作系统为linux,如果需要windows下的可直接参考:

sphinx + mmseg安装,这里的sphinx指的是csft,详见:

安装 mmseg :

# wget -c uploads/csft/3.1/Source/mmseg-3.1.tar.gz
# tar -zxvf mmseg-3.1.tar.gz
# cd mmseg-3.1
# ./configure  –prefix=/usr/local/mmseg
# make
# make install
# make clean
# cd ../

生成词典:
如果这个词库词量过小,可到搜狗上下载词库:
很多词库找不到TXT版的下载,可以直接通过地址: 词库id ,来下载

mmseg -u words.txt (utf-8编码)
cp ciku.txt.uni /usr/local/mmseg/dict/uni.lib

安装 csft :

# wget -c uploads/csft/3.1/Source/csft-3.1.tar.gz
# tar -zxvf csft-3.1.tar.gz
# cd csft-3.1
# ./configure \
–prefix=/usr/local/sphinx \
–with-mysql=/usr/local/mysql-5.1.28-rc \
–with-mmseg=/usr/local/mmseg \
–with-mmseg-includes=/usr/local/mmseg/include/mmseg/ \
–with-mmseg-libs=/usr/local/mmseg/lib/ \
–with-mysql-includes=/usr/local/mysql-5.1.28-rc/include/mysql/ \
–with-mysql-libs=/usr/local/mysql-5.1.28-rc/lib/mysql/

注意:修改/usr/local/mysql-5.1.28-rc为相应的mysql目录

——————————————————
生成索引:

indexer –config /usr/local/sphinx/etc/dz_conf.config –all
indexer –merge DSTINDEX SRCINDEX [--rotate]

CLI测试:

search –config /usr/local/sphinx/etc/dz_conf.config “xxx”

searchd:

/usr/local/sphinx/bin/searchd –config /usr/local/sphinx/etc/dz_conf.conf

——————————————————

配置文件:dz_data.conf
注意:修改source dzbbs和source threads 中的sql_host、sql_user、sql_pass、sql_db、sql_port参数,配置文件是按discuz的默认表前缀写的sql,所以修改了表前缀的请将cdb_替换为更改后的前缀。

首次运行:

/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/sphinx.conf dzbbs
/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/sphinx.conf threads
/usr/local/sphinx/bin/searchd –config /usr/local/sphinx/etc/sphinx.conf

如果论坛数据量比较大,这次执行可能比较耗时,这里生成的就是主索引。

为了及时搜索到新帖,使用增量索引,用cron来实现,使用crontab -e( root )或crontab -u user -e来添加。
下面的配置代表每天0点到2点,6点到23点这段时间中每5分钟生成一次增量索引,每天4点合并一次主索引和增量索引
全部帖子:

*/5 0-2,6-23 * * * /usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/dz_data.conf dzbbs_delta –rotate
0 4 * * * /usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/dz_data.conf dzbbs_merge –rotate && /usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/dz_data.conf –merge dzbbs dzbbs_merge –rotate

*/5 0-2,6-23 * * * /usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/dz_data.conf threads_delta –rotate
10 4 * * * /usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/dz_data.conf threads_merge –rotate && /usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/dz_data.conf –merge threads threads_merge –rotate

简单的说下crontab中前两个位置的配置,
*/5 0-2,6-23
前面的位置表示分钟,*/5代表每五分钟,如果是*则代表每分钟,也可以是0-59之间的具体整数,如10 4代表4点10分执行,这里可以根据需要调整;
后面的位置表示小时,0-2,6-23代表0点到2点、6点到23点,当然也可以写成*来实现每小时都执行,这里主要是考虑到2点到6点这段时间发帖量很小;

阅读(4885) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~