• HYPHP
  • 【续】搜索功能用不了,求大神们的解决方法!!

namespace Action;
use HY\Action;
!defined('HY_PATH') && exit('HY_PATH not defined.');
class Search extends HYBBS {
    public function __construct() {
		parent::__construct();
        
        $this->view = IS_MOBILE ? $this->conf['wap_search'] : $this->conf['pc_search'];
        
    }
    public function _no(){
        
        $this->index();
    }
    public function index(){
        
        $key = X("get.key");
        if(empty($key)) 
            $key='';
            //return $this->message("请输入关键字");
        $key = htmlspecialchars($key);
        $this->v("key",$key);
        $this->v("search_key",$key);

        


        
        $this->v('title',$key.' 搜索');

        //分页ID
        $pageid=intval(X('get.pageid')) or $pageid=1;

        $user_list =array();
        $forum_list = array();
        if($pageid == 1){
            if(mb_strlen($key) >= 2){
                $User = M('User');
                $user_list = (array)$User->select(array('user','id'),array('user[~]'=>$key,'ORDER'=>'id DESC'));
                foreach ($user_list as &$v) {
                    $v['avatar'] = $this->avatar($v['user']);
                }
            }

            $forum_list = (array)S('Forum')->select(array('name','id'),array('name[~]'=>$key,'LIMIT'=>10));

        }
        $this->v('user_list',$user_list);
        $this->v('forum_list',$forum_list);

        $type = intval(X('get.type'));
        $this->v("type",$type);

        if(mb_strlen($key) < $this->conf['search_key_size']){
            $this->v("pageid",$pageid);
            $this->v("page_count",0);
            $this->v("data",array());
            $this->v('message','搜索的关键字长度不能少于'.$this->conf['search_key_size'].'位');
            return $this->display('search_index');
        }
        
        $this->v("keyall",$key);
$setsea = X("get.setsea");
$setsea = htmlspecialchars($setsea);
$setss = get_plugin_inc('hacg_very_search');
$setss = $setss['setss'];
$setss = explode("-",$setss);
$setss = in_array(NOW_GROUP,$setss);
if($setsea!="all"){
$this->v("setsea","title");

        $Thread = M("Thread");
        
        $data=array();
        $page_count = 0;
        if($type == 2){
            $data = $Thread->select(
                array(
                    "[>]post" => [ "pid" => "id"], //post.id == thread.pid
                ),
                array(
                    'thread.id',
                    'thread.title',
                    'thread.uid',
                    'thread.summary',
                    'post.content',
                    'thread.goods',
                    'thread.nos',
                    'thread.views',
                    'thread.img_count',
                    'thread.files',
                    'thread.atime',
                ),
                array(
                    'AND'=>array(
                        'isthread'=>1,
                        'OR'=>array(
                            'thread.title[~]'=>$key,
                            'post.content[~]'=>$key
                        )
                    ),
                    'ORDER'=>'id DESC',
                    "LIMIT" => array(($pageid-1) * $this->conf['searchlist'], $this->conf['searchlist'])
                )
            );

            $page_count = $Thread->count(
                array(
                    "[>]post" => [ "pid" => "id"], //post.id == thread.pid
                ),
                '*',
                array('AND'=>array(
                    'isthread'=>1,'OR'=>array(
                        'thread.title[~]'=>$key,
                        'post.content[~]'=>$key
                    )))
            );
            
        }else{
            $data = $Thread->select('*',array(
                'title[~]'=>$key,
                'ORDER'=>'id DESC',
                'LIMIT' => array(($pageid-1) * $this->conf['searchlist'], $this->conf['searchlist'])
            ));
            $page_count = $Thread->count(array(
                'title[~]'=>$key
            ));
            foreach ($data as &$v) {
                $v['content'] = $v['summary'];
            }
        }
        
        if(empty($data)){
            $this->v('message','没有搜索到相关内容');
            $data=array();
        }




        //$Thread->format($data);
        }else if($setss){
$this->v("setsea","all");
$this->v("key",$key."&setsea=all");
$Thread = M("Thread");
$data=array();
$data = S("Plugin")->query("select hy_thread.* from hy_thread,hy_post where hy_thread.id=hy_post.tid and hy_post.isthread=1 and (hy_thread.title like '%".$key."%' or hy_post.content like '%".$key."%')  ORDER BY hy_thread.atime desc limit ".($pageid-1)*$this->conf['searchlist'].",".$this->conf['searchlist'])->fetchAll(\PDO::FETCH_ASSOC);
$Thread->format($data);
}else{
return $this->message("您所在用户组没有此权限");
}
/*

        $t=$key;

        $tmp_avatar = 'public/images/user.gif';
        foreach ($data as $i => &$v) {
            $v['title'] = str_replace($key,'<font color="red">'.$key.'</font>',$v['title']);
            $tmp = strip_tags($v['content']);

            if((empty($tmp) || strpos($tmp, $key) === false) && strpos($v['title'], $key) === false){
                unset($data[$i]);
                continue;
            }
            //临时解决
            $v['avatar']=array('a'=>$tmp_avatar,'b'=>$tmp_avatar,'c'=>$tmp_avatar);
            $v['user']='';
            $v['buser']='';
            //
            
            if(empty($tmp))
                $tmp = '...';


            if(mb_strlen($tmp) > 120){
                $length = mb_strpos($tmp,$key);
                $v['content'] = mb_substr($tmp, $length, 120) . '...';
            }else{
                $v['content'] = $tmp;
            }
            
            
            $v['content'] = str_replace($key,'<font color="red">'.$key.'</font>',$v['content']);
            
            
        }

        */
$count = count($data);
if($count<$this->conf['searchlist'])
 {$page_count = $pageid;}
else
 {$page_count = $pageid+1;}

$t=$key;
foreach ($data as &$v) {
 $v['title'] = str_replace($key,'<font color="red">'.$key.'</font>',$v['title']);
}

        $this->v("pageid",$pageid);
        $this->v("page_count",$page_count);
        $this->v("data",$data);
        $this->display('search_index');
    }
    
}



老大,帮我解决一下!!谢谢!!!!



 [ "pid" => "id"], 改为  array("pid" => "id")