internal static PublishedContentSet<IPublishedContent> ConvertSearchResultToPublishedContent(this IEnumerable<SearchResult> results, ContextualPublishedCache cache) { //TODO: The search result has already returned a result which SHOULD include all of the data to create an IPublishedContent, // however this is currently not the case: // http://examine.codeplex.com/workitem/10350 var list = new List<IPublishedContent>(); var set = new PublishedContentSet<IPublishedContent>(list); foreach (var result in results.OrderByDescending(x => x.Score)) { var content = cache.GetById(result.Id); if (content == null) continue; // skip if this doesn't exist in the cache // need to extend the content as we're going to add a property to it, // and we should not ever do it to the content we get from the cache, // precisely because it is cached and shared by all requests. // but we cannot wrap it because we need to respect the type that was // returned by the cache, in case the cache can create real types. // so we have to ask it to please extend itself. list.Add(content); var extend = set.MapContent(content); var property = new PropertyResult("examineScore", result.Score, Guid.Empty, PropertyResultType.CustomProperty); extend.AddProperty(property); } return set; }
public PublishedEmbeddedContent(IUserService userService, EmbeddedContentItem item, PublishedContentType contentType, PublishedContentSet <IPublishedContent> contentSet, int sortOrder, bool isPreview) { Name = item.Name; Key = item.Key; UpdateDate = item.UpdateDate; CreateDate = item.CreateDate; CreatorId = item.CreatorId; WriterId = item.WriterId; IsDraft = isPreview; SortOrder = sortOrder; ContentType = contentType; ContentSet = contentSet; _writerName = new Lazy <string>(() => userService.GetByProviderKey(WriterId).Name); _creatorName = new Lazy <string>(() => userService.GetByProviderKey(CreatorId).Name); _properties = (from property in item.Properties let propType = contentType.GetPropertyType(property.Key) where propType != null select new PublishedEmbeddedContentProperty(propType, property.Value, isPreview) ).ToList <IPublishedProperty>(); }
internal static PublishedContentSet <IPublishedContent> ConvertSearchResultToPublishedContent(this IEnumerable <SearchResult> results, ContextualPublishedCache cache) { //TODO: The search result has already returned a result which SHOULD include all of the data to create an IPublishedContent, // however this is currently not the case: // http://examine.codeplex.com/workitem/10350 var list = new List <IPublishedContent>(); var set = new PublishedContentSet <IPublishedContent>(list); foreach (var result in results.OrderByDescending(x => x.Score)) { var content = cache.GetById(result.Id); if (content == null) { continue; // skip if this doesn't exist in the cache } // need to extend the content as we're going to add a property to it, // and we should not ever do it to the content we get from the cache, // precisely because it is cached and shared by all requests. // but we cannot wrap it because we need to respect the type that was // returned by the cache, in case the cache can create real types. // so we have to ask it to please extend itself. list.Add(content); var extend = set.MapContent(content); var property = new PropertyResult("examineScore", result.Score, Guid.Empty, PropertyResultType.CustomProperty); extend.AddProperty(property); } return(set); }
public DynamicPublishedContentList(IEnumerable <DynamicPublishedContent> items) { _content = items.Select(x => x.PublishedContent).ToList(); _contentSet = new PublishedContentSet <IPublishedContent>(_content); Items = _contentSet.Select(x => new DynamicPublishedContent(x, this)).ToList(); }
public DynamicPublishedContentList() { _content = new List <IPublishedContent>(); _contentSet = new PublishedContentSet <IPublishedContent>(_content); Items = new List <DynamicPublishedContent>(); }
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) { EmbeddedContentConfig config = GetConfig(propertyType.DataTypeId); using (_profilingLogger.DebugDuration <EmbeddedContentValueConverter>($"ConvertSourceToObject({propertyType.PropertyTypeAlias})")) { if (source == null) { if (config.MaxItems == 1) { return(null); } return(Enumerable.Empty <IPublishedContent>()); } ; var items = ((JArray)source).ToObject <EmbeddedContentItem[]>(); var result = new List <IPublishedContent>(items.Length); PublishedContentSet <IPublishedContent> contentSet = result.ToContentSet(); for (var i = 0; i < items.Length; i++) { EmbeddedContentItem item = items[i]; if (!item.Published) { continue; } if (config.DocumentTypes.FirstOrDefault(x => x.DocumentTypeAlias == item.ContentTypeAlias) == null) { continue; } PublishedContentType contentType = null; try { contentType = PublishedContentType.Get(PublishedItemType.Content, item.ContentTypeAlias); } catch (Exception ex) { _profilingLogger.Logger.Error <EmbeddedContentValueConverter>($"Error getting content type {item.ContentTypeAlias}.", ex); } if (contentType == null) { continue; } IPublishedContent content = new PublishedEmbeddedContent(_userService, item, contentType, contentSet, i, preview); if (_publishedContentModelFactory != null) { content = _publishedContentModelFactory.CreateModel(content); } result.Add(content); } if (config.MaxItems == 1) { return(result.FirstOrDefault()); } return(contentSet); } }