using Raven.Client.Documents.Indexes; namespace zero.Pages; public class zero_Pages_ByHierarchy : ZeroIndex { public class Result : ZeroIdEntity, ISupportsDbConventions { public string Name { get; set; } public List Path { get; set; } = new List(); public string[] PathIds { get; set; } = Array.Empty(); } public class PathResult { public string Id { get; set; } public string Name { get; set; } } protected override void Create() { Map = items => items .Select(item => new { Item = item, Path = Recurse(item, x => LoadDocument(x.ParentId)).Where(x => x != null && x.Id != null && x.Id != item.Id).Reverse() }) .Select(item => new Result { Id = item.Item.Id, Name = item.Item.Name, Path = item.Path.Select(current => new PathResult() { Id = current.Id, Name = current.Name }).ToList(), PathIds = item.Path.Select(current => current.Id).ToArray() }); StoreAllFields(FieldStorage.Yes); Index("PathIds", FieldIndexing.Exact); //Index(x => x.ChannelId, FieldIndexing.Exact); } }