2

我正在使用目标代码模型从共享点搜索中检索搜索结果。任何人都可以建议我如何为我的搜索设置高级搜索选项。目标代码模型是否具有执行高级搜索的功能。

4

1 回答 1

1

是的,您可以使用FullTextSqlQuery类执行高级搜索,如下面的代码示例所示。另请参阅最佳实践:为企业搜索中的相关结果编写 SQL 语法查询

using (SPSite site = new SPSite("http://server"))   // Site Collection URL
using (FullTextSqlQuery query = new FullTextSqlQuery(site))
{
  query.ResultTypes = ResultType.RelevantResults;
  query.EnableStemming = true;
  query.TrimDuplicates = true;
  query.Culture = new CultureInfo(1033);    // Use en-US stemmer and word-breaker
  query.RowLimit = 40;
  query.StartRow = 0;
  query.KeywordInclusion = KeywordInclusion.Allkeywords;   // Implicit AND search
  query.HighlightedSentenceCount = 3;
  query.SiteContext = new Uri("http://server");  // Site Collection URL
  query.QueryText = "SELECT WorkId, Title, Path, HitHighlightedSummary, HitHighlightedProperties, CollapsingStatus, Description, Rank, Size" +
                     " FROM SCOPE()" +
                     " WHERE \"scope\" = 'A Scope'" +
                     " AND FREETEXT(defaultproperties, 'keyword1 keyword2')" +
                     " AND Color = 'Black'" + // Color is a managed property
                     " ORDER BY Rank DESC";            

  ResultTableCollection results = query.Execute();
  ResultTable relevantResults = results[ResultType.RelevantResults];

  // TODO: Process results
};
于 2009-03-13T10:48:36.910 回答