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

全屏阅读
  • 基本信息
  • 作者:
  • 作者已发布:924篇文章
  • 发布时间:2020年03月01日 15:32:57
  • 所属分类:Discuz
  • 阅读次数:3362次阅读
  • 标签:

搜索门户中的文章,并不是按这个走的,而且利用sphinx这个啊,要么只能分中文要么只能分英文(学艺不精没细了解啊,个人测试是这样的)。

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来搜文章的内容。

顶一下
(0)
0%
订阅 回复
踩一下
(1)
100%
» 郑重声明:本文由mpxq168发布,所有内容仅代表个人观点。版权归恒富网mpxq168共有,欢迎转载, 但未经作者同意必须保留此段声明,并给出文章连接,否则保留追究法律责任的权利! 如果本文侵犯了您的权益,请留言。

目前有 0 条留言 其中:访客:0 条, 博主:0 条

给我留言

您必须 [ 登录 ] 才能发表留言!