Discuz论坛上安装sphinx全文搜索详细攻略 由于discuz6或discuz7论坛在帖子和用户达到一定级别后,默认的搜索就会搜索导致mysql死锁等问题,导致性能急剧下降. 这时候就需要有个高性能的搜索引擎来替代,网上找了很多,就属Sphinx性能卓越,现在也有了中文分词的支持. 参考网站: http://www.sphinxsearch.com/ http://sphinx-for-discuz.googlecode.com/ 下载php接口 discuz6.1的: http://code.google.com/p/sphinx-for-discuz/downloads/detail?name=sphinx_for_discuz6.1.zip&can=2&q= discuz7的: http://code.google.com/p/sphinx-for-discuz/downloads/detail?name=sphinx_for_discuz7.zip&can=2&q= 需要用到的字典文件都在上面的包里面了.由于网上找了很多都有问题,默认的的接口文档还有错误.故把他整理出来,方便需要的朋友安装参考. 演示:http://www.rnjyz.com/ 同时感谢sphinx的中文支持http://www.coreseek.cn和php接口作者jayeeliu给大家带来的好东西. mmseg安装 #wget -c http://www.coreseek.cn/uploads/csft/3.1/Source/mmseg-3.1.tar.gz cd /home/tools/sphinx/3.1 tar -zxvf mmseg-3.1.tar.gz cd mmseg-3.1 ./configure --prefix=/usr/local/mmseg make make install make clean cd ../ 导入字典,words.txt文件在上面接口包中自己找. cd /usr/local/mmseg/data /usr/local/mmseg/bin/mmseg -u words.txt cp words.txt.uni /usr/local/mmseg/dict/uni.lib csft安装 # wget -c http://www.coreseek.cn/uploads/csft/3.1/Source/csft-3.1.tar.gz cd /home/tools/sphinx/3.1 tar -zxvf csft-3.1.tar.gz cd csft-3.1 ./configure \ --prefix=/usr/local/sphinx \ --with-mysql=/usr/local/mysql \ --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/include/mysql/ \ --with-mysql-libs=/usr/local/mysql/lib/mysql/ 出现liconv找不到的解决办法如下: #修改Makefile文件/home/tools/sphinx/3.1/csft-3.1/src和/home/tools/sphinx/3.1/csft-3.1/两个目录下都要改 LIBS = -lm -lz -lexpat -L/usr/local/lib -lpthread 为 LIBS = -lm -lz -lexpat -liconv -L/usr/local/lib -lpthread make make install make clean 上面已经安装完毕,下面开始生成索要和测试. 生成索引:(all前先stop searchd服务) cd /usr/local/sphinx/bin /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/dz_conf.config --all /usr/local/sphinx/bin/indexer --merge DSTINDEX SRCINDEX [--rotate] ---------如果出现libmysqlclient.so.16找不到就运行如下命令 ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16 ln -s /usr/local/libiconv/lib/libiconv.so.2 /usr/lib/libiconv.so.2 打开监听3312端口,接受查询searchd:放在linix开机自启动rc.local中 /usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/dz_conf.config 为了及时搜索到新帖,使用增量索引,用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_conf.config dzbbs_delta --rotate 0 4 * * * /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/dz_conf.config dzbbs_merge --rotate && /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/dz_conf.config --merge dzbbs dzbbs_merge --rotate */5 0-2,6-23 * * * /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/dz_conf.config threads_delta --rotate 10 4 * * * /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/dz_conf.config threads_merge --rotate && /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/dz_conf.config --merge threads threads_merge --rotate 下面开始安装php接口文件到discuz中.包中有详细的安装文档,大家根据需要修改就可以了.另外如果是discuz6.1的版本,上面的包中有错误,需要修改的地方有: search_sphinx.inc.php文件中 替换 if (isset($sp_orderby[$orderby])) { 为 if (in_array($orderby, $sp_orderby)) { ,第2个地方是$threadlist[$i]['subject'] = $sp_titles[$i];替换为 $threadlist[$l-$i-1]['subject'] = $sp_titles[$i]; 这样搜索出来的结果就是时间倒序了. 如果某些秘密版块不需要检索,可以修改sql语句,添加(fid!=110 and fid!=120) and到文件dz_conf.config中去,比如 FROM cdb_threads WHERE (fid!=110 and fid!=120) and closed = 0 AND tid>(SELECT value FROM cdb_settings WHERE variable='max_thread_id') 本文来自:http://www.rnjyz.com/ by 日内交易者,转载请保留出处.