ECSHOP联想下拉框

1、修改page_header.lbi模版文件,将搜索文本框修改为:

<input name="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" />
<div id="search_suggest" style="display:none;" onmouseover='javascript:_over();' onmouseout='javascript:_out();'></div>

嵌入js文件

<script type="text/javascript" src="/js/suggest.js"></script>

嵌入css文件

<link href="/themes/default/images/css.css" rel="stylesheet" type="text/css">

2、根目录添加php文件search_suggest.php文件

二、分词搜索

根目录增加织梦分词算法函数和词库:lib_splitword_full.php和dededic.csv

1、修改search.php文件第196行

/* 检查关键字中是否有空格,如果存在就是并 */
$arr = explode(' ', $_REQUEST['keywords']);
$operator = " AND ";

改为:

/*调用织梦分词功能-start*/
require("lib_splitword_full.php");
$sp = new SplitWord();
$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联合检索
$piaohong = $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";

修改为:

/*sun04zh3-20130905-调用织梦分词功能-更改ecshop的sql语句采用union方式-start*/
/*因为后面要用union生成数据集表,所以先根据拆分出的关键词,生成union所需的所有sql语句,*/
$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)//插入一个当所有拆分关键词在商品名称中为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 $keywords order 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 $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=="()")//当关键词为空时,没有拆分关键词,所以用于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 $select AS 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($piaohong AS $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>

四、文中所有涉及的修改和要用到的文件,因为没找到上传文件的地方所有放到其他网站了。下载地址:http://download.csdn.net/detail/sun04zh3/6216851

ECSHOP模糊分词搜索和商品列表关键字飘红功能的更多相关文章

  1. jQuery制作淘宝商城商品列表多条件查询功能

    一.介绍 这几天做网站的时候,突然用到这个功能,找了好久也没有找到.看到"希伟素材网"有这么一个JS,效果很不错,也正是我一直以来想要的结果.附图如下: 二:使用教程      1 ...

  2. 5- vue django restful framework 打造生鲜超市 -完成商品列表页(上)

    使用Python3.6与Django2.0.2(Django-rest-framework)以及前端vue开发的前后端分离的商城网站 项目支持支付宝支付(暂不支持微信支付),支持手机短信验证码注册, ...

  3. 修改ECSHOP后台的商品列表里显示该商品品牌

    如何在在ECSHOP后台的商品列表中也显示商品的品牌”.下面就来最模板讲一下如何来修改.此方法只保证在ECSHOP2.7.2版本下有效,其他版本请参照修改. 第一步:首先我们来打开程序文件: /adm ...

  4. React后台管理系统-商品列表搜索框listSearch组件

    1.商品列表搜索框 2.搜索框页面的结构为 <div className="row search-wrap">               <div classN ...

  5. ecshop的商品列表输出中多出一条空记录

    这个是ECSHOP的一个BUG, 在模板中显示商品列表的位置,加一句{if $goods}判断商品存在才显示: {foreach from=$goods_list item=goods} {if $g ...

  6. ecshop二次开发 给商品添加自定义字段

    说起自定义字段,我想很多的朋友像我一样会想起一些开源的CMS(比如Dedecms.Phpcms.帝国)等,他们是可以在后台直接添加自定义字段的. 抱着这种想法我在Ecshop的后台一顿找,不过肿么都木 ...

  7. 商城项目:商品列表ajax加载,ajax加入购物车--五张表的联合查询

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductLists.a ...

  8. 6- vue django restful framework 打造生鲜超市 -完成商品列表页(下)

    Vue+Django REST framework实战 搭建一个前后端分离的生鲜超市网站 Django rtf 完成 商品列表页下 drf中的request和response drf对于django的 ...

  9. Python网络爬虫——京东商城商品列表

    Python_网络爬虫--京东商城商品列表 最近在拓展自己知识面,想学习一下其他的编程语言,处于多方的考虑最终选择了Python,Python从发布之初就以庞大的用户集群占据了编程的一席之地,pyth ...

随机推荐

  1. 转:从三层架构到MVC-MVP

    当然这种架构模式本身的一些问题也会在接下来的内容就加以介绍,另外就是如果大家有什么不同观点的话,欢迎拍砖(只要不打脸就行,呵呵). 一. MVC是谁提出的 模型-视图-控制器(MVC)是Xerox P ...

  2. 关于类似(i++)+(++i)

    这是一个“然并卵”的问题,因为没有人愿意在代码中给自己找这种麻烦,看到书上讲到这个问题忍不住想顺势总结下,就从表达式说起吧. 在js中,同一般的语言一样,表达式分很多种. 对象和数组的初始化表达式:即 ...

  3. php curl 的用法 转载

    curl 是使用URL语法的传送文件工具,支持FTP.FTPS.HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE和LDAP.curl 支持SSL证书.HTTP POS ...

  4. html5的自定义data-*属性和jquery的data()方法的使用示例

    人们总喜欢往HTML标签上添加自定义属性来存储和操作数据. 但这样做的问题是,你不知道将来会不会有其它脚本把你的自定义属性给重置掉,此外,你这样做也会导致html语法上不符合Html规范,以及一些其它 ...

  5. SQL语句新建表,同时添加主键、索引、约束

    SQL语句新建数据表   主键,索引,约束 CREATE TABLE [dbo].[T_SendInsideMessageRec]( [SendInsideMID] [uniqueidentifier ...

  6. Cocos2d-x标签文乱码问题

    我们在Windows下使用Visual Studio 2012开发游戏的时候,使用标签中包含中文时候会出现乱码或无法显示,如下图所示: 而应该显示的中文是如下图所示: HelloWorldScene. ...

  7. 13款精彩实用的最新jQuery插件

    1.jQuery特色菜单 圆形动画菜单插件 jQuery是一个非常流行的WEB前端框架,尽管HTML5非常酷,但是如果HTML5结合jQuery的话就能实现更酷更实用的插件.今天分享的这款jQuery ...

  8. Oracle11g使用exp导出空表

    1.Oracle11g默认对空表不分配segment,故使用exp导出Oracle11g数据库时,空表不会导出. 2.设置deferred_segment_creation 参数为FALSE后,无论是 ...

  9. C++学习——类的继承

    公有继承(public).私有继承(private).保护继承(protected)是常用的三种继承方式. 1. 公有继承(public) 公有继承的特点是基类的公有成员和保护成员作为派生类的成员时, ...

  10. F. Igor and Interesting Numbers

    http://codeforces.com/contest/747/problem/F cf #387 div2 problem f 非常好的一道题.看完题,然后就不知道怎么做,感觉是dp,但是不知道 ...