[转]MOSS 2007 最简单的自定义搜索框 SearchBox

项目有个需要就是对搜索中心进行定制,要求普通搜索,只对标题搜索,高级搜索才对内容搜索。

这个问题好长一段时间不能解决,原本打算重新用搜索的API,重新开发所有搜索的webpart,最后找到一个比较简单的方法:

1 通过研究,可以用JS实现,搜索框与原来的搜索框样式一样。

2 添加一个自定义的搜索结果页:  /Search/customResults.aspx,

编写核心搜索的xslt,屏蔽掉如下代码,就是不显示内容搜索的内容:

 
  
< div class = " srch-Description " >
< xsl:choose >


<!--
< xsl:when test = " hithighlightedsummary[. != ''] " >
< xsl:call - template name = " HitHighlighting " >
< xsl:with - param name = " hh " select = " hithighlightedsummary " />
</ xsl:call - template >
</ xsl:when >

-->

< xsl:when test = " description[. != ''] " >
< xsl:value - of select = " description " />
</ xsl:when >
</ xsl:choose >
</ div >

3 高级搜索中,结果页还用原来的结果页显示/Search/results.aspx

4 分别在/Search/results.aspx,/Search/customResults.aspx,/Search/default.aspx页面删除原来的搜索框,

添加一个内容编辑器Web部件,添加如下HTML代码,即可。

通过JS会自动在普通搜索中,添加“k=title:guoqiang”,这样就实现了只对标题guoqiang进行搜索了。

 
  
< script type = " text/javascript " >
function CustomSearch() {
var key
= document.getElementById( " customInputKeywords " ).value;
var searchUrl
= " /Search/customResults.aspx?k=title%3A " + key;
top.location.href
= searchUrl;
return true ;
}


function CustomAdvSearch() {

var key
= document.getElementById( " customInputKeywords " ).value;
var searchUrl
= " /Search/advanced.aspx?k= " + key;
top.location.href
= searchUrl;
return true ;

}
</ script >


< table class = " ms-sbtable ms-sbtable-ex " border = " 0 " >
< tbody >
< tr class = " ms-sbrow " >
< td class = " ms-sbcell " >
< input type = " text "
style
= " width: 280px " id = " customInputKeywords "
class = " ms-sbplain "
title
= " 输入搜索文字 "
alt
= " 输入搜索文字 " maxlength = " 200 " />
</ td >
< td class = " ms-sbgo ms-sbcell " >
< a id = " customGo " title = " 开始搜索 "
href
= " javascript:CustomSearch() " >
< img style = " border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px;
border - left - width: 0px "
title = " 开始搜索 " alt = " 开始搜索 "
src
= " /_layouts/images/gosearch.gif " /></ a >
</ td >
< td class = " ms-sbcell ms-sblink " >
< a id = " customAdvSearchLink " title = " 高级搜索 " href = " javascript:CustomAdvSearch() " > 高级搜索 </ a >
</ td >
</ tr >
</ tbody >
</ table >

原文地址:http://blog.csdn.net/guoqiang1983/archive/2009/10/11/4653791.aspx

转载于:https://www.cnblogs.com/bmib/archive/2011/03/28/1998084.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值