您可以通过powershell添加新的搜索范围: New-SPEnterpriseSearchQueryScope -SearchApplication“Search Service Application” - Name NewSearchScope -Description“New Search Test Scope”-DisplayInAdminUI 1-OwningSiteUrl http://servername/sites/
但有没有人知道示例代码如何通过OM执行此操作? (使用Microsoft.SharePoint.Administration命名空间而不是Microsoft.Office.Server.Search)
任何指针都会很棒
问候 沫
的 的 *更新* * 忽略错误处理/日志记录等,这是一种有效的方法:
SPSite siteColl =(SPSite)properties.Feature.Parent;
Microsoft.SharePoint.Administration.SPServiceApplication spserviceapp = siteColl.SearchServiceInstance.Service.Applications["Search Service Application"];
SearchServiceApplication searchserviceapp = (SearchServiceApplication)spserviceapp;
ScopeInfo scopeInfo = new ScopeInfo();
scopeInfo.Name = "Scope test1";
scopeInfo.Description = "Scope test1";
scopeInfo.DisplayInAdminUI = true;
scopeInfo.CompilationType = ScopeCompilationType.AlwaysCompile;
scopeInfo.CompilationState = ScopeCompilationState.NeedsCompile;
int statusCode = 0;
int scopeId = searchserviceapp.AddScope(scopeInfo, out statusCode);
if (scopeId > 0)
{
RuleInfo ruleInfo;
ruleInfo = new RuleInfo();
ruleInfo.FilterBehavior = ScopeRuleFilterBehavior.Include;
ruleInfo.RuleType = ScopeRuleType.AllContent;
int ruleId = searchserviceapp.AddRule(ruleInfo, scopeId);
}
searchserviceapp.Update(true);
而不是searchcontext的ssp方式?
SearchContext searchctx = null;
searchctx = SearchContext.GetContext(web.Site);
范围范围=新范围(searchctx);
范围currentScope = scopes.AllScopes.Create(
“CurrentScopeName”,string.Empty,new Uri(web.Site.Url),true,
string.Format(“{0} /Search/Pages/Results.aspx”,web.Site.Url),
ScopeCompilationType.AlwaysCompile);
currentScope.Update();
currentScope.Rules.CreateUrlRule(ScopeRuleFilterBehavior.Include,
UrlScopeRuleType.Domain,web.Site.Url);
ScopeDisplayGroup group = scopes.GetDisplayGroup(new Uri(web.Url),
“搜索下拉”); group.Add(currentScope);
group.Update();
scopes.StartCompilation();
scopes.Update();
答案 0 :(得分:0)
SearchContext
在SharePoint 2010 Server中标记为已过时,因此不是推荐的方法。