ecshop二次开发--热词搜索且显示

本文介绍了一种优化网站搜索功能的方法,通过修改页面头部文件并利用数据库中的搜索记录,实现了热门搜索词的展示,并能根据搜索引擎来源统计关键词的使用频率。

1.进入upload->themes->degault->library->page_header.lbi中搜索以下代码

    {if $searchkeywords}  
      
         {$lang.hot_search} :  
      
        {foreach from=$searchkeywords item=val}  
      
            <a href="search.php?keywords={$val|escape:url}">{$val}</a>  
      
        {/foreach}  
      
    {/if}  

2,把搜索到的代码替换为一下代码

   {$lang.hot_search} :  
  
    {if $searchkeywords}  
  
        {foreach from=$searchkeywords item=val}  
  
            <a href="search.php?keywords={$val|escape:url}">{$val}</a>  
  
        {/foreach}  
  
{/if}  
  
// 数据库ecs_keywords 表中的数据  
  
         {if $searchengine}  
  
                   {foreach from=$searchengine item=val}  
  
                            {foreach from=$val key=key item=v}  
  
                                     <a href="search.php?keywords={$key|escape:url}">{$key}</a>  
  
                            {/foreach}  
  
                   {/foreach}  
  
         {/if}  

3.进入upload->admin->searchengie_stats.php复制一下代码

    /* 时间参数 */  
    /* TODO: 时间需要改 */  
    if (isset($_POST) && !empty($_POST))  
    {  
        $start_date = $_POST['start_date'];  
        $end_date   = $_POST['end_date'];  
    }  
    else  
    {  
        $start_date = local_date('Y-m-d', strtotime('-1 week'));  
        $end_date   = local_date('Y-m-d');  
    }  
    /* ------------------------------------- */  
    /* --综合流量  
    /* ------------------------------------- */  
    $max = 0;  
    $general_xml = "<chart caption='$_LANG[tab_keywords]' shownames='1' showvalues='0' decimals='0' numberPrefix='' outCnvBaseFontSize='12' baseFontSize='12'>";  
    $sql = "SELECT keyword, count, searchengine ".  
            " FROM " .$ecs->table('keywords').  
            " WHERE date >= '$start_date' AND date <= '" .$end_date. "'";  
    if (isset($_POST['filter']))  
    {  
        $sql .= ' AND '. db_create_in($_POST['filter'], 'searchengine');  
    }  
    $res = $db->query($sql);  
    $search = array();  
    $searchengine = array();  
    $keyword = array();  
      
    while ($val = $db->fetchRow($res))  
    {  
        $keyword[$val['keyword']] = 1;  
        $searchengine[$val['searchengine']][$val['keyword']] = $val['count'];  
    }  



4.将你复制到的代码放入到upload->includes->lib_main.php后找到assign_template方法后,将你复制到的代码放到assign_template后

注意:第四步是我已经将第三部代码所整合在一起了,所以在这里第三部你可以省下不用写。

