From 6c2cebf6cb9b9cd4b8de8af39fc8b6301c5366b2 Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Thu, 31 Oct 2024 14:13:08 +0100 Subject: [PATCH] fix: search all group names --- Shoko.Server/Filters/FilterExtensions.cs | 5 +++-- Shoko.Server/Models/SVR_AnimeGroup.cs | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Shoko.Server/Filters/FilterExtensions.cs b/Shoko.Server/Filters/FilterExtensions.cs index fe49da093..faf809cb0 100644 --- a/Shoko.Server/Filters/FilterExtensions.cs +++ b/Shoko.Server/Filters/FilterExtensions.cs @@ -33,8 +33,7 @@ public static Filterable ToFilterable(this SVR_AnimeSeries series) NamesDelegate = () => { var titles = series.Titles.Select(t => t.Title).ToHashSet(); - var group = series.AnimeGroup; - if (group is not null) + foreach (var group in series.AllGroupsAbove) titles.Add(group.GroupName); return titles; @@ -180,6 +179,8 @@ public static Filterable ToFilterable(this SVR_AnimeGroup group) NamesDelegate = () => { var result = new HashSet() { group.GroupName }; + foreach (var grp in group.AllGroupsAbove) + result.Add(grp.GroupName); result.UnionWith(series.SelectMany(a => a.Titles.Select(t => t.Title))); return result; }, diff --git a/Shoko.Server/Models/SVR_AnimeGroup.cs b/Shoko.Server/Models/SVR_AnimeGroup.cs index 6109dd13c..f677b5223 100644 --- a/Shoko.Server/Models/SVR_AnimeGroup.cs +++ b/Shoko.Server/Models/SVR_AnimeGroup.cs @@ -33,6 +33,30 @@ public string SortName public SVR_AnimeGroup? Parent => AnimeGroupParentID.HasValue ? RepoFactory.AnimeGroup.GetByID(AnimeGroupParentID.Value) : null; + public List AllGroupsAbove + { + get + { + var allGroupsAbove = new List(); + var groupID = AnimeGroupParentID; + while (groupID.HasValue && groupID.Value != 0) + { + var grp = RepoFactory.AnimeGroup.GetByID(groupID.Value); + if (grp != null) + { + allGroupsAbove.Add(grp); + groupID = grp.AnimeGroupParentID; + } + else + { + groupID = 0; + } + } + + return allGroupsAbove; + } + } + public List Anime => RepoFactory.AnimeSeries.GetByGroupID(AnimeGroupID).Select(s => s.AniDB_Anime).WhereNotNull().ToList();