Skip to content

Commit

Permalink
Fix Searching in Desktop.
Browse files Browse the repository at this point in the history
The sorting is unintuitive, but fixing it would require rewriting the entire search system, and possibly the MainList backend
  • Loading branch information
da3dsoul committed Oct 6, 2018
1 parent a6fee0d commit 498fbab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions Shoko.Desktop/ViewModel/Helpers/GroupSearchFilterHelper.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class GroupSearchFilterHelper


public static bool EvaluateGroupTextSearch(VM_AnimeGroup_User grp, string filterText) public static bool EvaluateGroupTextSearch(VM_AnimeGroup_User grp, string filterText)
{ {
filterText = filterText.Trim();
if (string.IsNullOrEmpty(filterText)) return true; if (string.IsNullOrEmpty(filterText)) return true;


if (grp == null) if (grp == null)
Expand All @@ -39,18 +40,20 @@ public static bool EvaluateGroupTextSearch(VM_AnimeGroup_User grp, string filter


/// <summary> /// <summary>
/// checks if a given string is actually just a number. optimized version provided by cazzar /// checks if a given string is actually just a number. optimized version provided by cazzar
/// even faster version from da3dsoul
/// </summary> /// </summary>
/// <param name="str">potential number to check</param> /// <param name="s">potential number to check</param>
/// <returns></returns> /// <returns></returns>
private static bool IsDigitsOnly(string s) => long.TryParse(s, out long _); private static bool IsDigitsOnly(string s) => s.All(c => c <= '9' && c >= '0');


public static bool EvaluateSeriesTextSearch(VM_AnimeSeries_User series, string filterText, SeriesSearchType searchType = SeriesSearchType.Everything) public static bool EvaluateSeriesTextSearch(VM_AnimeSeries_User series, string filterText, SeriesSearchType searchType = SeriesSearchType.TitleOnly)
{ {
filterText = filterText.Trim();
if (string.IsNullOrEmpty(filterText)) return true; if (string.IsNullOrEmpty(filterText)) return true;


if (series == null) return false; if (series == null) return false;


if (IsDigitsOnly((filterText))) if (IsDigitsOnly(filterText))
{ {
return (Convert.ToInt32(filterText) == series.AniDBAnime.AniDBAnime.AnimeID); return (Convert.ToInt32(filterText) == series.AniDBAnime.AniDBAnime.AnimeID);
} }
Expand All @@ -61,8 +64,9 @@ public static bool EvaluateSeriesTextSearch(VM_AnimeSeries_User series, string f
return EvaluateAnimeTextSearch(series.AniDBAnime, filterText, searchType); return EvaluateAnimeTextSearch(series.AniDBAnime, filterText, searchType);
} }


public static bool EvaluateAnimeTextSearch(CL_AniDB_AnimeDetailed anime, string filterText, SeriesSearchType searchType) public static bool EvaluateAnimeTextSearch(CL_AniDB_AnimeDetailed anime, string filterText, SeriesSearchType searchType = SeriesSearchType.TitleOnly)
{ {
filterText = filterText.Trim();
if (string.IsNullOrEmpty(filterText)) return true; if (string.IsNullOrEmpty(filterText)) return true;


if (anime == null) return false; if (anime == null) return false;
Expand All @@ -82,13 +86,9 @@ public static bool EvaluateAnimeTextSearch(CL_AniDB_AnimeDetailed anime, string
return false; return false;
} }


public static bool EvaluateAnimeTextSearch(CL_AniDB_AnimeDetailed anime, string filterText) public static bool EvaluateAnimeTextSearch(VM_AniDB_Anime anime, string filterText, SeriesSearchType searchType = SeriesSearchType.TitleOnly)
{
return EvaluateAnimeTextSearch(anime, filterText, SeriesSearchType.Everything);
}

public static bool EvaluateAnimeTextSearch(VM_AniDB_Anime anime, string filterText, SeriesSearchType searchType = SeriesSearchType.Everything)
{ {
filterText = filterText.Trim();
if (string.IsNullOrEmpty(filterText)) return true; if (string.IsNullOrEmpty(filterText)) return true;
if (anime == null) return false; if (anime == null) return false;


Expand Down
2 changes: 1 addition & 1 deletion Shoko.Desktop/ViewModel/VM_MainListHelper.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private bool SeriesSearchFilter(object obj)


if (SearchResultCount > 100) return false; if (SearchResultCount > 100) return false;


var passed = GroupSearchFilterHelper.EvaluateSeriesTextSearch(ser, SeriesSearchTextBox.Text.Replace("'", "`"), SerSearchType); var passed = GroupSearchFilterHelper.EvaluateSeriesTextSearch(ser, SeriesSearchTextBox.Text, SerSearchType);


if (passed) if (passed)
SearchResultCount++; SearchResultCount++;
Expand Down

0 comments on commit 498fbab

Please sign in to comment.