Create Managed Property for Search Service Application.

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();
                }
            }
        }




















 

Popular posts from this blog

Custom Form Base Login Web Part With Sharepoint 2010

Real World Branding with SharePoint 2010 Publishing Sites