KeywordContext Class

Entry point for the search keyword management functionality (e.g. search setting groups, best bets, synonyms, etc.).

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Search.Extended.Administration.KeywordContext

Namespace:  Microsoft.SharePoint.Search.Extended.Administration
Assembly:  Microsoft.SharePoint.Search.Extended.Administration (in Microsoft.SharePoint.Search.Extended.Administration.dll)

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
Public NotInheritable Class KeywordContext _
    Implements IDisposable
'Usage
Dim instance As KeywordContext
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel = true)]
public sealed class KeywordContext : IDisposable

Examples

The following C# example uses the class to create a keyword and associate it with a synonym, a best bet, etc.

             using System;
             using Microsoft.SharePoint.Search.Extended.Administration;
             
             namespace Example
             {
                 class Program
                 {
                     static void Main(string[] args)
                     {
                         using (KeywordContext keywordContext = new KeywordContext())
                         {
                             // Get a search setting group by id.
                             var searchSettingGroup = keywordContext.SearchSettingGroups.GetSearchSettingGroup("Search setting group id");
            
                             // Create a keyword.
                             var keyword = searchSettingGroup.Keywords.AddKeyword("contoso");
            
                             // Create a synonym.
                             keyword.Synonyms.AddSynonym("contoso corporation");
            
                             // Create a best bet.
                             var bestbet = keyword.BestBet.AddBestBet("Contoso Home Page");
                             bestbet.Uri = new Uri("http://www.contoso.com");
            
                             // Create a document promotion.
                             var promotion = keyword.Promotions.AddPromotion("Promotion for developers");
                             promotion.BoostValue = 1000000;
                             promotion.PromotedItems.AddPromotedDocument("http://www.contoso.com/developers.html");
            
                             // Create a context that matches people that have a developer role.
                             var context = searchSettingGroup.Contexts.AddContext("Developer context");
                             context.ContextExpression.AddMatchExpression("role", "developer");
            
                             // Attach the context to the developer promotion.
                             promotion.AttachContext(context);
                         }
                     }
                 }
             }
             

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

KeywordContext Members

Microsoft.SharePoint.Search.Extended.Administration Namespace