织梦Dedecms系统实现按“字母检索”搜索功能(3)

//判断是否为声母搜索
if($searchtype<>"pytitle"){
if($keyword==""||strlen($keyword)<3){
ShowMsg("关键字不能小于3个字节!","-1");
exit();
}
}

第五步,修改并实现搜索。

修改/include/inc_arcsearch_view.php,目标:

获得字母关键字,生成新的检索条件,获取搜索类型关键字($searchtype),调用不同的显示模板。

好的,我们继续修改,修改如下,红色部分为新增或者修改的部分。

修改function GetKeywordSql()函数,新增:

//声母搜索支持
if($this->SearchType=="pytitle"){
  $kwsql .= " And dede_archives.pytitle like '$this->Keywords%' ";
}

仿站建议放在foreach($ks as $k){...}下面

第六步,通过上面,已经实现了按字母索引,但是调用的是系统的搜索模板,不适合按照字母索引的特点,因此我们需要更进一步,增加新的模板支持。

1、修改/include/inc_arcsearch_view.php,修改function __construct()构造函数。为:

if($this->SearchType=="pytitle") $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/".$GLOBALS['cfg_templets_pysearch'];
  else $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search.htm";

目标是判断当$searchtype==pytitle的时候,调用全局变量cfg_templets_pysearch定义的模板。

2、修改include/config_hand.php文件。增加全局变量cfg_templets_pysearch。

//拼音搜索模板
$cfg_templets_pysearch = 'pylist.htm';

然后就可以在模板文件夹里面新增pylist.htm模板,来显示字母列表的结果了。

第七步,事情还没结束呢。要是我希望限制显示的范围怎么办?例如我只想显示软件的,或者某个栏目的这么显示,更进一步。

其实search支持很多参数,例如$typeid(栏目编号)、$channeltype(文章类型编号)、$orderby(排序方法)等,现在你知道怎么办了吧?还不知道,下面是一个例子:

<a href=http://www.dede58.com/"/plus/search.php?keyword=a&searchtype=pytitle&typeid=2&$channeltype=3&$orderby=title">A</a>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/210cf0cd690a866ce598cb90e99eb4b7.html