以下代码是我将我所复制的代码放到assign_template方法后的效果

    function assign_template($ctype = '', $catlist = array())  
    {  
        global $smarty;  
      
        $smarty->assign('image_width',   $GLOBALS['_CFG']['image_width']);  
        $smarty->assign('image_height',  $GLOBALS['_CFG']['image_height']);  
        $smarty->assign('points_name',   $GLOBALS['_CFG']['integral_name']);  
        $smarty->assign('qq',            explode(',', $GLOBALS['_CFG']['qq']));  
        $smarty->assign('ww',            explode(',', $GLOBALS['_CFG']['ww']));  
        $smarty->assign('ym',            explode(',', $GLOBALS['_CFG']['ym']));  
        $smarty->assign('msn',           explode(',', $GLOBALS['_CFG']['msn']));  
        $smarty->assign('skype',         explode(',', $GLOBALS['_CFG']['skype']));  
        $smarty->assign('stats_code',    $GLOBALS['_CFG']['stats_code']);  
        $smarty->assign('copyright',     sprintf($GLOBALS['_LANG']['copyright'], date('Y'), $GLOBALS['_CFG']['shop_name']));  
        $smarty->assign('shop_name',     $GLOBALS['_CFG']['shop_name']);  
        $smarty->assign('service_email', $GLOBALS['_CFG']['service_email']);  
        $smarty->assign('service_phone', $GLOBALS['_CFG']['service_phone']);  
        $smarty->assign('shop_address',  $GLOBALS['_CFG']['shop_address']);  
        $smarty->assign('licensed',      license_info());  
        $smarty->assign('ecs_version',   VERSION);  
        $smarty->assign('icp_number',    $GLOBALS['_CFG']['icp_number']);  
        $smarty->assign('username',      !empty($_SESSION['user_name']) ? $_SESSION['user_name'] : '');  
        $smarty->assign('category_list', cat_list(0, 0, true,  2, false));  
        $smarty->assign('catalog_list',  cat_list(0, 0, false, 1, false));  
        $smarty->assign('navigator_list',        get_navigator($ctype, $catlist));  //自定义导航栏  
      
        if (!empty($GLOBALS['_CFG']['search_keywords']))  
        {  
            $searchkeywords = explode(',', trim($GLOBALS['_CFG']['search_keywords']));  
        }  
        else  
        {  
            $searchkeywords = array();  
        }  
        $smarty->assign('searchkeywords', $searchkeywords);  
        /* 时间参数 */  
        /* TODO: 时间需要改 */  
        if (isset($_POST) && !empty($_POST))  
        {  
            $start_date = $_POST['start_date'];  
            $end_date   = $_POST['end_date'];  
        }  
        else  
        {  
            $start_date = local_date('Y-m-d', strtotime('-1 week'));  
            $end_date   = local_date('Y-m-d');  
        }  
        /* ------------------------------------- */  
        /* --综合流量  
        /* ------------------------------------- */  
        $max = 0;  
        //$general_xml = "<chart caption='$_LANG[tab_keywords]' shownames='1' showvalues='0' decimals='0' numberPrefix='' outCnvBaseFontSize='12' baseFontSize='12'>";  
        $sql = "SELECT keyword, count, searchengine ".  
                " FROM " .$GLOBALS['ecs']->table('keywords').  
                " WHERE date >= '$start_date' AND date <= '" .$end_date. "'order by count desc limit 5";  
        if (isset($_POST['filter']))  
        {  
            $sql .= ' AND '. db_create_in($_POST['filter'], 'searchengine');  
        }  
        $res = $GLOBALS['db']->query($sql);  
        $search = array();  
        $searchengine = array();  
        $keyword = array();  
      
        while ($val = $GLOBALS['db']->fetchRow($res))  
        {  
            $keyword[$val['keyword']] = 1;  
            $searchengine[$val['searchengine']][$val['keyword']] = $val['count'];  
        }  
        $smarty->assign("searchengine",$searchengine);  
    }  



5.这样所做的搜索就到此完毕了。


第一种案例演示:






第二种案例演示:(直接从后台进行添加,你所想要搜索的词语)



安装说明: 1. 复制search 目录到网站根目录,请不要修改此文件夹的名称 2. 初次安装, 访问: 域名/search/baseline.php 例如:你的域名是www.ahuoo.com, 那么请访问 www.ahuoo.com/search/baseline.php 3. 修改代码 1.先备份网站根目录的search.php,然后用插件里面的替换掉 2.在模版中找到商品搜索页中的商品名称显示语句,有些模版在library/search_goods_list.lbi文件中,如果没有search_goods_list.lbi文件那就在search.dwt文件中。 语句如: <a href="{$goods.url}" title="{$goods.goods_name|escape:html}" class="name">{$goods.goods_name}</a> 将其中的{$goods.goods_name}改为{$goods.new_goods_name} 3. 在admin\goods.php文件中找到如下代码: sys_msg($is_insert ? $_LANG['add_goods_ok'] : $_LANG['edit_goods_ok'], 0, $link); 在此代码上一行前添加如下代码: require_once ('../search/delta.php'); //ahuoo 4. 在admin\category.php文件中找到如下代码: sys_msg($_LANG['catedit_succed'], 0, $link); 在此代码上一行前添加如下代码: require_once ('../search/delta.php'); //ahuoo 4. 如果需要添加自定义关键词可访问: 域名/search/add_word.php 一般情况下是不需要的。 插件原理: Ecshop默认情况下搜索是根据数据库按搜索的字符串去匹配,不能自动根据需要去自动分词。 例如:你搜索“李宁安踏” 标题里面必须要有“李宁安踏”才能出来, 如果某个商品标题只有“李宁”是不会出来的,这样对于普通的用户是不友好的。 本插件提供的功能: 1.提供一种强大的分词搜索,用户可以不用空格某几个分词,随便打一个句子就可以搜索出对应的结果 2.可以自定义分词。 3.搜索结果自动按照相关度排序,相关度越相关,越排在最前面。 插件为试用版,如果正式使用可以联系作者购买,当前只索引了商品的标题和分类信息,如果需要索引商品详情可以定制化开发,shopex也会有对应的版本。 插件作者 :阿虎 QQ:1976468723 演示地址: 前台:http://ahuoo.com/ec/search.php?encode=YTo0OntzOjg6ImNhdGVnb3J5IjtzOjE6IjAiO3M6ODoia2V5d29yZHMiO3M6MTI6IuiBlOmAmuS4ieaYnyI7czoxMDoiaW1hZ2VGaWVsZCI7czowOiIiO3M6MTg6InNlYXJjaF9lbmNvZGVfdGltZSI7aToxNDQ5MDYxNTAzO30= 后台: http://ahuoo.com/ec/admin 用户名/密码:test/test123
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值