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_WithChildren : ZeroIndex<Page, zero_Pages_WithChildren.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 ParentId { get; set; }
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public string[] ChildrenIds { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Create()
|
|
|
|
|
{
|
|
|
|
|
Map = items => items.Where(x => x.ParentId != null).Select(item => new Result
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
ParentId = item.ParentId,
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
ChildrenIds = new string[] { }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Reduce = results => results.GroupBy(x => new { x.ParentId }).Select(group => new Result()
|
|
|
|
|
{
|
|
|
|
|
Id = group.Key.ParentId,
|
|
|
|
|
ParentId = group.Key.ParentId,
|
|
|
|
|
Name = String.Empty,
|
|
|
|
|
ChildrenIds = group.Select(x => x.Id).ToArray()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
StoreAllFields(FieldStorage.Yes);
|
|
|
|
|
//Index(x => x.ChannelId, FieldIndexing.Exact);
|
|
|
|
|
}
|
|
|
|
|
}
|