关键词联想关联 php,ECSHOP商品关键词模糊分词搜索插件,商品列表关键字加红功能...
各位ECSHOP網店系統用戶大家好,歡迎來到ECSHOP商品關鍵詞模糊分詞搜索商品列表關鍵字加紅功能。
最近給客戶做一個ECSHOP商城,發現ECSHOP的模糊搜索要求太高,需要加入and、空格、加號等,客戶搜索的時候不可能這樣操作。
考慮到工期的問題,采用了織夢的分詞算法,搜索效果雖然不是特別理想,但是這么短的時間也只能這樣了。
在此分享給沒錢又著急的朋友,需要用到的文件在文章末尾提供下載,大家下載后也可以直接覆蓋使用。
一、ECSHOP聯想下拉框
1、修改page_header.lbi模版文件,將搜索文本框修改為:ecshop"?class="search-input"??οnfοcus="if(this.value=='ecshop'){this.value='';this.style.color='#000';}"??οnblur="closediv();if(this.value==''){this.value='ecshop';this.style.color='#999';}"?style="color:#999;"??οnkeyup="keyupdeal(event,this.value);"?οnkeydοwn="keydowndeal(event);"?οnclick="keyupdeal(event,this.value);"???autocomplete="off"?/>????
嵌入js文件
嵌入css文件
2、根目錄添加php文件search_suggest.php文件
二、分詞搜索
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";
打開 /includes/lib_goods.php 文件(建議使用editplus)找到下面代碼(大概在287行左右)/*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($setable("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,"$ph",$tihuan);?????????}????????????????$arr[$row['goods_id']]['goods_name']?=?$row['goods_name'];//因為前臺用到沒有替換的商品名稱,所以保留goods_name值
$arr[$row['goods_id']]['tihuan']?=?$tihuan;?????????/*根據分詞對產品名稱進行替換-end*/
2、修改search.dwt模板文件
將顯示商品名稱的地方替換為:
{$goods.tihuan}
四、文中所有涉及的修改和要用到的文件
總結
以上是生活随笔為你收集整理的关键词联想关联 php,ECSHOP商品关键词模糊分词搜索插件,商品列表关键字加红功能...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里巴巴矢量图标库的引入——symbol
- 下一篇: PHP聊天记录内啥,PHP的PSR系列轨