think PHP搜索功能代码,ThinkCMFX 1.3.0搜索功能扩展

修改 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;}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值