Permalink
Browse files

Fix Searching in Desktop.

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 498fbabd9791ea82f5b074e602f30b09ab844031
@@ -14,6 +14,7 @@ public class GroupSearchFilterHelper

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

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

/// <summary>
/// checks if a given string is actually just a number. optimized version provided by cazzar
/// even faster version from da3dsoul
/// </summary>
/// <param name="str">potential number to check</param>
/// <param name="s">potential number to check</param>
/// <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 (series == null) return false;

if (IsDigitsOnly((filterText)))
if (IsDigitsOnly(filterText))
{
return (Convert.ToInt32(filterText) == series.AniDBAnime.AniDBAnime.AnimeID);
}
@@ -61,8 +64,9 @@ public static bool EvaluateSeriesTextSearch(VM_AnimeSeries_User series, string f
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 (anime == null) return false;
@@ -82,13 +86,9 @@ public static bool EvaluateAnimeTextSearch(CL_AniDB_AnimeDetailed anime, string
return false;
}

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

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

@@ -317,7 +317,7 @@ private bool SeriesSearchFilter(object obj)

if (SearchResultCount > 100) return false;

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

if (passed)
SearchResultCount++;

0 comments on commit 498fbab

Please sign in to comment.