修改 ThinkCMFX 1.3.0 中的搜索功能
文件位置:
application/Portal/Common/function.php
修改:
注释掉function sp_sql_posts_paged_bykeyword(...){...}
粘贴入下面的代码
/**
* 功能扩展:格式化多关键词,以空格分割并删除首尾空格,增加查询字段,匹配文章关键词、标题、内容
* modify by Ult-UX 2014-12-09
*/function sp_sql_posts_paged_bykeyword($keyword,$tag,$pagesize=20,$pagetpl='{first}{prev}{liststart}{list}{listend}{next}{last}'){
$where=array();
$tag=sp_param_lable($tag);
$field = !empty($tag['field']) ? $tag['field'] : '*';
$limit = !empty($tag['limit']) ? $tag['limit'] : '';
$order = !empty($tag['order']) ? $tag['order'] : 'post_date';
//格式化关键词
$array_key = explode(" ",'%'.str_ireplace(" ","% %",trim($keyword," ")).'%');
// 生成查询条件
$map['post_keywords'] = array('LIKE', $array_key,'AND');
$map['post_title'] = array('LIKE', $array_key,'AND');
$map['post_content'] = array('LIKE', $array_key,'AND');
$map['_logic'] = 'OR';
// 封装查询条件
$where['_complex'] = $map;
// 只查询已发布的内容
$where['status'] = array('eq',1);
$where['post_status'] = array('eq',1);
if (isset($tag['cid'])) {
$where['term_id'] = array('in',$tag['cid']);
}
if (isset($tag['ids'])) {
$where['object_id'] = array('in',$tag['ids']);
}
$join = "".C('DB_PREFIX').'posts as b on a.object_id =b.id';
$join2= "".C('DB_PREFIX').'users as c on b.post_author = c.id';
$rs= M("TermRelationships");
$totalsize=$rs->alias("a")->join($join)->join($join2)->field($field)->where($where)->count();
import('Page');
if ($pagesize == 0) {
$pagesize = 20;
}
$PageParam = C("VAR_PAGE");
$page = new Page($totalsize,$pagesize);
$page->setLinkWraper("li");
$page->__set("PageParam", $PageParam);
$page->SetPager('default', $pagetpl, array("listlong" => "6", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
$posts=$rs->alias("a")->join($join)->join($join2)->field($field)->where($where)->order($order)->limit($page->firstRow . ',' . $page->listRows)->select();
$content['count']=$totalsize;
$content['posts']=$posts;
$content['page']=$page->show('default');
return $content;}