Files
mixtape/zero.Core/Database/Indexes/Pages_ByHierarchy.cs
T

51 lines
1.3 KiB
C#
Raw Normal View History

2020-05-20 11:19:43 +02:00
using Raven.Client.Documents.Indexes;
using System;
using System.Collections.Generic;
using System.Linq;
using zero.Core.Entities;
namespace zero.Core.Database.Indexes
{
2021-08-27 11:46:50 +02:00
public class Pages_ByHierarchy : ZeroIndex<Page, Pages_ByHierarchy.Result>
2020-05-20 11:19:43 +02:00
{
2021-05-04 17:23:52 +02:00
public class Result : ZeroIdEntity, IZeroDbConventions
2020-05-20 11:19:43 +02:00
{
public string Name { get; set; }
public List<PathResult> Path { get; set; } = new List<PathResult>();
2021-11-09 16:07:43 +01:00
public string[] PathIds { get; set; } = Array.Empty<string>();
2020-05-20 11:19:43 +02:00
}
public class PathResult
{
public string Id { get; set; }
public string Name { get; set; }
}
2021-08-27 11:46:50 +02:00
protected override void Create()
2020-05-20 11:19:43 +02:00
{
2021-11-09 16:07:43 +01:00
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()
});
2020-05-20 11:19:43 +02:00
StoreAllFields(FieldStorage.Yes);
2021-11-09 16:07:43 +01:00
Index("PathIds", FieldIndexing.Exact);
2020-05-20 11:19:43 +02:00
//Index(x => x.ChannelId, FieldIndexing.Exact);
}
}
}