public override IEnumerable <Item> GetSourceItems() { // RootPath and IncludedContentTypes are required // If these are not set, return an empty Enumerable if (ID.IsNullOrEmpty(RootPath) || IncludedContentTypes.Any() == false) { return(Enumerable.Empty <Item>()); } using ( var searcher = ContentSearchManager.GetIndex(string.Format("sitecore_{0}_index", Sitecore.Context.Database.Name)) .CreateSearchContext()) { var query = PredicateBuilder.True <CustomSearchResultItem>(); // Root Path query = query.And(i => i.Paths.Contains(RootPath)); // Included Content Types var contentTypesQuery = PredicateBuilder.False <CustomSearchResultItem>(); foreach (var ct in IncludedContentTypes) { var id = ct; contentTypesQuery = contentTypesQuery.Or(i => i.TemplateId == id); } query = query.And(contentTypesQuery); // Tags var tagsQuery = PredicateBuilder.True <CustomSearchResultItem>(); foreach (var tag in Tags) { var id = tag; tagsQuery = tagsQuery.And(i => i.Links.Contains(id)); } query = query.And(tagsQuery); // results var maximumItemsInFeed = int.Parse(Settings.GetSetting("Feeds.MaximumItemsInFeed", "50")); var results = searcher.GetQueryable <CustomSearchResultItem>() .Where(query) .Take(maximumItemsInFeed) .GetResults() .Hits .Select(i => i.Document.GetItem()) .ToList(); return(results); } }
public override IEnumerable <Item> GetSourceItems() { if (ID.IsNullOrEmpty(RootPath) || IncludedContentTypes.Any() == false) { return(Enumerable.Empty <Item>()); } string databaseName = Sitecore.Context.Database.Name; using (var searcher = ContentSearchManager.GetIndex(string.Format(INDEX, databaseName)).CreateSearchContext()) { var query = PredicateBuilder.True <CustomSearchResultItem>(); query = query.And(i => i.Paths.Contains(RootPath)); var contentTypesQuery = PredicateBuilder.False <CustomSearchResultItem>(); foreach (var ct in IncludedContentTypes) { var id = ct; contentTypesQuery = contentTypesQuery.Or(i => i.TemplateId == id); } query = query.And(contentTypesQuery); var from = DateTime.Today.AddMonths(-RecencyMonths); query = query.And(x => x.CreatedDate.Between(from, DateTime.Today, Inclusion.Both)); var tagsQuery = PredicateBuilder.True <CustomSearchResultItem>(); foreach (var tag in Tags) { var id = tag; tagsQuery = tagsQuery.And(i => i.PrimaryTag.Contains(id)); } query = query.And(tagsQuery); var results = searcher.GetQueryable <CustomSearchResultItem>() .Where(query) .Take(MaximumItemsInFeed) .GetResults() .Hits .Select(i => i.Document.GetItem()) .ToList(); return(results); } }
public bool AllowedContent(IContentType contentType) { if (ExcludedContentTypes.Any()) { if (ExcludedContentTypes.Contains(contentType.Alias) || contentType.CompositionAliases().Any(ExcludedContentTypes.Contains)) { return(false); } } if (IncludedContentTypes.Any()) { if (IncludedContentTypes.Contains(contentType.Alias) || contentType.CompositionAliases().Any(IncludedContentTypes.Contains)) { return(true); } return(false); } return(true); }