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<CrawledProperty>();
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();
}
}
}
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<CrawledProperty>();
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();
}
}
}
Comments
Post a Comment