菜单
展开边栏 收起边栏

正确的使用phpcms 搜索,可解决搜索为空的问题

问题的前提是你先正确的开启了并正确设置了搜索功能,在后台设置,如果不会可以自行参考官方的使用文档,如果正确开启了还不行就看下面吧

 

1.找到 phpcms/modules/search/index.php 文件,打开并编辑。

2.查找代码:

//如果分词结果为空
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%'";
}

$result = $this->db->listinfo($sql, 'searchid DESC', $page, 10);

替换为:

//如果分词结果为空
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%'";
}
$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $sql_time AND `data` like '%$q%' ";
$result = $this->db->listinfo($sql, 'searchid DESC', $page, 10);

仔细看,实际上就是加了一行 

$sql = "`siteid`= '$siteid' AND `typeid` = '$typeid' $sql_time AND `data` like '%$q%' ";

然后搞定。

 

 

联系疆飞

PS:没事不要瞎联系,除非你想请我吃饭...

Copyright © 2008-. JiangFei.net all rights reserved 苏ICP备18062911号