protected ManagedProperty GetCurrentObject(object modelHost, ManagedPropertyDefinition definition, out ManagedPropertyCollection properties, out List <CrawledPropertyInfo> crawledProps) { if (modelHost is FarmModelHost) { var context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default); var searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy; var ssai = searchProxy.GetSearchServiceApplicationInfo(); var application = SearchService.Service.SearchApplications.GetValue <SearchServiceApplication>(ssai.SearchServiceApplicationId); SearchObjectOwner searchOwner = new SearchObjectOwner(SearchObjectLevel.Ssa); if (cachedCrawledProps == null) { cachedCrawledProps = application.GetAllCrawledProperties(string.Empty, string.Empty, 0, searchOwner); } crawledProps = cachedCrawledProps; var schema = new Schema(application); properties = schema.AllManagedProperties; return(properties.FirstOrDefault(p => p.Name.ToUpper() == definition.Name.ToUpper())); } throw new NotImplementedException(); }
protected ManagedProperty GetCurrentObject(object modelHost, ManagedPropertyDefinition definition, out ManagedPropertyCollection properties, out List<CrawledPropertyInfo> crawledProps) { if (modelHost is FarmModelHost) { var context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default); var searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy; var ssai = searchProxy.GetSearchServiceApplicationInfo(); var application = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(ssai.SearchServiceApplicationId); SearchObjectOwner searchOwner = new SearchObjectOwner(SearchObjectLevel.Ssa); if (cachedCrawledProps == null) cachedCrawledProps = application.GetAllCrawledProperties(string.Empty, string.Empty, 0, searchOwner); crawledProps = cachedCrawledProps; var schema = new Schema(application); properties = schema.AllManagedProperties; return properties.FirstOrDefault(p => p.Name.ToUpper() == definition.Name.ToUpper()); } throw new NotImplementedException(); }
public static ManagedProperty CreateManagedProperty(SPSite site, string name, string crawledName, ManagedDataType type, SearchCategory searchCategory = SearchCategory.SharePoint, bool searchable = true, bool refinable = true, bool retrievable = true, bool sortable = true, bool hasMultipleValues = false, bool safeForAnonymous = false, bool tokenNormalization = false) { // Get the default service context var context = SearchContext.GetContext(site); // Get the schema of our Search Service Application Schema schema = new Schema(context); if (schema.AllManagedProperties.SingleOrDefault(i => i.Name == name) != null) { Logger.Logger.Debug("SearchUtils.CreateManagedProperty", $"The property \"{name}\" already exists."); return(null); } var categoryName = Enum.GetName(typeof(SearchCategory), searchCategory).Replace("_", " "); Category category = schema.AllCategories.Single(i => i.Name == categoryName); CrawledProperty crawledProperty = category.GetAllCrawledProperties().SingleOrDefault(i => i.Name == crawledName); if (crawledProperty != null) { // Get all the managed properties ManagedPropertyCollection properties = schema.AllManagedProperties; // Add a new property ManagedProperty property = properties.Create(name, type); property.Searchable = searchable; property.Refinable = refinable; property.Retrievable = retrievable; property.Sortable = sortable; property.HasMultipleValues = hasMultipleValues; property.TokenNormalization = tokenNormalization; property.SafeForAnonymous = safeForAnonymous; // Get the current mappings MappingCollection mappings = property.GetMappings(); // Add a new mapping to a previously crawled field var myMapping = new Mapping(); myMapping.CrawledPropertyName = crawledProperty.Name; myMapping.CrawledPropset = crawledProperty.Propset; myMapping.ManagedPid = property.PID; // Add the mapping mappings.Add(myMapping); // Update the collection of mappings property.SetMappings(mappings); // Write the changes back property.Update(); return(property); } return(null); }
public SPManagedPropertyCollection(ManagedPropertyCollection propertyCollection) { _propertyCollection = propertyCollection; }