开发者

How to group a Custom Search Scope in Site Collection Level using MOSS Object Model

开发者 https://www.devze.com 2023-01-23 16:31 出处:网络
I have created custom search scope in the FARM Level and I am able to see in my site collection search scope settings and I can enable to make custom search scope move it to default group through brow

I have created custom search scope in the FARM Level and I am able to see in my site collection search scope settings and I can enable to make custom search scope move it to default group through browser. Is there anyway I can achieve the same functionality using Custom coding in moss 2007 Object Model.

http://nickgrattan.files.wordpress.com/2007/08/shsc1.jpg?w=700

Any help would be appr开发者_运维问答eciated

Thanks

Deepu


using Microsoft.Office.Server;
using Microsoft.Office.Server.Search;
using Microsoft.Office.Server.Search.Administration;
 static void CreateScope()
        {
    SearchContext searchContext;
                using (SPSite site = new SPSite("Your SiteCollection Site"))
                {
                    searchContext = SearchContext.GetContext(site);
                    Scopes scopes = new Scopes(searchContext);
                    Scope newScope = scopes.AllScopes.Create("CustomScope", "Scope Description", new Uri(site.Url), true, "Your Custom Serach aspx Page", ScopeCompilationType.AlwaysCompile);
                    newScope.Rules.CreateUrlRule(ScopeRuleFilterBehavior.Include, UrlScopeRuleType.Folder, "Folder Name");                  
                    newScope.Update();
                    ScopeDisplayGroup group = scopes.GetDisplayGroup(new Uri(site.Url), "Search Dropdown");
                    group.Add(newScope);
                    group.Update();
                }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消