当我们配置好MOSS搜索好,但它默认的搜索链接是该文档本身的连接,而非我们想要的链接,有时候我们想要的是它的别一个栏来当链接,有时候我们也想显示别的栏给用户看,可以通过修改搜索结果中返回的属性来达到目的。
1. 首先要了解MOSS搜索返回的是什么
MOSS搜索结果返回的是XML数据集, 那它返回的XML数据格式是怎样的哪,如下:
代码
<
All_Results
>
<
Result
>
<
id
>
1
</
id
>
<
workid
>
56859
</
workid
>
<
rank
>
851
</
rank
>
<
title
>
区信息办整合政务基础数据,推进信息资源共享
</
title
>
<
author
>
系统帐户
</
author
>
<
size
>
5836
</
size
>
<
url
>
http:
//
localhost:7001/BMYW/XXB/2009/6339694771417558327245.HTML</url>
<
urlEncoded
>
http
%
3A
%
2F
%
2F172
%
2E25
%
2E0
%
2E185
%
3A7001
%
2FBMYW
%
2FXXB
%
2F2009
%
2F6339694771417558327245
%
2EHTML
</
urlEncoded
>
<
description
></
description
>
<
write
>
2009
/
5
/
21
</
write
>
<
sitename
>
http:
//
localhost:7001</sitename>
<
collapsingstatus
>
0
</
collapsingstatus
>
<
hithighlightedsummary
>
<
ddd
/>
<
c0
>
信息
</
c0
>
办整合了涉及全区37个政务部门的412类,
264
.3万项政务基础数据,研究建立以
<
c0
>
信息
</
c0
>
资源目录为引导的
<
c0
>
信息
</
c0
>
资源共享服务体系。
<
c0
>
信息
</
c0
>
资源内容涵盖经济建设、社会管理与服务等多领域、多部门、多应用主题,将于
<
ddd
/>
</
hithighlightedsummary
>
<
hithighlightedproperties
>
<
HHTitle
>
区
<
c0
>
信息
</
c0
>
办整合政务基础数据,推进
<
c0
>
信息
</
c0
>
资源共享
</
HHTitle
>
<
HHUrl
>
http:
//
localhost:7001/BMYW/XXB/2009/6339694771417558327245.HTML</HHUrl>
</
hithighlightedproperties
>
<
contentclass
>
STS_ListItem_DocumentLibrary
</
contentclass
>
<
isdocument
>
1
</
isdocument
>
<
picturethumbnailurl
></
picturethumbnailurl
>
<
imageurl imageurldescription
=
"
类型结果: 文档
"
>/
_layouts
/
images
/
html16.gif
</
imageurl
>
</
Result
>
<
Result
>
...
</
Result
>
</
All_Results
>
上面代码可以能过修改MOSS搜索结果的XSL属性看到,做法是把MOSS搜索核心结果WEB部件的XSL默认属性改成:
代码
<?
xml version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
<
xsl:stylesheet version
=
"
1.0
"
xmlns:xsl
=
"
http://www.w3.org/1999/XSL/Transform
"
>
<
xsl:output method
=
"
xml
"
version
=
"
1.0
"
encoding
=
"
UTF-8
"
indent
=
"
yes
"
/>
<
xsl:template match
=
"
/
"
>
<
xsl:copy
-
of select
=
"
*
"
/>
</
xsl:template
>
</
xsl:stylesheet
>
修改完后再查看搜索结果的html源代码就可以找到上面的XML代码。从上面的代码可以看出MOSS搜索结果返回的主要属性有workid,title,url,HHTitle,HHUrl等这些属性。
2. 添加元数据属性映射
因为搜索结果返回的属性是从元数据属性映射过来的,所以对于我们要在搜索结果中新加的属性必须选配置元数据属性映射,关于如何配置元数据属性映射,请看写的《MOSS Search学习记录(五):利用元数据和规则搜索多个列表中指定范围的内容》,注意配好要启动完全爬网,而不是添量爬网,要么新加的属性值为空。
3. 向搜索查询添加属性
打开搜索结果核心WEB部件的结果查询选项中选定的列,可以看到里面的Column就是我们刚刚从搜索结果的html文件中查看到的XML文件的属性,workid,title
,url,HHTitle,HHUrl等,在里面加入我们要用于当链接的属性,如添加><Column Name="LinkTo"/> ,LinkTo是文档库中的一个栏名,但它必须得是元数据的映射。
4. 修改搜索核心 Web 部件的 XSL,让它包含新属性
把搜索核心结果WEB部件的XSL修改回原来的,找到如下代码:
代码
<
xsl:template match
=
"
Result
"
>
<
xsl:variable name
=
"
id
"
select
=
"
id
"
/>
<
xsl:variable name
=
"
url
"
select
=
"
url
"
/>
<
span
class
=
"
srch-Icon
"
>
<
a href
=
"
{$url}
"
id
=
"
{concat('CSR_IMG_',$id)}
"
title
=
"
{$url}
"
>
<
img align
=
"
absmiddle
"
src
=
"
{imageurl}
"
border
=
"
0
"
alt
=
"
{imageurl/@imageurldescription}
"
/>
</
a
>
</
span
>
<
span
class
=
"
srch-Title
"
>
<
a href
=
"
{$url}
"
id
=
"
{concat('CSR_',$id)}
"
title
=
"
{$url}
"
>
<
xsl:choose
>
<
xsl:when test
=
"
hithighlightedproperties/HHTitle[. != '']
"
>
<
xsl:call
-
template name
=
"
HitHighlighting
"
>
<
xsl:with
-
param name
=
"
hh
"
select
=
"
hithighlightedproperties/HHTitle
"
/>
</
xsl:call
-
template
>
</
xsl:when
>
<
xsl:otherwise
><
xsl:value
-
of select
=
"
title
"
/></
xsl:otherwise
>
</
xsl:choose
>
</
a
>
<
br
/>
</
span
>
<
xsl:choose
>
<
xsl:when test
=
"
$IsThisListScope = 'True' and contentclass[. = 'STS_ListItem_PictureLibrary'] and picturethumbnailurl[. != '']
"
>
<
div style
=
"
padding-top: 2px; padding-bottom: 2px;
"
>
<
a href
=
"
{$url}
"
id
=
"
{concat('CSR_P',$id)}
"
title
=
"
{title}
"
>
<
img src
=
"
{picturethumbnailurl}
"
alt
=
""
/>
</
a
>
</
div
>
</
xsl:when
>
</
xsl:choose
>
<
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
>
<
p
class
=
"
srch-Metadata
"
>
<
span
class
=
"
srch-URL
"
>
<
a href
=
"
{$url}
"
id
=
"
{concat('CSR_U_',$id)}
"
title
=
"
{$url}
"
dir
=
"
ltr
"
>
<
xsl:choose
>
<
xsl:when test
=
"
hithighlightedproperties/HHUrl[. != '']
"
>
<
xsl:call
-
template name
=
"
HitHighlighting
"
>
<
xsl:with
-
param name
=
"
hh
"
select
=
"
hithighlightedproperties/HHUrl
"
/>
</
xsl:call
-
template
>
</
xsl:when
>
<
xsl:otherwise
><
xsl:value
-
of select
=
"
url
"
/></
xsl:otherwise
>
</
xsl:choose
>
</
a
>
</
span
>
<
xsl:call
-
template name
=
"
DisplaySize
"
>
<
xsl:with
-
param name
=
"
size
"
select
=
"
size
"
/>
</
xsl:call
-
template
>
<
xsl:call
-
template name
=
"
DisplayString
"
>
<
xsl:with
-
param name
=
"
str
"
select
=
"
author
"
/>
</
xsl:call
-
template
>
<
xsl:call
-
template name
=
"
DisplayString
"
>
<
xsl:with
-
param name
=
"
str
"
select
=
"
write
"
/>
</
xsl:call
-
template
>
<
xsl:call
-
template name
=
"
DisplayCollapsingStatusLink
"
>
<
xsl:with
-
param name
=
"
status
"
select
=
"
collapsingstatus
"
/>
<
xsl:with
-
param name
=
"
urlEncoded
"
select
=
"
urlEncoded
"
/>
<
xsl:with
-
param name
=
"
id
"
select
=
"
concat('CSR_CS_',$id)
"
/>
</
xsl:call
-
template
>
</
p
>
</
xsl:template
>
上面代码就是搜索结果Result的配置,可以看到 <xsl:variable name="url" select="url"/>,下面的<a></a>链接中有<a href="{$url}">等结果,就明白它们是怎么显示的了,先把 <xsl:variable name="url" select="url"/>改成 <xsl:variable name="linkto" select="linkto"/>,然后再改链接<a href="{$url}">为<a href="{$linkto}">,保存好结果就是我们想要达到的了,在里面还可以改或添加自己想达到的效果。