最近在用ECSHOP做一个商城,发现ECSHOP的模糊搜索要求太高,需要加入and、空格、加号等,客户搜索的时候不可能这样操作。所以想对搜索功能进行改进,可是在网上没有找到这样的插件,有收费的,结果要2000大元。考虑了一下申请经费的麻烦,自己费点儿力气做一个吧。
考虑到工期的问题,采用了织梦的分词算法,搜索效果虽然不是特别理想,但是这么短的时间也只能这样了。
在此分享给没钱又着急的朋友,需要用到的文件在文章末尾提供下载,大家下载后也可以直接覆盖使用。
一、ECSHOP联想下拉框
1、修改page_header.lbi模版文件,将搜索文本框修改为:
嵌入js文件
嵌入css文件
2、根目录添加php文件search_suggest.php文件
二、分词搜索
根目录增加织梦分词算法函数和词库:lib_splitword_full.php和dededic.csv
1、修改search.php文件第196行
改为:
2、修改search.php文件第382行到403行
修改为:
$select = "(";
foreach($arr AS $se => $t)
{
$select .= "SELECT click_count,goods_sn,is_alone_sale,is_on_sale,is_delete,goods_id, goods_name, market_price, is_new, is_best, is_hot, shop_price AS org_price, shop_price ,promote_price, promote_start_date, promote_end_date, goods_thumb, goods_img, goods_brief, goods_type FROM(select click_count,goods_sn,is_alone_sale,is_on_sale,is_delete,goods_id, goods_name, market_price, is_new, is_best, is_hot, shop_price AS org_price, shop_price ,promote_price, promote_start_date, promote_end_date, goods_thumb, goods_img, goods_brief, goods_type from".$ecs->table('goods')." where goods_name like '%$t%' order by click_count desc) AS P$se";
if($se==0)
{
$select .= " UNION SELECT click_count,goods_sn,is_alone_sale,is_on_sale,is_delete,goods_id, goods_name, market_price, is_new, is_best, is_hot, shop_price AS org_price, shop_price ,promote_price, promote_start_date, promote_end_date, goods_thumb, goods_img, goods_brief, goods_type FROM(select click_count,goods_sn,is_alone_sale,is_on_sale,is_delete,goods_id, goods_name, market_price, is_new, is_best, is_hot, shop_price AS org_price, shop_price ,promote_price, promote_start_date, promote_end_date, goods_thumb, goods_img, goods_brief, goods_type from".$ecs->table('goods')." where 1 $keywords order by click_count desc) AS Pa";
}
if($se<count($arr)-1)
{
$select.=" UNION ";
}
}
$select.=")";
if($select=="()")
{
$sql = "SELECT COUNT(*) FROM ".$ecs->table("goods")." AS P " .
"WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1 " ;
}
else
{
$sql = "SELECT COUNT(*) FROM $select AS P " .
"WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1 " ;
}
$count = $db->getOne($sql);
$max_page = ($count> 0) ? ceil($count / $size) : 1;
if ($page > $max_page)
{
$page = $max_page;
}
if($select=="()")
{
$sql = "SELECT click_count,goods_sn,is_alone_sale,is_on_sale,is_delete,goods_id, goods_name, market_price, is_new, is_best, is_hot, shop_price AS org_price, shop_price ,promote_price, promote_start_date, promote_end_date, goods_thumb, goods_img, goods_brief, goods_type ".
"FROM ".$ecs->table("goods")." AS P " .
"WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1 " ;
}
else
{
$sql = "SELECT click_count,goods_sn,is_alone_sale,is_on_sale,is_delete,goods_id, goods_name, market_price, is_new, is_best, is_hot, shop_price AS org_price, shop_price ,promote_price, promote_start_date, promote_end_date, goods_thumb, goods_img, goods_brief, goods_type ".
"FROM $select AS P " .
"WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1 " ;
}
三、搜索出的产品列表产品关键词飘红功能:
1、修改search.php文件第473行到480行
修改为:
2、修改search.dwt模板文件
将显示商品名称的地方替换为:
本文标签:
声明:本文由代码号注册/游客用户【平安】供稿发布,本站不对用户发布的ecshop分词搜索和商品关键字红色的实现方法信息内容原创度和真实性等负责。如内容侵犯您的版权或其他权益,请留言并加以说明。站长审查之后若情况属实会及时为您删除。同时遵循 CC 4.0 BY-SA 版权协议,尊重和保护作者的劳动成果,转载请标明出处链接和本声明内容。本文作者:平安» https://www.ebingou.cn/dmh/13514.html
很赞哦! (0)