SharePoint 2010 - 在FullTextSqlQuery中使用SPS-Birthday

时间:2011-11-22 12:38:16

标签: sharepoint full-text-search

我正在尝试构建一个自定义的webpart来显示即将到来的生日。 此代码有效,但我需要检索生日以过滤我的结果。

我尝试使用SPS-Birthday,但后来我得到了一个异常

public static void BirthDay()
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                StringBuilder queryText = new StringBuilder();
                queryText.Append("SELECT PreferredName, AccountName, ??SPS-BIRTHDAY??");
                queryText.Append("FROM SCOPE() ");
                queryText.Append("WHERE \"scope\" = 'People' ");

                using (FullTextSqlQuery query = new FullTextSqlQuery(site))
                {
                    query.QueryText = queryText.ToString();
                    query.RankingModelId = "D9BFB1A1-9036-4627-83B2-BBD9983AC8A1";
                    query.KeywordInclusion = KeywordInclusion.AnyKeyword;
                    query.ResultTypes = ResultType.RelevantResults;
                    query.RowLimit = 5000;
                    ResultTableCollection results = new ResultTableCollection();

                    try
                    {
                        results = query.Execute();

                        if (results.Count == 0)
                            throw new ArgumentException("// No results");
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message, ex.InnerException);
                    }

                    ResultTable relevantResults = results[ResultType.RelevantResults];
                    resultDataTable = new DataTable();
                    resultDataTable.Load(relevantResults, LoadOption.OverwriteChanges);

                    count = resultDataTable.Rows.Count;
                }
            }

        });

1 个答案:

答案 0 :(得分:1)

尝试进入中央管理员并确保生日字段可以“在范围内使用”。转到中央管理员 - >管理搜索服务应用程序 - >元数据属性...然后查找并选择托管属性下的生日属性...然后单击“在范围中使用此字段”