Files
mixtape/zero.Core/Pages/Indexes/zero_Pages_ByHierarchy.cs
T

46 lines
1.2 KiB
C#
Raw Normal View History

2021-11-19 16:11:12 +01:00
using Raven.Client.Documents.Indexes;
2021-11-20 13:52:28 +01:00
namespace zero.Pages;
2021-11-19 16:11:12 +01:00
2022-01-06 18:10:58 +01:00
public class zero_Pages_ByHierarchy : ZeroIndex<Page, zero_Pages_ByHierarchy.Result>
2021-11-19 16:11:12 +01:00
{
2021-12-02 13:43:04 +01:00
public class Result : ZeroIdEntity, ISupportsDbConventions
2021-11-19 16:11:12 +01:00
{
public string Name { get; set; }
public List<PathResult> Path { get; set; } = new List<PathResult>();
public string[] PathIds { get; set; } = Array.Empty<string>();
}
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<Page>(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);
}
}