Function for Create Managed property for Search Service Application.

private static void CreateManagedProperty(Schema schema, string managedPropertyName, string crawledPropertyCategory, string crawledPropertyName)
{
if (!schema.AllManagedProperties.Contains(managedPropertyName))
{
Category category = schema.AllCategories[crawledPropertyCategory];
var crawledProps = category.QueryCrawledProperties(crawledPropertyName, 1, Guid.NewGuid(), String.Empty, true).Cast();
var crawledProp = crawledProps.FirstOrDefault();
if (crawledProp != null)
{
ManagedDataType managedPropertyType = GetManagedPropertyType(crawledProp);
ManagedProperty managedProperty = schema.AllManagedProperties.Create(managedPropertyName, managedPropertyType);
var mappings = managedProperty.GetMappings();
mappings.Add(new Mapping(crawledProp.Propset, crawledProp.Name, crawledProp.VariantType, managedProperty.PID));
managedProperty.SetMappings(mappings);
managedProperty.Update();
}
}
}

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: