discuzx3.1文章进行全文检索的实现方法


本文整理自网络,侵删。

首先说明啊,这个检索是直接用like来弄的,所以,如果你的站数据量大,这样很吃系统,自己掂量着办,我研究了下利用sphinx的,结果搞定了才发现这个只是针对论坛的帖子。搜索门户中的文章,并不是按这个走的,而且利用sphinx这个啊,要么只能分中文要么只能分英文(学艺不精没细了解啊,个人测试是这样的)。而我目前碰到的要求是需要对文章也执行like。所以,经过研究,类比了下搜索文章标题的功能,成功实现了discuzX3对门户中的文章进行全文检索的功能,以下操作方法discuz版本为20140101的X3.1。具体方法如下:

1.用notepad++或其他文本编辑器打开下述文件

网站目录\source\class\table\table_portal_article_content.php
2.在下面的

代码如下:

class table_portal_article_content extends discuz_table
{

后添加

代码如下:

public function fetch_all_by_sql($where, $order = '', $start = 0, $limit = 0, $count = 0, $alias = '') {
$where = $where && !is_array($where) ? " WHERE $where" : '';
if(is_array($order)) {
$order = '';
}
if($count) {
return DB::result_first('SELECT count(*) FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
}
return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
}

变为:

代码如下:

class table_portal_article_content extends discuz_table
{
public function fetch_all_by_sql($where, $order = '', $start = 0, $limit = 0, $count = 0, $alias = '') {
$where = $where && !is_array($where) ? " WHERE $where" : '';
if(is_array($order)) {
$order = '';
}
if($count) {
return DB::result_first('SELECT count(*) FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
}
return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
}

上面添加那个方法才能用$query = C::t(‘portal_article_content’)->fetch_all_by_sql。

阅读剩余部分

相关阅读 >>

90后站长谈做网站的经验心得

研究ubb的跨站脚本攻击之综合篇

phpwind与discuz截取字符函数substrs与cutstr性能比较

iis下论坛静态化分析

discuz!7.0主题回收站功能详解

php用户密码加密算法分析【discuz加密算法】

齐博cms整合dz论坛后标签无法显示论坛图片的解决方法

基于discuz security.inc.php代码的深入分析

帝国cms7.5整合论坛程序discuzx3.2同时登陆退出的实现方法

mysql下为数据库设置交叉权限的方法

更多相关阅读请进入《Discuz论坛》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...