discuzx文章进行全文检索的实现方法
首先说明啊,这个检索是直接用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
{
后添加
复制代码代码如下:
变为:
复制代码代码如下:
上面添加那个方法才能用$query = C::t(‘portal_article_content’)->fetch_all_by_sql。
3.打开
网站目录\source\module\search\search_portal.php
搜索
复制代码代码如下:
在其后添加如下代码:
复制代码代码如下:
上面代码的意思是,如果搜标题没搜到,那就用like来搜文章的内容。
保存后,更新下discuz的缓存,搜文章里的内容试试,如果能搜到,OK,大功告成~
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。
3.打开
网站目录\source\module\search\search_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,大功告成~
免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。
热门教程
discuz电脑版、手机版去除标题title中的PoweredbyDisc2018-12-27
Discuz 触屏手机版支持视频播放的方法2018-12-27
discuz手机版支持视频播放的修改方法2018-12-27
Discuz! 程序 X3.2、X3.3升级3.4教程2018-12-27
discuz X3以及X3.4论坛搬家完美详细教程2019-01-02
怎么开启手机版2018-12-25
去掉Discuz论坛底部的Powered 等版权信息2018-12-27
discuz! x3.4插件位置DZ论坛X3版本插件在哪个文件夹?2018-12-26
Mysql修改端口号后织梦dedecms的修改方法2018-12-27
Discuz!X3.2论坛实现全站HTTPS终极方法教程2018-12-28