ThinkCMFX 1.3.0搜索功能扩展


修改 ThinkCMFX 1.3.0 中的搜索功能

文件位置:

application/Portal/Common/function.php

修改:

  1. 注释掉function sp_sql_posts_paged_bykeyword(...){...}

  2. 粘贴入下面的代码

/**
 * 功能扩展:格式化多关键词,以空格分割并删除首尾空格,增加查询字段,匹配文章关键词、标题、内容
 * 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;}


打赏

评论

暂时关闭,稍后恢复~
文档请看10遍以上!有问题可加QQ群!
发表话题

源素材推荐

提问必知

0.话题发布后没及时显示,请联系官方QQ群管理;
1.话题支持代码,qq截屏直接粘贴,和QQ群一样;
2.问题描述清,比如服务器版本,程序版本;
3.能上代码,就不用文字;
4.把问题发到话题后再发QQ群;
5.如果感觉回复者解答的不错,可以发红包!
6.多帮助别人也是对自己的锻炼!
7.付费讨论中只有提问者和付费用户才可以查看回复

积分规则

1.评论积分+1;每天最多10次奖励
2.发布话题积分+1;每天最多5次奖励
3.垃圾评论积分-500;
4.黄色,暴力,违反我国法律评论直接封号


ThinkCMF 8.0.0发布啦!祝大家节日快乐! 立即体验!