65.9K
CodeProject 正在变化。 阅读更多。
Home

Microsoft Content Management Server 搜索控件 (C#)

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.47/5 (9投票s)

2004年7月26日

CPOL

3分钟阅读

viewsIcon

256477

downloadIcon

1632

为内容管理服务器网站提供搜索功能,使用 SharePoint Portal Server 作为搜索引擎。

Sample Image - sample.gif

引言

这一套用户控件为 Microsoft 内容管理服务器 (MCMS) 网站提供搜索功能,使用 SharePoint Portal Server (SPS) 作为搜索引擎。它使用 SPS 的搜索 Web 服务提供简单的关键字搜索。提供了一个搜索选项来选择特定的内容索引。搜索结果显示在一个可自定义的 DataGrid 中。

此用户控件集的 VB.NET 版本可在 此处 获取。

SharePoint 设置

请参考 Emmanuel Desigaud 的 文章,了解如何为搜索设置 SPS。基本上,您需要设置一个内容索引并添加一个内容源。另外,请确保在您的 CMS 网站中执行搜索的用户可以访问 SPS 搜索 Web 服务。

安装

  1. SPSSearch.xml 复制到您的 XML 目录(如果存在),或者复制到您网站的任何位置。如果您想在搜索结果中包含其他列,请将其他字段添加到 select 语句中。您还可以更改返回的最大搜索结果数量,在 <Count>500</Count> 中,如果您愿意的话。
  2. 将用户控件 SearchInput 复制到您的用户控件目录。默认的搜索按钮是一个文本按钮。如果您想要一个图片按钮,请相应地更改 SearchButtonSearchImageButtonVisible 属性,并更新 SearchImageButtonImageUrl。即使您不使用其中一个按钮,也不要删除它们。
  3. 将用户控件 SearchResults 复制到您的用户控件目录。如果您在 SPSSearch.xml 中添加了其他字段,请自定义 SearchResult.ascx 以包含这些字段。在 SearchResults.aspx.cs 中,将第 18 行的命名空间 SPSSearchusing ProjectName.SPSSearch; 替换为您项目的名称。
  4. QueryService.csSearchUtilities.cs 复制到您的类目录。
  5. Search.css 复制到您的 CSS 目录。
  6. 在您的 web.config 中,将以下键添加到 appSettings
    <appSettings>
        <add key="QuestechSystems.SPSSearchUrl" 
          value="http://<SPSServer>/_vti_bin/search.asmx" />
        <add key="QuestechSystems.SPSSearchXml" value="[Url to SPSSearch.xml]" />
        <add key="QuestechSystems.SPSSearchIndexesText" 
          value="[A comma delimited list of Content Indexes Display Name]" />
        <add key="QuestechSystems.SPSSearchIndexesValue" 
          value="[A comma delimited list of Content Indexes]" />
    </appSettings>

    例如

    <appSettings>
        <add key="QuestechSystems.SPSSearchUrl" 
          value="http://<SPSServer>/_vti_bin/search.asmx" />
        <add key="QuestechSystems.SPSSearchXml" 
          value="/<CMS Site Application Name>/Xml/SPSSearch.xml" />
        <add key="QuestechSystems.SPSSearchIndexesText" 
          value="All,Sub Site 1,Sub Site 2" />
        <add key="QuestechSystems.SPSSearchIndexesValue" 
          value="All,Sub_Site_1_Content_Index,Sub_Site_2_Content_Index" />
    </appSettings>

    将在 SearchInput 用户控件中添加一个下拉列表用于显示指定的内容索引。“All”在 SPSSearchIndexesValue 中是一个特殊值,它定义搜索将在 SPSSearchIndexesValue 中定义的所有内容索引上执行。如果您只有一个内容索引需要搜索,请添加以下内容代替

    <appSettings>
        <add key="QuestechSystems.SPSSearchUrl" 
          value="http://<SPSServer>/_vti_bin/search.asmx" />
        <add key="QuestechSystems.SPSSearchXml" 
          value="/<CMS Site Application Name>/Xml/SPSSearch.xml" />
        <add key="QuestechSystems.SPSSearchIndexesValue" 
          value="Site_Content_Index" />
    </appSettings>

    在这种情况下,不会添加下拉列表。

  7. 将用户控件 SearchInput 添加到您的 CMS 网站中您希望显示搜索输入框的位置。结果页面的 URL 通过 SearchResultsUrl 属性指定。搜索结果页面可以是 CMS 模板页面,也可以是普通的 ASP.NET 页面。例如
    <%@ Register TagPrefix="uc1" 
        TagName="SearchInput" Src="~/UserControls/SearchInput.ascx" %>
    . . . . . .
    <uc1:SearchInput id="SearchInput" 
        SearchResultsUrl="" DefaultSearchIndex="" runat="server">
    </uc1:SearchInput>

    如果未指定 SearchResultsUrl,则使用当前页面作为结果页面。如果您指定了多个内容索引,可以使用 DefaultSearchIndex 属性选择默认要搜索的内容索引。自定义 SearchInput.ascx 以更改搜索输入元素的布局。

  8. 将用户控件 SearchResult 添加到您的搜索结果页面。该控件有两个可以设置的属性
    • DefaultPageSize: 每页搜索结果的数量。默认值为 10。
    • FilterRights: [true|false]。默认情况下,搜索结果将过滤掉您无权查看的任何 CMS 页面。如果您的搜索结果不包含任何授权内容和/或您希望提高性能,请将其设置为 false。但请谨慎使用。
  9. Search.css 包含到所有引用搜索控件的页面中。
  10. 将所有新文件包含到您的 CMS 项目中。在 VS.NET 中重新构建您的网站。

注释

  1. 如果 SearchResults 遇到任何错误,它会掩盖错误并返回“未找到页面”。要查看实际错误,请将查询字符串“debug=true”添加到搜索结果页面并重新加载页面。
  2. 搜索控件在 CMS 未发布模式下运行。返回的链接都是已发布的链接。

历史

  • V1.0 - 2004.07.26 - 基础版。
  • V1.1 - 2004.08.20 - 启用了对 meta Keywords 和 Description 的搜索。
  • V1.2 - 2005.02.05 - 添加了搜索多个内容索引的选项。
  • V1.3 - 2005.02.13 - 在 web.config 中添加了可配置的 SPS 搜索 Web 服务 URL,以方便部署。(请注意:所有 Web.Config 的 App Settings 键名现在都已按命名空间限定。)
  • V1.4 - 2005.06.25 - 允许精确短语搜索。
© . All rights reserved.