1

我按照http://technet.microsoft.com/en-us/library/ff621097(v=office.14).aspx上的说明创建了一些托管属性。然后,我使用以下代码创建了一个自定义 SharePoint 应用程序页面,其中包含 KeywordQuery 搜索以仅查找文档:

using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.Office.Server.Search.Query;
using Microsoft.SharePoint.WebControls;

protected System.Data.DataTable TrySearch(string keywords, Int32 pageSize, Int32 page, out Int32 totalPages)
{

    int startRow = (page - 1)*rowLimit;

    var kwq = new KeywordQuery(Site);
    kwq.QueryText = string.Format("Title:\"{0}\"", keywords);
    kwq.ResultTypes = ResultType.RelevantResults;
    kwq.RowLimit = pageSize;
    kwq.StartRow = startRow;
    kwq.TrimDuplicates = true;
    kwq.HiddenConstraints = "path:\"*/User Docs*\" AND IsDocument:true";
    kwq.KeywordInclusion = KeywordInclusion.AllKeywords;

    // Default
    kwq.SelectProperties.Add("WorkId");
    kwq.SelectProperties.Add("Rank");
    kwq.SelectProperties.Add("Title");
    kwq.SelectProperties.Add("Path");
    kwq.SelectProperties.Add("SiteName");
    kwq.SelectProperties.Add("HitHighlightedSummary");
    kwq.SelectProperties.Add("HitHighlightedProperties");
    kwq.SelectProperties.Add("ContentClass");
    kwq.SelectProperties.Add("IsDocument");

    // Custom (they come back blank even when set as managed properties)
    kwq.SelectProperties.Add("IntroText");
    kwq.SelectProperties.Add("Date");
    kwq.SelectProperties.Add("ListItemId");        

    ResultTableCollection rtc = kwq.Execute();

    var results = new DataTable();

    if (rtc.Count == 0)
    {
        totalPages = 0;
        return results;
    }

    using (ResultTable relevantResults = rtc[ResultType.RelevantResults])
    {
        results.Load(relevantResults, LoadOption.OverwriteChanges);
        totalPages = (int) Math.Round((double) relevantResults.TotalRows/pageSize);
    }

    return results;
}

我的问题是,无论我做什么,我都无法为我的托管属性取回值。搜索工作正常。我可以相应地过滤并得到我期望的结果,只是自定义列是空的。我最关心的是 ID,但我很想获得我要求的所有自定义属性。

我在服务器上错过了某种设置吗?任何帮助表示赞赏。

4

1 回答 1

0

我想你现在一定已经找到了解决方案,但对于那些在同样问题上苦苦挣扎的人来说,解决方案是:

将爬网属性映射到现有/新托管属性后,再次爬网。而已。将显示所请求属性的数据。

于 2014-02-04T07:08:19.140 回答