最新文章

点击排行

最新评论

当前位置:首页 > 网站制作 >
dedecms搜索功能强化修改,将搜索功能扩展到附加表的内
发表日期:2014-11-12 09:22 来源:未知 浏览: 评论:

  dede的高级搜索也只能搜索各个模块的标题,关键字,内容摘要等主表字段。对于附加表中的字段却搜索不到,比如文章的内容等附加表中的字段。由于dede默认搜索范围只限制在主表中,要想将文章、商品、分类信息等模块的内容也添加到搜索范围以内,仅凭原有的高级搜索也是无能为力。我的方法是将主表与各个附加表连表查询,从而获取附加表中的信息进行匹配。

内容来自oleou.com

  思路其实很简单,只是在实际操作过程中还是会遇到种种问题,以至于摸索了一个小周末,才将整个功能拓展出来,所以也是为了供参考,让更多的朋友不走弯路。有需要搜索文章内容的朋友可以看下~ 本文来自oleou

  以5.6为例,打开搜索类/include/arc.searchview.class.php第178行 本文来自oleou

$kwsqls[] = " CONCAT(arc.title,' ',arc.writer,' ',arc.keywords) like '%$k%' ";

  此行是关键字匹配。 内容来自oleou.com

  然后是493行 o l e o u.com

 

本文来自oleou

 //搜索 
$query = "Select arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,act.namerule2
,act.ispart,act.moresite,act.siteurl,act.sitepath from `{$this->AddTable}` arc left join `sq_arctype` act on arc.typeid=act.idwhere {$this->AddSql} $ordersql limit $limitstart,$row"; 

  此段是查询。

oleou

  要查文章的内容,就要将手伸到附加表中,即将主表与附加表连表查询。 o l e o u.com

  先链表,即将搜索功能代码替换为
 

oleou

 

本文来自oleou

 //搜索
$query = "Select arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,act.namerule2
,act.ispart,act.moresite,act.siteurl,act.sitepath,addart.body,addsho.body,addser.body from `{$this->AddTable}` arc
left join `sq_arctype` act on arc.typeid=act.id
left join `sq_addonarticle` addart on arc.id=addart.aid
left join `sq_addonshop` addsho on arc.id=addsho.aid
left join `sq_addonservice` addser on arc.id=addser.aid
where {$this->AddSql} $ordersql limit $limitstart,$row";

 

oleou.com

  我这里是查询文章、商品及自定义模型服务表的内容,大家根据各自需求连相应的附加表。

本文来自oleou

  表链好后就是关键字查询了,这里将178行代码改为 o l e o u.com

$kwsqls[] = " CONCAT(arc.title,' ',arc.description,' ',addart.body,' ',arc.keywords) like '%$k%' OR CONCAT(arc.title,' ',arc.description,' ',addsho.body,' ',arc.keywords) like '%$k%' OR CONCAT(arc.title,' ',arc.description,' ',addser.body,' ',arc.keywords) like '%$k%'";

 

www.oleou.com

  到这里还没完,运行的话会提示sql语句错误。原因是321行处也有个搜索关键字语句

本文来自oleou

 $cquery = "Select * From `{$this->AddTable}` arc where ".$this->AddSql;

  www.oleou.com

  这里也要对应的改为

www.oleou.com

$cquery = "Select arc.*,addart.body,addsho.body,addser.body From `{$this->AddTable}` arc
left join `sq_addonarticle` addart on arc.id=addart.aid
left join `sq_addonshop` addsho on arc.id=addsho.aid
left join `sq_addonservice` addser on arc.id=addser.aid
where ".$this->AddSql;

  oleou

  至此,就大功告成了。这可是我折腾了两天才搞定的,里面有几处出乎意料的错误,现在看起来都很简单,呵呵~

www.oleou.com

  希望对有些朋友有用~ o l e o u.com

本文标签: dedecms
OLEOU 2018
返回顶部