Discuz!X3.5对门户文章进行全文检索的功能

2023-11-23 14:58

版本X3.2修改以下两个文件即可实现门户文章全文搜索:

1.打开网站目录\source\class\table\table_portal_article_content.php
搜索:
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。

2.打开网站目录\source\module\search\search_portal.php
搜索:
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来搜文章的内容。

版本X3.5还在研究中……

Copyright © 2002-2024 Iszw.net All Rights Reserved.      川公网安备 51010702002244号

蜀ICP备2020035322号-1    本站已开启 IPv6 访问

返回顶部