Permalink
Browse files

Fix Searching

  • Loading branch information...
da3dsoul committed Aug 1, 2018
1 parent 07df60e commit d3eec153d89d9dd3c5e84f5061c67323ea6fd72f
Showing with 28 additions and 80 deletions.
  1. +1 −1 Shoko.Commons
  2. +27 −79 Shoko.Desktop/ViewModel/Helpers/GroupSearchFilterHelper.cs
@@ -13,100 +13,59 @@ 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;

// 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);

0 comments on commit d3eec15

Please sign in to comment.