九十六、ecshop模糊搜索分词插件
1、打开search.php文件
(1)找到:(大约在75行左右)
require(dirname(__FILE__) . '/includes/init.php');
在这段代码的下面添加:
/* add by mofangweb.com 分词搜索插件 begin */
require(dirname(__FILE__) . '/includes/cls_splitword.php');
/* add by mofangweb.com 分词搜索插件 end */
(2)找到:(大约在125-167行左右)
$action = '';
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'form')
{
/* 要显示高级搜索栏 */
$adv_value['keywords'] = htmlspecialchars(stripcslashes($_REQUEST['keywords']));
$adv_value['brand'] = $_REQUEST['brand'];
$adv_value['min_price'] = $_REQUEST['min_price'];
$adv_value['max_price'] = $_REQUEST['max_price'];
$adv_value['category'] = $_REQUEST['category'];
$attributes = get_seachable_attributes($_REQUEST['goods_type']);
/* 将提交数据重新赋值 */
foreach ($attributes['attr'] AS $key => $val)
{
if (!empty($_REQUEST['attr'][$val['id']]))
{
if ($val['type'] == 2)
{
$attributes['attr'][$key]['value']['from'] = !empty($_REQUEST['attr'][$val['id']]['from']) ? htmlspecialchars(stripcslashes(trim($_REQUEST['attr'][$val['id']]['from']))) : '';
$attributes['attr'][$key]['value']['to'] = !empty($_REQUEST['attr'][$val['id']]['to']) ? htmlspecialchars(stripcslashes(trim($_REQUEST['attr'][$val['id']]['to']))) : '';
}
else
{
$attributes['attr'][$key]['value'] = !empty($_REQUEST['attr'][$val['id']]) ? htmlspecialchars(stripcslashes(trim($_REQUEST['attr'][$val['id']]))) : '';
}
}
}
if ($_REQUEST['sc_ds'])
{
$smarty->assign('scck', 'checked');
}
$smarty->assign('adv_val', $adv_value);
$smarty->assign('goods_type_list', $attributes['cate']);
$smarty->assign('goods_attributes', $attributes['attr']);
$smarty->assign('goods_type_selected', $_REQUEST['goods_type']);
$smarty->assign('cat_list', cat_list(0, $adv_value['category'], true, 2, false));
$smarty->assign('brand_list', get_brand_list());
$smarty->assign('action', 'form');
$smarty->assign('use_storage', $_CFG['use_storage']);
$action = 'form';
}
在这段代码的上面添加:
/* add by mofangweb.com 分词搜索插件 begin */
$keywords = $_REQUEST['keywords'];
$sp = new SplitWord();
$sp->SetSource($keywords);
$sp->SetResultType(2);
$sp->StartAnalysis(TRUE);
$keywords = $sp->GetFinallyResult(' ');
$keywords_operator = ' AND ';
$keywords_arr = preg_replace("/[ ]{1,}/", $keywords_operator, trim($keywords));
/* add by mofangweb.com 分词搜索插件 end */
(3)找到:(大约在172-198行左右)
if (!empty($_REQUEST['keywords']))
{
$arr = array();
if (stristr($_REQUEST['keywords'], ' AND ') !== false)
{
/* 检查关键字中是否有AND,如果存在就是并 */
$arr = explode('AND', $_REQUEST['keywords']);
$operator = " AND ";
}
elseif (stristr($_REQUEST['keywords'], ' OR ') !== false)
{
/* 检查关键字中是否有OR,如果存在就是或 */
$arr = explode('OR', $_REQUEST['keywords']);
$operator = " OR ";
}
elseif (stristr($_REQUEST['keywords'], ' + ') !== false)
{
/* 检查关键字中是否有加号,如果存在就是或 */
$arr = explode('+', $_REQUEST['keywords']);
$operator = " OR ";
}
else
{
/* 检查关键字中是否有空格,如果存在就是并 */
$arr = explode(' ', $_REQUEST['keywords']);
$operator = " AND ";
}
将这段代码修改为:
if (!empty($keywords_arr))
{
/* mod by mofangweb.com 分词搜索插件 begin */
$arr = array();
if (stristr($keywords_arr, ' AND ') !== false)
{
/* 检查关键字中是否有AND,如果存在就是并 */
$arr = explode('AND', $keywords_arr);
$operator = " AND ";
}
elseif (stristr($keywords_arr, ' OR ') !== false)
{
/* 检查关键字中是否有OR,如果存在就是或 */
$arr = explode('OR', $keywords_arr);
$operator = " OR ";
}
elseif (stristr($keywords_arr, ' + ') !== false)
{
/* 检查关键字中是否有加号,如果存在就是或 */
$arr = explode('+', $keywords_arr);
$operator = " OR ";
}
else
{
/* 检查关键字中是否有空格,如果存在就是并 */
$arr = explode(' ', $keywords_arr);
$operator = " AND ";
}
/* mod by mofangweb.com 分词搜索插件 end */
(其实就是把$_REQUEST['keywords']修改为$keywords_arr)
(4)找到:(大约在409-441行左右)
$watermark_img = '';
if ($promote_price != 0)
{
$watermark_img = "watermark_promote_small";
}
elseif ($row['is_new'] != 0)
{
$watermark_img = "watermark_new_small";
}
elseif ($row['is_best'] != 0)
{
$watermark_img = "watermark_best_small";
}
elseif ($row['is_hot'] != 0)
{
$watermark_img = 'watermark_hot_small';
}
if ($watermark_img != '')
{
$arr[$row['goods_id']]['watermark_img'] = $watermark_img;
}
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
if($display == 'grid')
{
$arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
}
else
{
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
}
将这段代码修改为:
/* mod by mofangweb.com 分词搜索插件 begin */
$watermark_img = '';
if ($promote_price != 0)
{
$watermark_img = "watermark_promote_small";
}
elseif ($row['is_new'] != 0)
{
$watermark_img = "watermark_new_small";
}
elseif ($row['is_best'] != 0)
{
$watermark_img = "watermark_best_small";
}
elseif ($row['is_hot'] != 0)
{
$watermark_img = 'watermark_hot_small';
}
if ($watermark_img != '')
{
$arr[$row['goods_id']]['watermark_img'] = $watermark_img;
}
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
if($display == 'grid')
{
$arr[$row['goods_id']]['goods_name'] = $arr[$row['goods_id']]['new_goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
}
else
{
$arr[$row['goods_id']]['goods_name'] = $arr[$row['goods_id']]['new_goods_name'] = $row['goods_name'];
}
if (!empty($keywords_arr))
{
$new_keywords = explode($keywords_operator, $keywords_arr);
foreach ($new_keywords as $keywords_val)
{
$arr[$row['goods_id']]['new_goods_name'] = preg_replace("/($keywords_val)/is", "
\$1", $arr[$row['goods_id']]['new_goods_name']);
}
}
/* mod by mofangweb.com 分词搜索插件 end */
2、打开themes/您当前的模板文件夹名称/search.dwt文件(下面是以默认模板default为例,具体情况根据您的模板文件进行修改)
找到:(下面的代码在里面)
{$goods.goods_name}
将这段代码修改为:
{$goods.new_goods_name}
3、直接复制includes文件夹里面的文件到您网站根目录includes文件夹下。