From d3eec153d89d9dd3c5e84f5061c67323ea6fd72f Mon Sep 17 00:00:00 2001 From: da3dsoul Date: Tue, 31 Jul 2018 20:08:53 -0400 Subject: [PATCH] Fix Searching --- Shoko.Commons | 2 +- .../Helpers/GroupSearchFilterHelper.cs | 106 +++++------------- 2 files changed, 28 insertions(+), 80 deletions(-) diff --git a/Shoko.Commons b/Shoko.Commons index f5bec3ef..6604f384 160000 --- a/Shoko.Commons +++ b/Shoko.Commons @@ -1 +1 @@ -Subproject commit f5bec3ef336ac3cf88e047dc78b079a42cec0eb4 +Subproject commit 6604f38452a04c2000b319d67346973ec2520ae8 diff --git a/Shoko.Desktop/ViewModel/Helpers/GroupSearchFilterHelper.cs b/Shoko.Desktop/ViewModel/Helpers/GroupSearchFilterHelper.cs index 0b829022..798e2588 100644 --- a/Shoko.Desktop/ViewModel/Helpers/GroupSearchFilterHelper.cs +++ b/Shoko.Desktop/ViewModel/Helpers/GroupSearchFilterHelper.cs @@ -13,8 +13,10 @@ public class GroupSearchFilterHelper { public static bool EvaluateGroupTextSearch(VM_AnimeGroup_User grp, string filterText) { - if (string.IsNullOrEmpty(filterText) || grp == null) - return true; + if (string.IsNullOrEmpty(filterText)) return true; + + if (grp == null) + return false; // do this so that when viewing sub groups they don't get filtered if (grp.AnimeGroupParentID.HasValue) return true; @@ -22,91 +24,48 @@ public static bool EvaluateGroupTextSearch(VM_AnimeGroup_User grp, string filter // get all possible names for the group // search the group name - int index = grp.GroupName.IndexOf(filterText, 0, StringComparison.InvariantCultureIgnoreCase); - if (index > -1) return true; + if (grp.GroupName.FuzzyMatches(filterText)) return true; // search the sort name - index = grp.SortName.IndexOf(filterText, 0, StringComparison.InvariantCultureIgnoreCase); - if (index > -1) return true; + if (grp.SortName.FuzzyMatches(filterText)) return true; // search the titles (romaji name, english names) etc from anidb - if (grp.Stat_AllTitles != null && grp.Stat_AllTitles.Count > 0) - { - if (grp.Stat_AllTitles.SubContains(filterText)) - return true; - - foreach (string title in grp.Stat_AllTitles) - { - if (string.IsNullOrEmpty(title)) continue; - if (!Misc.FuzzyMatches(title, filterText)) continue; - return true; - } - } - - // check the tags - if (grp.Stat_AllTags != null && grp.Stat_AllTags.Count > 0) - { - - if (grp.Stat_AllTags.Contains(filterText, StringComparer.InvariantCultureIgnoreCase)) - return true; - } - - // check the custom tags - if (grp.Stat_AllCustomTags != null && grp.Stat_AllCustomTags.Count > 0) - { - if (grp.Stat_AllCustomTags.Contains(filterText, StringComparer.InvariantCultureIgnoreCase)) - return true; - } + if (grp.AllAnimeSeries.Any(a => EvaluateSeriesTextSearch(a, filterText))) + return true; return false; } - public static bool EvaluateSeriesTextSearch(VM_AnimeSeries_User series, string filterText, SeriesSearchType searchType) + public static bool EvaluateSeriesTextSearch(VM_AnimeSeries_User series, string filterText, SeriesSearchType searchType = SeriesSearchType.Everything) { - if (string.IsNullOrEmpty(filterText) || series == null) - return true; + if (string.IsNullOrEmpty(filterText)) return true; + + if (series == null) return false; - if (!string.IsNullOrEmpty(series.SeriesNameOverride)) - { - int index = series.SeriesNameOverride.IndexOf(filterText, 0, StringComparison.InvariantCultureIgnoreCase); - if (index > -1) return true; - } + if (!string.IsNullOrEmpty(series.SeriesNameOverride) && series.SeriesNameOverride.FuzzyMatches(filterText)) + return true; return EvaluateAnimeTextSearch(series.AniDBAnime, filterText, searchType); } - public static bool EvaluateSeriesTextSearch(VM_AnimeSeries_User series, string filterText) - { - return EvaluateSeriesTextSearch(series, filterText, SeriesSearchType.Everything); - } - public static bool EvaluateAnimeTextSearch(CL_AniDB_AnimeDetailed anime, string filterText, SeriesSearchType searchType) { - if (string.IsNullOrEmpty(filterText) || anime == null) - return true; + if (string.IsNullOrEmpty(filterText)) return true; + + if (anime == null) return false; // search the romaji name, english names etc from anidb if (anime.AnimeTitles.Any(a => (a.Language.Equals("en") || a.Language.Equals("x-jat") || - a.Language.Equals(VM_ShokoServer.Instance.LanguagePreference)) && a.Title.Contains(filterText))) + a.Language.Equals(VM_ShokoServer.Instance.LanguagePreference)) && a.Title.FuzzyMatches(filterText))) return true; - foreach (string title in anime.AnimeTitles.Where(a => - a.Language.Equals("en") || a.Language.Equals("x-jat") || - a.Language.Equals(VM_ShokoServer.Instance.LanguagePreference)).Select(a => a.Title)) + // check the tags + if (searchType == SeriesSearchType.Everything && anime.Tags.Select(a => a.TagName).Any(a => a.FuzzyMatches(filterText))) { - if (string.IsNullOrEmpty(title)) continue; - if (!Misc.FuzzyMatches(title, filterText)) continue; return true; } - if (searchType == SeriesSearchType.Everything) - { - // check the tags - if (anime.Tags.Select(a => a.TagName).Contains(filterText, StringComparer.InvariantCultureIgnoreCase)) - return true; - } - return false; } @@ -115,40 +74,29 @@ public static bool EvaluateAnimeTextSearch(CL_AniDB_AnimeDetailed anime, string return EvaluateAnimeTextSearch(anime, filterText, SeriesSearchType.Everything); } - public static bool EvaluateAnimeTextSearch(VM_AniDB_Anime anime, string filterText, SeriesSearchType searchType) + public static bool EvaluateAnimeTextSearch(VM_AniDB_Anime anime, string filterText, SeriesSearchType searchType = SeriesSearchType.Everything) { - if (string.IsNullOrEmpty(filterText) || anime == null) - return true; + if (string.IsNullOrEmpty(filterText)) return true; + if (anime == null) return false; // search the romaji name, english names etc from anidb - if (anime.GetAllTitles().SubContains(filterText)) - return true; - if (anime.GetAllTitles() != null) { foreach (string title in anime.GetAllTitles()) { - if (string.IsNullOrEmpty(title)) continue; - if (!Misc.FuzzyMatches(title, filterText)) continue; - return true; + if (title.FuzzyMatches(filterText)) return true; } } - if (searchType == SeriesSearchType.Everything) + // check the tags + if (searchType == SeriesSearchType.Everything && anime.GetAllTags().Contains(filterText, StringComparer.InvariantCultureIgnoreCase)) { - // check the tags - if (anime.GetAllTags().Contains(filterText, StringComparer.InvariantCultureIgnoreCase)) - return true; + return true; } return false; } - public static bool EvaluateAnimeTextSearch(VM_AniDB_Anime anime, string filterText) - { - return EvaluateAnimeTextSearch(anime, filterText, SeriesSearchType.Everything); - } - public static bool EvaluateGroupFilter(VM_GroupFilter gf, VM_AnimeGroup_User grp) { return gf.EvaluateGroupFilter(grp);