diff --git a/src/UmbracoExamine/UmbracoContentIndexer.cs b/src/UmbracoExamine/UmbracoContentIndexer.cs index 478f4a23fc..aa70162b31 100644 --- a/src/UmbracoExamine/UmbracoContentIndexer.cs +++ b/src/UmbracoExamine/UmbracoContentIndexer.cs @@ -32,6 +32,7 @@ namespace UmbracoExamine private readonly IDataTypeService _dataTypeService; private readonly IUserService _userService; private readonly IContentTypeService _contentTypeService; + private readonly EntityXmlSerializer _serializer = new EntityXmlSerializer(); #region Constructors @@ -142,12 +143,10 @@ namespace UmbracoExamine _userService = userService; _contentTypeService = contentTypeService; } - + #endregion - #region Constants & Fields - - + #region Constants & Fields /// /// Used to store the path of a content object @@ -382,6 +381,9 @@ namespace UmbracoExamine } IContent[] content; + //used to track non-published entities so we can determine what items are implicitly not published + var notPublished = new HashSet(); + do { long total; @@ -398,8 +400,9 @@ namespace UmbracoExamine _publishedQuery = Query.Builder.Where(x => x.Published == true); } - //add the published filter - descendants = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total, "Path", Direction.Ascending, true, _publishedQuery); + //get all paged records but order by level ascending, we need to do this because we need to track which nodes are not published so that we can determine + // which descendent nodes are implicitly not published + descendants = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total, "level", Direction.Ascending, true, (string)null); } //if specific types are declared we need to post filter them @@ -412,7 +415,7 @@ namespace UmbracoExamine { content = descendants.ToArray(); } - AddNodesToIndex(GetSerializedContent(content), type); + AddNodesToIndex(GetSerializedContent(content, notPublished).WhereNotNull(), type); pageIndex++; } while (content.Length == pageSize); @@ -468,12 +471,28 @@ namespace UmbracoExamine } } - private IEnumerable GetSerializedContent(IEnumerable content) - { - var serializer = new EntityXmlSerializer(); + private IEnumerable GetSerializedContent(IEnumerable content, ISet notPublished) + { foreach (var c in content) { - var xml = serializer.Serialize( + if (SupportUnpublishedContent == false) + { + //if we don't support published content and this is not published then track it and return null + if (c.Published == false) + { + notPublished.Add(c.Path); + yield return null; + } + + //if we don't support published content, check if this content item exists underneath any already tracked + //unpublished content and if so return null; + if (notPublished.Any(path => c.Path.StartsWith(string.Format("{0},", path)))) + { + yield return null; + } + } + + var xml = _serializer.Serialize( _contentService, _dataTypeService, _userService,