我正在使用目标代码模型从sharepoint搜索中检索搜索结果。任何人都可以建议如何为我的搜索添加高级搜索选项。目标代码模型具有执行高级搜索的功能。
答案 0 :(得分:1)
是的,您可以使用FullTextSqlQuery类执行高级搜索,如下面的代码示例所示。另请参阅Best Practices: Writing SQL Syntax Queries for Relevant Results in Enterprise Search。
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
};