轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 ECShop网店 查看主题

ECSHOP商品关键词模糊分词搜索插件,商品列表关键字加红功能

发布者: msdn4783 | 发布时间: 2018-8-10 05:34| 查看数: 4154| 评论数: 1|帖子模式

[size=12.0000pt][size=12.0000pt]各位网店系统用户大家好,欢迎来到图文教程,今天为大家详细解说一下ECSHOP商品关键词模糊分词搜索商品列表关键字加红功能[size=12.0000pt][size=12.0000pt]。

[size=12.0000pt][size=12.0000pt]ECSHOP教程网ECSHOP视频教程也再不断的完善与跟进,期待大家的关注!希望在ECSHOP的道路上,[size=12.0000pt]网与您一路同行!

最近给客户做一个ECSHOP商城,发现ECSHOP的模糊搜索要求太高,需要加入and、空格、加号等,客户搜索的时候不可能这样操作。
考虑到工期的问题,采用了织梦的分词算法,搜索效果虽然不是特别理想,但是这么短的时间也只能这样了。
在此分享给没钱又着急的朋友,需要用到的文件在文章末尾提供下载,大家下载后也可以直接覆盖使用。
一、ECSHOP联想下拉框
1、修改page_header.lbi模版文件,将搜索文本框修改为:


           
  1. [/code]            [/td]        [/tr]    [/table]嵌入js文件
  2. [font=宋体, Verdana, Arial]
  3. [/font]
  4. [table=560,rgb(247,247,247)]            [tr]            [td]                        [code]
复制代码
           
            

嵌入css文件

                       
  1. [/code]            
  2.             [/td]        [/tr]    [/table]
  3. 2、根目录添加php文件search_suggest.php文件
  4. 二、分词搜索
  5. [size=12.0000pt][size=12.0000pt][url=http://www.qingyuanma.com/forum-43-1.html]ECSHOP教程[/url][/size][/size]根目录增加织梦分词算法函数和词库:lib_splitword_full.php和dededic.csv
  6. 1、修改search.php文件第196行[font=宋体, Verdana, Arial]
  7. [/font]
  8. [table=560,rgb(247,247,247)]            [tr]            [td]            [code]/* 检查关键字中是否有空格,如果存在就是并 */
  9.             $arr        = explode(' ', $_REQUEST['keywords']);             $operator   = " AND ";
复制代码
           

改为:


           
  1. /*调用织梦分词功能-start*/
  2.             require("lib_splitword_full.php");             $sp = new SplitWord();             $fenci=$sp->SplitRMM($_REQUEST['keywords']);             $sp->Clear();             /* 织梦分词后是使用空格进行划分,所以仍可使用ecshop的按照空格拆分为数组功能:检查关键字中是否有空格,如果存在就是并 */
  3.             $arr        = explode(' ', $fenci);             $arr        = array_reverse($arr);//将数组倒序排列,并插入完整关键字到数组末尾
  4.             $arr[count($arr)]=$_REQUEST['keywords'];             $arr        = array_reverse($arr);//再次将数组倒序,使完整关键字可以第一个被检索
  5.             array_pop($arr);//删除织梦分词产生的数组最后一个元素为空格
  6.             $operator   = " and ";//sql检索语句使用union联合检索
  7.             $piaohong = $arr;//$arr数组在飘红的时候已经被产品列表占用了,所以另外赋值给一个数组备用。
  8.             /*调用织梦分词功能-end*/
复制代码
           
2、修改search.php文件第382行到403行

           
  1. /* 获得符合条件的商品总数 */
  2.     $sql   = "SELECT COUNT(*) FROM " .$ecs->table('goods'). " AS g ".
  3.         "WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
  4.         "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;     }      /* 查询商品 */
  5.     $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, ".
  6.                 "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
  7.                 "g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type ".
  8.             "FROM " .$ecs->table('goods'). " AS g ".
  9.             "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  10.                     "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  11.             "WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
  12.                 "AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . " ) ".$tag_where." ) " .
  13.             "ORDER BY $sort $order";
复制代码
           
打开 /includes/lib_goods.php 文件(建议使用editplus)找到下面代码(大概在287行左右)

           
  1. /*sun04zh3-20130905-调用织梦分词功能-更改ecshop的sql语句采用union方式-start*/
  2. /*因为后面要用union生成数据集表,所以先根据拆分出的关键词,生成union所需的所有sql语句,*/
  3. $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";//第一个关键词是完整关键词
  4.         if($se==0)//插入一个当所有拆分关键词在商品名称中为and时的sql语句
  5.         {             $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($setable("goods")." AS P " .
  6.             "WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1  " ;     }     else     {          /* 获得符合条件的商品总数 */
  7.         $sql   = "SELECT COUNT(*) FROM $select AS P " .
  8.                 "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表
  9.     {          /* 查询商品 */
  10.     $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 ".
  11.             "FROM ".$ecs->table("goods")." AS P " .
  12.             "WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1  " ;     }     else     {          /* 查询商品 */
  13.             $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 ".
  14.             "FROM $select AS P " .
  15.             "WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1  " ;     }
复制代码
           

三、搜索出的产品列表产品关键词飘红功能:
1、修改search.php文件第473行到480行


           
  1. 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'];         }
复制代码
           

修改为:


           
  1. /*根据分词对产品名称进行替换-start*/
  2.         $tihuan=$row["goods_name"];         foreach($piaohong AS $ph_count => $ph)         {              $tihuan = str_replace($ph,"$ph",$tihuan);         }                $arr[$row['goods_id']]['goods_name'] = $row['goods_name'];//因为前台用到没有替换的商品名称,所以保留goods_name值
  3.            $arr[$row['goods_id']]['tihuan'] = $tihuan;         /*根据分词对产品名称进行替换-end*/
复制代码
           

2、修改search.dwt模板文件
将显示商品名称的地方替换为:


           
  1. {$goods.tihuan}
复制代码
           

四、文中所有涉及的修改和要用到的文件
下载地址:www.qingyuanma.com/moban-311.html

最新评论

MableMok12 发表于 2022-7-9 05:18
可币怎么免费获得

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表