手机
当前位置:查字典教程网 >CMS教程 >discuz >discuzx3.1文章进行全文检索的实现方法
discuzx3.1文章进行全文检索的实现方法
摘要:首先说明啊,这个检索是直接用like来弄的,所以,如果你的站数据量大,这样很吃系统,自己掂量着办,我研究了下利用sphinx的,结果搞定了才...

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

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

网站目录sourceclasstabletable_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。

3.打开

网站目录sourcemodulesearchsearch_portal.php

搜索

</p> <p> foreach($query as $article) {

$ids .= ','.$article['aid'];

$num++;

}

在其后添加如下代码:

if($num==0){

list($srchtxt, $srchtxtsql) = searchkey($keyword, "content LIKE '%{text}%'", true);

$query = C::t('portal_article_content')->fetch_all_by_sql(' 1 '.$srchtxtsql, 'ORDER BY aid DESC ', 0, $_G['setting']['search']['portal']['maxsearchresults']);

foreach($query as $article) {

$ids .= ','.$article['aid'];

$num++;

}

}

上面代码的意思是,如果搜标题没搜到,那就用like来搜文章的内容。

保存后,更新下discuz的缓存,搜文章里的内容试试,如果能搜到,OK,大功告成~

【discuzx3.1文章进行全文检索的实现方法】相关文章:

Discuz! 2.5 安全码的重置问题

Discuz 密码错误次数过多导致等待15分钟的解决办法

Discuz教程之关于安装使用时的一些小细节问题的总结

discuz论坛用户通过邮件验证的设置方法[图文]

使用Discuz!后台备份和恢复Discuz!站点数据库的方法教程

discuz X2正式版forum首页的$navtitle显示不正确只显示论坛的解决方法

discuz不修改代码达到允许referer跳转到同顶级域名的解决方案

discuz伪静态唯独 论坛主题列表页 无法显示的解决方法

Discuz和jQuery变量名冲突的3种解决方法

Discuz! 6.1.0 图文安装教程

精品推荐
分类导航