2022-12-07 14:05:11 +01:00
|
|
|
using Raven.Client.Documents;
|
|
|
|
|
using Raven.Client.Documents.Indexes;
|
|
|
|
|
|
2026-04-07 14:23:29 +02:00
|
|
|
namespace Finch.Raven;
|
2022-12-07 14:05:11 +01:00
|
|
|
|
2026-04-07 14:23:29 +02:00
|
|
|
public class FinchTreeHierarchyIndexResult : FinchIdEntity, ISupportsDbConventions
|
2022-12-07 14:05:11 +01:00
|
|
|
{
|
|
|
|
|
public List<string> Path { get; set; } = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 14:23:29 +02:00
|
|
|
public abstract class FinchTreeHierarchyIndex<T> : FinchIndex<T, FinchTreeHierarchyIndexResult> where T : FinchIdEntity, ISupportsTrees
|
2022-12-07 14:05:11 +01:00
|
|
|
{
|
|
|
|
|
protected override void Create()
|
|
|
|
|
{
|
2026-04-07 14:23:29 +02:00
|
|
|
Map = items => items.Select(item => new FinchTreeHierarchyIndexResult
|
2022-12-07 14:05:11 +01:00
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
Path = Recurse(item, x => LoadDocument<T>(x.ParentId))
|
|
|
|
|
.Where(x => x != null && x.Id != null && x.Id != item.Id)
|
|
|
|
|
.Reverse()
|
|
|
|
|
.Select(current => current.Id)
|
|
|
|
|
.ToList()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
StoreAllFields(FieldStorage.Yes);
|
|
|
|
|
//Index(x => x.ChannelId, FieldIndexing.Exact);
|
|
|
|
|
}
|
|
|
|
|
}
|