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. backbone.Model 源码笔记

    backbone.Model backbone的model(模型),用来存储数据,交互数据,数据验证,在view里面可以直接监听model来达到model一改变,就通知视图. 这个里面的代码是从bac ...

  2. 【PHP基础】常用mySQL语句以及WampServer2.2设置数据库默认编码

    一.WampServer2.2设置数据库默认编码(此部分转自http://www.cnsecer.com/5984.html) wamp下MySQL的默认编码是Latin1,不支持中文,要支持中文的话 ...

  3. 22----2013.06.29---HTML--html介绍.超链接和图片,表格,表单,表单标签,meta,复习当天内容

    01 HTML HTML :Hypertext Markup Language   超文本标记语言(类似于 裸奔的人.) 作用:向用户展示信息. CSS: Cascading 层叠样式表(类似于 人的 ...

  4. [老老实实学WCF] 第一篇 Hello WCF

    老老实实学WCF  第一篇 Hello WCF WCF(Windows Communication Foundation)是微软公司推出的面向服务技术的集大成者,涵盖继承了其之前发布的所有的分布式应用 ...

  5. 在iOS中,实现点击搜索结果隐藏搜索结果的方法。

    不知道有没有别的什么的好的方法,最近在实现一个需求(点击搜索,然后输入搜索内容,显示搜索出来的结果,然后点击搜索结果,在当前页面显示所点击的结果的详细的信息).遇到的问题是,点击搜索结果的时候,搜索的 ...

  6. 利用ExcelDataReader封装类 导入表格数据

    nuget 添加Install-Package ExcelDataReader

  7. List.Select按字符串选择属性

    不知道大家有没有遇到这样的情况:List使用Lambda表达式的时候,想要选择项的某个属性列. 例如,选择编号ID: var idList=list.Select(o=>o.ID).ToList ...

  8. 简单的json传送数据

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  9. Template_5模板拾遗1

    1,typename和class模板参数作为类的时候只能用classtemplate<typename T, template<typename ELEM> class CONT = ...

  10. MVC5_学习笔记_1_CodeFirst

    MVC5_EF6_1/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) *//* Author: Nicolas Hery - ...