destoon供应多关键词搜索补丁
2014-03-27 金城 2177
destoon5.0的供应搜索功能只支持一个词的搜索,功能比较简单。
用空格隔开的多个词也只是的这几个词的顺序的并关系LIKE模式,还是不够模糊。
如: 关键词为 “红色 方形”,后台处理为 AND keyword LIKE '%红色%方形%';
如果想处理成 AND (keyword LIKE '红色' OR keyword LIKE '方形') 则下边的补丁可以做到。
<?php
# 在 /module/sell/serach.inc.php 的 if($keyword) $conditione.= " AND $dfields[$fields] LIKE '%$keyword%'";下
# 补丁
#require_once(DT_ROOT."/module/sell/search.inc.kw.like.patch.php");
#
$keyword_trim=trim(preg_replace('/\s+/ium',' ',$kw));
if($keyword_trim!=''){
if(preg_match('/ /ium',$keyword_trim)){
$keyword_array=explode(" ",$keyword_trim);
$condition=preg_replace('/ AND [^ %]+ LIKE %'.$keyword.'%/ium','',$condition);
$condition_array=array();
foreach($keyword_array as $k){
array_push($condition_array,"$dfields[$fields] LIKE '%$k%'");
}
$condition .=" AND (". implode(" OR ",$condition_array) .")";
}
}
# 在 /module/sell/serach.inc.php 的 if($keyword) $conditione.= " AND $dfields[$fields] LIKE '%$keyword%'";下
# 补丁
#require_once(DT_ROOT."/module/sell/search.inc.kw.like.patch.php");
#
$keyword_trim=trim(preg_replace('/\s+/ium',' ',$kw));
if($keyword_trim!=''){
if(preg_match('/ /ium',$keyword_trim)){
$keyword_array=explode(" ",$keyword_trim);
$condition=preg_replace('/ AND [^ %]+ LIKE %'.$keyword.'%/ium','',$condition);
$condition_array=array();
foreach($keyword_array as $k){
array_push($condition_array,"$dfields[$fields] LIKE '%$k%'");
}
$condition .=" AND (". implode(" OR ",$condition_array) .")";
}
}