【发布时间】:2011-10-27 15:19:17
【问题描述】:
我目前有一个知识库搜索功能,可以过滤掉一组常用词(a、able、about 等),这样它们就不会在查询中发送。不幸的是,当有人只搜索其中一个常用词时,它什么也不返回(而当它没有被过滤和查询时,我有代码返回“抱歉,没有找到结果”并将搜索记录在数据库中)。
如果搜索过滤词但未找到结果,我需要对过滤词执行相同操作,但我不确定最好的方法。下面是过滤后的代码。
//Defines common words to be striped.
$commonWords = array('a','able', etc)
//Strips common words from being included as a search term
$searchterm = preg_replace("/\b(".implode('|',$commonWords).")\b/i",'',$searchterm);
if(mysql_num_rows($result) == 0) {
echo "<img src=\"images/oops.png\"> Sorry, no results found. <br /><br /><div id=\"custformSubmit\">Chat Now</div>";
//Records missing search terms in a database
mysql_query("INSERT INTO quer (IP, Query) VALUES ('$ip','$search')") or die(mysql_error());;
我知道 if(mysql_num_rows($result) == 0) 不起作用,因为在提交时实际上没有搜索任何内容,但我不确定解决此问题的最佳方法。
编辑:此外,div id 'custformSubmit' 会打开一个聊天窗口,以便与代表聊天,这是必要的。
【问题讨论】:
标签: php javascript mysql search