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

45 lines
1.2 KiB
C#
Raw Normal View History

2020-09-02 15:46:54 +02:00
using Raven.Client.Documents.Indexes;
using System;
using System.Linq;
using zero.Core.Entities;
namespace zero.Core.Database.Indexes
{
2021-08-27 11:46:50 +02:00
public class Media_ByParent : ZeroMultiMapIndex<MediaListItem>
2020-09-02 15:46:54 +02:00
{
2021-08-27 11:46:50 +02:00
protected override void Create()
2020-09-02 15:46:54 +02:00
{
2021-05-04 17:23:52 +02:00
AddMap<MediaFolder>(items => items.Select(item => new MediaListItem
2020-09-02 15:46:54 +02:00
{
Id = item.Id,
ParentId = item.ParentId,
CreatedDate = item.CreatedDate,
IsFolder = true,
Name = item.Name,
Image = null,
2020-09-06 17:31:31 +02:00
Children = 0,
Size = 0,
IsShared = item.Blueprint != null,
AspectRatio = 0
2020-09-02 15:46:54 +02:00
}));
2021-05-04 17:23:52 +02:00
AddMap<Media>(items => items.Select(item => new MediaListItem
2020-09-02 15:46:54 +02:00
{
Id = item.Id,
ParentId = item.FolderId,
CreatedDate = item.CreatedDate,
IsFolder = false,
Name = item.Name,
Image = item.PreviewSource,
2020-09-06 17:31:31 +02:00
Children = 0,
Size = item.Size,
IsShared = item.Blueprint != null,
AspectRatio = item.ImageMeta != null ? (float)item.ImageMeta.Width / item.ImageMeta.Height : 0
2020-09-02 15:46:54 +02:00
}));
StoreAllFields(FieldStorage.Yes);
Index(x => x.ParentId, FieldIndexing.Exact);
}
}
}