phpcms v9怎么按栏目搜索
4个回答
展开全部
修改了全部栏目搜索不到数据的bug
1、修改后台添加、修改内容时添加栏目id到搜索表中
找到 phpcms\model\content_model.class.php 大概106、287行左右,一共两处
$this->search_api($id,$inputinfo);
修改为:
$this->search_api($id,$systeminfo['catid'],$inputinfo);
找到 大概381行,将private function search_api 方法替换为以下代码
private function search_api($id = 0,$catid, $data = array(), $action = 'update') {
$type_arr = getcache('search_model_'.$this->siteid,'search');
$typeid = $type_arr[$this->modelid]['typeid'];
if($action == 'update') {
$fulltext_array = getcache('model_field_'.$this->modelid,'model');
foreach($fulltext_array AS $key=>$value){
if($value['isfulltext']) {
$fulltextcontent .= $data['system'][$key] ? $data['system'][$key] : $data['model'][$key];
}
}
$this->search_db->update_search($typeid ,$id, $fulltextcontent,addslashes($data['system']['title']).' '.addslashes($data['system']['keywords']),$data['system']['inputtime'],'',$catid);
} elseif($action == 'delete') {
$this->search_db->delete_search($typeid ,$id);
}
}
2、修改搜索模板文件
找到 phpcms\model\search_model.calss.php 的 21行左右
将 update_search 方法替换为:
public function update_search($typeid ,$id = 0,$data = '',$text = '',$adddate = 0, $iscreateindex=0,$catid) {
$segment = pc_base::load_sys_class('segment');
//分词结果
$fulltext_data = $segment->get_keyword($segment->split_result($data));
$fulltext_data = $text.' '.$fulltext_data;
if(!$iscreateindex) {
$r = $this->get_one(array('typeid'=>$typeid,'id'=>$id),'searchid');
}
if($r) {
$searchid = $r['searchid'];
$this->update(array('data'=>$fulltext_data,'adddate'=>$adddate,'catid'=>$catid),array('typeid'=>$typeid,'id'=>$id));
} else {
$siteid = param::get_cookie('siteid');
$searchid = $this->insert(array('typeid'=>$typeid,'id'=>$id,'adddate'=>$adddate,'data'=>$fulltext_data,'siteid'=>$siteid,'catid'=>$catid),true);
}
return $searchid;
}
3、修改后台更新全站缓存位置
找到phpcms\models\content\classes\search_api.class.php 的第 31行
将 $system_keys = 'id,inputtime'.implode(',',$system_keys);
修改为
$system_keys = 'id,inputtime,catid,'.implode(',',$system_keys);
找到 $temp['adddate'] = $r['inputtime'];在后面加上
$temp['catid'] = $r['catid'];
找到phpcms\models\search\search_admin.php大概第85行,将foreach修改为下面
foreach ($datas as $id=>$r) {
$this->db->update_search($typeid ,$id, $r['fulltextcontent'],$r['title'],$r['adddate'], 1,$r['catid']);
}
4、修改前台搜索程序
找到 phpcms\models\search\index.php 第25行
在 if(isset($_GET['q'])) { 下加上
$catid =$_GET['catid']?" AND catid = '$_GET[catid]'":'';
然后在第57行左右,将
$commend = $this->db->get_one("`typeid` = '$typeid' $sql_time AND `data` like '%$q%'");
修改为
$commend = $this->db->get_one("`typeid` = '$typeid' $sql_time $catid AND `data` like '%$q%'");
再找到第84行左右将
//如果分词结果为空
if(!empty($segment_q)) {
$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $sql_time AND MATCH (`data`) AGAINST ('$segment_q' IN BOOLEAN MODE)";
} else {
$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $sql_time AND `data` like '%$q%'";
}
修改为
//如果分词结果为空
if(!empty($segment_q)) {
$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $catid $sql_time AND MATCH (`data`) AGAINST ('$segment_q' IN BOOLEAN MODE)";
} else {
$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $catid $sql_time AND `data` like '%$q%'";
}
5、最后一步,到数据库中,找到数据表 表前缀_search,在此表中加一字段 catid int 4 做个索引,去按栏目id搜索试试吧,可以了,调试可用。
1、修改后台添加、修改内容时添加栏目id到搜索表中
找到 phpcms\model\content_model.class.php 大概106、287行左右,一共两处
$this->search_api($id,$inputinfo);
修改为:
$this->search_api($id,$systeminfo['catid'],$inputinfo);
找到 大概381行,将private function search_api 方法替换为以下代码
private function search_api($id = 0,$catid, $data = array(), $action = 'update') {
$type_arr = getcache('search_model_'.$this->siteid,'search');
$typeid = $type_arr[$this->modelid]['typeid'];
if($action == 'update') {
$fulltext_array = getcache('model_field_'.$this->modelid,'model');
foreach($fulltext_array AS $key=>$value){
if($value['isfulltext']) {
$fulltextcontent .= $data['system'][$key] ? $data['system'][$key] : $data['model'][$key];
}
}
$this->search_db->update_search($typeid ,$id, $fulltextcontent,addslashes($data['system']['title']).' '.addslashes($data['system']['keywords']),$data['system']['inputtime'],'',$catid);
} elseif($action == 'delete') {
$this->search_db->delete_search($typeid ,$id);
}
}
2、修改搜索模板文件
找到 phpcms\model\search_model.calss.php 的 21行左右
将 update_search 方法替换为:
public function update_search($typeid ,$id = 0,$data = '',$text = '',$adddate = 0, $iscreateindex=0,$catid) {
$segment = pc_base::load_sys_class('segment');
//分词结果
$fulltext_data = $segment->get_keyword($segment->split_result($data));
$fulltext_data = $text.' '.$fulltext_data;
if(!$iscreateindex) {
$r = $this->get_one(array('typeid'=>$typeid,'id'=>$id),'searchid');
}
if($r) {
$searchid = $r['searchid'];
$this->update(array('data'=>$fulltext_data,'adddate'=>$adddate,'catid'=>$catid),array('typeid'=>$typeid,'id'=>$id));
} else {
$siteid = param::get_cookie('siteid');
$searchid = $this->insert(array('typeid'=>$typeid,'id'=>$id,'adddate'=>$adddate,'data'=>$fulltext_data,'siteid'=>$siteid,'catid'=>$catid),true);
}
return $searchid;
}
3、修改后台更新全站缓存位置
找到phpcms\models\content\classes\search_api.class.php 的第 31行
将 $system_keys = 'id,inputtime'.implode(',',$system_keys);
修改为
$system_keys = 'id,inputtime,catid,'.implode(',',$system_keys);
找到 $temp['adddate'] = $r['inputtime'];在后面加上
$temp['catid'] = $r['catid'];
找到phpcms\models\search\search_admin.php大概第85行,将foreach修改为下面
foreach ($datas as $id=>$r) {
$this->db->update_search($typeid ,$id, $r['fulltextcontent'],$r['title'],$r['adddate'], 1,$r['catid']);
}
4、修改前台搜索程序
找到 phpcms\models\search\index.php 第25行
在 if(isset($_GET['q'])) { 下加上
$catid =$_GET['catid']?" AND catid = '$_GET[catid]'":'';
然后在第57行左右,将
$commend = $this->db->get_one("`typeid` = '$typeid' $sql_time AND `data` like '%$q%'");
修改为
$commend = $this->db->get_one("`typeid` = '$typeid' $sql_time $catid AND `data` like '%$q%'");
再找到第84行左右将
//如果分词结果为空
if(!empty($segment_q)) {
$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $sql_time AND MATCH (`data`) AGAINST ('$segment_q' IN BOOLEAN MODE)";
} else {
$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $sql_time AND `data` like '%$q%'";
}
修改为
//如果分词结果为空
if(!empty($segment_q)) {
$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $catid $sql_time AND MATCH (`data`) AGAINST ('$segment_q' IN BOOLEAN MODE)";
} else {
$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $catid $sql_time AND `data` like '%$q%'";
}
5、最后一步,到数据库中,找到数据表 表前缀_search,在此表中加一字段 catid int 4 做个索引,去按栏目id搜索试试吧,可以了,调试可用。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询