在WSS中高亮显示搜索结果

SharePoint中的搜索结果默认是不高亮显示搜索关键字的,最近我看到老外有一篇文章介绍如何实现这个
为了防止文章无法打开,就把它转载到这里一下。
原文地址:http://msd2d.com/newsletter_tip.aspx?section=sharepoint&id=c89e3424-d7e6-4f79-9c89-be219513357b

Highlighting search words in the WSS search results page


Submitted By: Igor Goldshtaub
Posted On: 4/10/2006

Description:

Hi all, 

Highlighting my searched text in the search results page is one of the basic features I would expect from a search engine. Unfortunately this is not the case in SharePoint 2003. 

Many of my customers requested a basic or extended support for Search results highlighting.

Extended support includes some extra functionality such as highlighting the text inside documents opened from the search results page. This will require a more complicated solution; you may find a link to a nice add-on that does the trick (both WSS and SPS) at the end of this article. 

If all you are interested for now is in highlighting the searched text in the WSS search results page, you should be able to complete this by adding some JavaScript code to the searchresults.aspx page located in the SharePoint layouts folder.

This example adds this functionality to an English SharePoint search result page. In case you are not using English please change any reference to "1033" to your own language's LCID number.

Solution Description:

ý First open the searchresults.aspx page to edit.

o   Open "C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033" folder.

o   Locate the "searchresults.aspx" file

Open it using notepad or any other text editor.

ý Then, you should insert a JavaScript code block into the page that will run and do the highlighting work for you:

o   Open a script block before the </body> tag:
            <script language="javascript">
                        //Your code goes here…

</script>

Copy the attached source code into the JavaScript block: 

ý Now, all you have to do is save and close the page, sit back and wait for compliments from your boss/customer/colleagues.

 And don’t tell me taking 5 minutes to do it wasn’t worth it!

 For conclusion, from now on – when you are searching items in a WSS site using nothing but the normal WSS search page, the results should look like this: 

Note: If you're looking for a more complete solution that support both SPS/WSS searches, and also highlights the searched text inside documents (MS WORD, HTML, .TXT, PDF), you should have a look at this SharePoint add-on we have developed at KWizCom:

http://www.kwizcom.com/ProductPage.asp?ProductID=28&ProductSubNodeID=79

 这是附件代码:

None.gif         
None.gifvar strSearchTerm 
=  document.forms[ " frmSearch " ].elements[ " SearchString " ].value;
None.gifHighlightSearchTerm(strSearchTerm);
None.gif
None.giffunction HighlightSearchTerm(strSearchTerm)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    var cellTables 
= document.all.tags("table");
InBlock.gif    var strSearchTerm 
= strSearchTerm.toLowerCase();
InBlock.gif    
if(strSearchTerm == "")
InBlock.gif        
return;
InBlock.gif    
for(var ii = 0; ii < cellTables.length; ii++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if((cellTables[ii].all["frmSearch"!= null|| (cellTables[ii].className != ""))
InBlock.gif            
continue;
InBlock.gif        var cellTags 
= cellTables[ii].all.tags("td");
InBlock.gif        
InBlock.gif        
for(var iii = 0; iii < cellTags.length; iii++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(cellTags[iii].className != "ms-vb")
InBlock.gif                
continue;
InBlock.gif            var strBodyText 
= cellTags[iii].innerHTML;
InBlock.gif            var strText 
= strBodyText.toLowerCase();
InBlock.gif            var i 
= -1;
InBlock.gif            var strNewText 
= "";
InBlock.gif            
while (strBodyText.length > 0
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                i 
= strText.indexOf(strSearchTerm, i+1);
InBlock.gif                
if (i < 0
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    strNewText 
+= strBodyText;
InBlock.gif                    strBodyText 
= "";
ExpandedSubBlockEnd.gif                }
 
InBlock.gif                
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (strBodyText.lastIndexOf(">", i) >= strBodyText.lastIndexOf("<", i)) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
if (strText.lastIndexOf("/script>", i) >= strText.lastIndexOf("<script", i)) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            strNewText 
+= strBodyText.substring(0, i) + "<B style='COLOR: black; BACKGROUND-COLOR: #ffff66'>" + strBodyText.substr(i, strSearchTerm.length) + "</B>";
InBlock.gif                            strBodyText 
= strBodyText.substr(i + strSearchTerm.length);
InBlock.gif                            strText 
= strBodyText.toLowerCase();
InBlock.gif                            i 
= -1;
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            cellTags[iii].innerHTML 
= strNewText;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/baoposhou/archive/2006/04/12/372809.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值