您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程
ecshop商品关键词模糊分词搜索插件,商品列表关键字加红功能
之桃2024-04-20Ecshop商城教程已有人查阅
导读ECSHOP商品关键词模糊分词搜索商品列表关键字加红功能。最近给客户做一个ECSHOP商城,发现ECSHOP的模糊搜索要求太高,需要加入and、空格、加号等,客户搜索的时候不可能这样操作。
ECSHOP商品关键词模糊分词搜索商品列表关键字加红功能。最近给客户做一个ECSHOP商城,发现ECSHOP的模糊搜索要求太高,需要加入and、空格、加号等,客户搜索的时候不可能这样操作。
考虑到工期的问题,采用了织梦的分词算法,搜索效果虽然不是特别理想,但是这么短的时间也只能这样了。
在此分享给没钱又着急的朋友,需要用到的文件在文章末尾提供下载,大家下载后也可以直接覆盖使用。
一、ECSHOP联想下拉框
1、修改page_header.lbi模版文件,将搜索文本框修改为:
<scripttype="text/javascript"src="/js/suggest.js"></script>
嵌入css文件
<linkhref="/themes/default/images/css.css"rel="stylesheet"type="text/css">
2、根目录添加php文件search_suggest.php文件
二、分词搜索
ECSHOP教程根目录增加织梦分词算法函数和词库:lib_splitword_full.php和dededic.csv
1、修改search.php文件 96行
/*检查关键字中是否有空格,如果存在就是并*/$arr=explode(' ',$_REQUEST['keywords']);$operator= " AND ";
改为:
/*调用织梦分词功能-start*/require("lib_splitword_full.php");$sp=newSplitWord();$fenci=$sp->SplitRMM($_REQUEST['keywords']);$sp->Clear();/*织梦分词后是使用空格进行划分,所以仍可使用ecshop的按照空格拆分为数组功能:检查关键字中是否有空格,如果存在就是并*/$arr=explode(' ',$fenci);$arr=array_reverse($arr);//将数组倒序排列,并插入完整关键字到数组末尾$arr[count($arr)]=$_REQUEST['keywords'];$arr=array_reverse($arr);//再次将数组倒序,使完整关键字可以 个被检索array_pop($arr);//删除织梦分词产生的数组最后一个元素为空格$operator= " and ";//sql检索语句使用union联合检索$ hong=$arr;//$arr数组在飘红的时候已经被产品列表占用了,所以另外赋值给一个数组备用。/*调用织梦分词功能-end*/
2、修改search.php文件第382行到403行
/*sun04zh3-20130905-调用织梦分词功能-更改ecshop的sql语句采用union方式-start*//*因为后面要用union生成数据集表,所以先根据拆分出的关键词,生成union所需的所有sql语句,*/$select= "(";foreach($arrAS$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)//插入一个当所有拆分关键词在商品名称中为and时的sql语句{$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$keywordsorder by click_count desc) AS Pa"; }if($se<count($arr)-1)//在每条select语句后增加union,最后一个不加,所以$se小于元素数量-1{$select.=" UNION "; } }$select.=")";if($select=="()")//当关键词为空时,没有拆分关键词,所以用于union的$select为空,仍需要调用goods表{$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$selectAS 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=="()")//当关键词为空时,没有拆分关键词,所以用于union的$select为空,仍需要调用goods表{/*查询商品*/$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$selectAS P " . "WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1 "; }
三、搜索出的产品列表产品关键词飘红功能:
1、修改search.php文件第473行到480行
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']; }
修改为:
/*根据分词对产品名称进行替换-start*/$tihuan=$row["goods_name"];foreach($ hongAS$ph_count=>$ph) {$tihuan=str_replace($ph,"<b style='color:#d90000'>$ph</b>",$tihuan); }$arr[$row['goods_id']]['goods_name'] =$row['goods_name'];//因为前台用到没有替换的商品名称,所以保留goods_name值$arr[$row['goods_id']]['tihuan'] =$tihuan;/*根据分词对产品名称进行替换-end*/
2、修改search.dwt模板文件
将显示商品名称的地方替换为:
<p><a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.tihuan}</a></p>
四、文中所有涉及的修改和要用到的文件
下载地址:www.ebingou.cn/moban-311.html
考虑到工期的问题,采用了织梦的分词算法,搜索效果虽然不是特别理想,但是这么短的时间也只能这样了。
在此分享给没钱又着急的朋友,需要用到的文件在文章末尾提供下载,大家下载后也可以直接覆盖使用。
一、ECSHOP联想下拉框
1、修改page_header.lbi模版文件,将搜索文本框修改为:
<inputname="keywords"type="text"id="keyword"value="<!--{if ($search_keywords neq "")}{$search_keywords|escape}--><!--{else}-->ecshop<!--{/if}-->" class="search-input" onfocus="if(this.value=='ecshop'){this.value='';this.style.color='#000';}" onblur="closediv();if(this.value==''){this.value='ecshop';this.style.color='#999';}" style="color:#999;" onkeyup="keyupdeal(event,this.value);" onkeydown="keydowndeal(event);" onclick="keyupdeal(event,this.value);" autocomplete="off" /><divid="search_suggest"style="display:none;"onmouseover='javascript:_over();'onmouseout='javascript:_out();'></div>
嵌入js文件<scripttype="text/javascript"src="/js/suggest.js"></script>
嵌入css文件
<linkhref="/themes/default/images/css.css"rel="stylesheet"type="text/css">
2、根目录添加php文件search_suggest.php文件
二、分词搜索
ECSHOP教程根目录增加织梦分词算法函数和词库:lib_splitword_full.php和dededic.csv
1、修改search.php文件 96行
/*检查关键字中是否有空格,如果存在就是并*/$arr=explode(' ',$_REQUEST['keywords']);$operator= " AND ";
改为:
/*调用织梦分词功能-start*/require("lib_splitword_full.php");$sp=newSplitWord();$fenci=$sp->SplitRMM($_REQUEST['keywords']);$sp->Clear();/*织梦分词后是使用空格进行划分,所以仍可使用ecshop的按照空格拆分为数组功能:检查关键字中是否有空格,如果存在就是并*/$arr=explode(' ',$fenci);$arr=array_reverse($arr);//将数组倒序排列,并插入完整关键字到数组末尾$arr[count($arr)]=$_REQUEST['keywords'];$arr=array_reverse($arr);//再次将数组倒序,使完整关键字可以 个被检索array_pop($arr);//删除织梦分词产生的数组最后一个元素为空格$operator= " and ";//sql检索语句使用union联合检索$ hong=$arr;//$arr数组在飘红的时候已经被产品列表占用了,所以另外赋值给一个数组备用。/*调用织梦分词功能-end*/
2、修改search.php文件第382行到403行
/*获得符合条件的商品总数*/$sql= "SELECT COUNT(*) FROM " .$ecs->table('goods'). " AS g ". "WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1$attr_in". "AND (( 1 " .$categories.$keywords.$brand.$min_price.$max_price.$intro.$outstock." ) ".$tag_where." )";$count=$db->getOne($sql);$max_page= ($count> 0) ?ceil($count/$size) : 1;if($page>$max_page) {$page=$max_page; }/*查询商品*/$sql= "SELECT g.goods_id, g.goods_name, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ". "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". "g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type ". "FROM " .$ecs->table('goods'). " AS g ". "LEFT JOIN " .$GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". "WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1$attr_in". "AND (( 1 " .$categories.$keywords.$brand.$min_price.$max_price.$intro.$outstock. " ) ".$tag_where." ) " . "ORDER BY$sort$order";
打开 /includes/lib_goods.php 文件(建议使用editplus)找到下面代码(大概在287行左右)/*sun04zh3-20130905-调用织梦分词功能-更改ecshop的sql语句采用union方式-start*//*因为后面要用union生成数据集表,所以先根据拆分出的关键词,生成union所需的所有sql语句,*/$select= "(";foreach($arrAS$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)//插入一个当所有拆分关键词在商品名称中为and时的sql语句{$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$keywordsorder by click_count desc) AS Pa"; }if($se<count($arr)-1)//在每条select语句后增加union,最后一个不加,所以$se小于元素数量-1{$select.=" UNION "; } }$select.=")";if($select=="()")//当关键词为空时,没有拆分关键词,所以用于union的$select为空,仍需要调用goods表{$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$selectAS 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=="()")//当关键词为空时,没有拆分关键词,所以用于union的$select为空,仍需要调用goods表{/*查询商品*/$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$selectAS P " . "WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1 "; }
三、搜索出的产品列表产品关键词飘红功能:
1、修改search.php文件第473行到480行
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']; }
修改为:
/*根据分词对产品名称进行替换-start*/$tihuan=$row["goods_name"];foreach($ hongAS$ph_count=>$ph) {$tihuan=str_replace($ph,"<b style='color:#d90000'>$ph</b>",$tihuan); }$arr[$row['goods_id']]['goods_name'] =$row['goods_name'];//因为前台用到没有替换的商品名称,所以保留goods_name值$arr[$row['goods_id']]['tihuan'] =$tihuan;/*根据分词对产品名称进行替换-end*/
2、修改search.dwt模板文件
将显示商品名称的地方替换为:
<p><a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.tihuan}</a></p>
四、文中所有涉及的修改和要用到的文件
下载地址:www.ebingou.cn/moban-311.html
本文标签:
很赞哦! ()
相关教程
图文教程
ecshop商城404页面设置方法
404页面是HTTP状态码中的一种,简单的说就是当用户输入了错误的链接时返回的提示页面。别小看404,它会影响到流量,影响到网页排名,影响到用户体验,影响到xxoo…
ecshop调用指定广告的写法实例
在include/lib_goods.php文件下面新增:二、然后再指定的位置的控制页面增加:例如首页调用,我们在index.php页面增加
ecshop后台管理增加 和毛利润统计的实现方法
ecshop 功能二次开发 关于后台管理增加 和毛利润统计功能(一)首先在订单中的商品信息【编辑】页面中,修改 。也可以在添加商品时添加成本的如果不做手工修改,则使用默认的商品
ecshop标签调用大全
先从index.php主页开始,页面关键字 {$keywords },页面标题 {$page_title},产品分类,父分类列表 {foreach from=$categories item=cat },父分类超链接 http://localhost/ecsh
相关源码
-
(PC+WAP)绿色环保建筑设备通用行业pbootcms源码下载通过模块调整可适配园林景观、装配式建筑、绿色装修等生态建设相关领域。预制绿色建材展示、能耗模拟等专业模块,集成项目案例、环保工艺等建筑行业特色内容结构,测试数据包含LEED认证体系查看源码 -
(PC+WAP)铝合金门窗定制pbootcms网站模板源码为铝合金门窗、定制门窗企业打造的高性能网站模板,基于PbootCMS开源内核开发,采用HTML5自适应架构,PC与手机端数据实时同步,覆盖全终端用户交互场景。查看源码 -
(自适应)蓄电池能源智能数码科技产品pbootcms模板源码下载本款基于PbootCMS开发的网站模板为蓄电池及能源科技企业设计,特别适合锂电池、储能系统、新能源电池等产品的展示与推广。查看源码 -
(自适应)绿色LED灯具照明灯饰灯光灯泡pbootcms网站源码下载本模板基于PbootCMS内核开发,为LED照明、灯具制造及相关光电技术企业量身打造。设计充分考虑了照明行业的展示需求,从产品陈列到技术说明,从光源展示到工程案例,每一个细节都体现出专业照明行业的特点。查看源码 -
(PC+WAP)聚氨酯粉末涂料防腐耐用材料粘合剂网站源码下载为化工涂料企业设计的展示系统,集成产品技术参数库、颜色样板展示器和配方查询模块。支持粉末涂料、环氧树脂等多类产品分类展示查看源码 -
(自适应响应式)投资理财金融机构财务管理pbootcms模板本模板基于PbootCMS系统开发,为投资理财、金融机构等行业设计。采用专业严谨的布局风格,突出金融服务行业特色,适合展示各类理财产品、投资服务和金融资讯。查看源码
| 分享笔记 (共有 篇笔记) |
