Permalink
Browse files

[C] Redo Search in API to Return More Useful Results

  • Loading branch information...
da3dsoul committed Aug 2, 2018
1 parent b856cf8 commit f0a1f556e394027e47a68675145da576b41f1221
Showing with 28 additions and 8 deletions.
  1. +28 −8 Shoko.Server/API/v2/Modules/Common.cs
@@ -2327,6 +2327,10 @@ internal static string SanitizeFuzzy(string value, bool replaceInvalid)
class SearchGrouping
{
public List<SVR_AnimeSeries> Series { get; set; }
public bool exact_match { get; set; }
public int distance { get; set; }
public int index { get; set; }
public string match { get; set; }
}
/// <summary>
@@ -2457,11 +2461,19 @@ class SearchGrouping
if (title2 == null) return -1;
return String.Compare(title1, title2, StringComparison.InvariantCultureIgnoreCase);
});
return Tuple.Create(a.Key, tempSeries);
var result = new SearchGrouping
{
Series = a.OrderBy(b => b.AirDate).ToList(),
exact_match = distLevenshtein[tempSeries[0]].Item1.exact_match,
distance = distLevenshtein[tempSeries[0]].Item1.distance,
index = distLevenshtein[tempSeries[0]].Item1.index,
match = distLevenshtein[tempSeries[0]].Item2
};
return result;
});
series = tempListToSort.OrderBy(a => distLevenshtein[a.Item2[0]].Item1.distance)
.SelectMany(a => a.Item2).ToDictionary(a => a, a => distLevenshtein[a].Item2);
series = tempListToSort.OrderBy(a => a.distance)
.SelectMany(a => a.Series).ToDictionary(a => a, a => distLevenshtein[a].Item2);
foreach (KeyValuePair<SVR_AnimeSeries, string> ser in series)
{
if (offset == 0)
@@ -2518,7 +2530,7 @@ class SearchGrouping
var distLevenshtein = new ConcurrentDictionary<SVR_AnimeSeries, Tuple<Misc.SearchInfo, string>>();
allSeries.ForAll(a => CheckTagsFuzzy(a, query, ref distLevenshtein, realLimit));
series = distLevenshtein.Keys.OrderBy(a => distLevenshtein[a].Item1)
series = distLevenshtein.Keys.OrderBy(a => distLevenshtein[a].Item1.distance)
.ThenBy(a => distLevenshtein[a].Item2.Length)
.ThenBy(a => a.Contract.AniDBAnime.AniDBAnime.MainTitle)
.ToDictionary(a => a, a => distLevenshtein[a].Item2);
@@ -2649,11 +2661,19 @@ class SearchGrouping
if (title2 == null) return -1;
return String.Compare(title1, title2, StringComparison.InvariantCultureIgnoreCase);
});
return Tuple.Create(a.Key, tempSeries);
var result = new SearchGrouping
{
Series = a.OrderBy(b => b.AirDate).ToList(),
exact_match = distLevenshtein[tempSeries[0]].Item1.exact_match,
distance = distLevenshtein[tempSeries[0]].Item1.distance,
index = distLevenshtein[tempSeries[0]].Item1.index,
match = distLevenshtein[tempSeries[0]].Item2
};
return result;
});
series = tempListToSort.OrderBy(a => distLevenshtein[a.Item2[0]].Item1.distance)
.SelectMany(a => a.Item2).ToDictionary(a => a, a => distLevenshtein[a].Item2);
series = tempListToSort.OrderBy(a => a.distance)
.SelectMany(a => a.Series).ToDictionary(a => a, a => distLevenshtein[a].Item2);
distLevenshtein = new ConcurrentDictionary<SVR_AnimeSeries, Tuple<Misc.SearchInfo, string>>();
@@ -2663,7 +2683,7 @@ class SearchGrouping
if (tag_limit > 0)
{
allSeries.ForAll(a => CheckTagsFuzzy(a, query, ref distLevenshtein, tag_limit));
series.AddRange(distLevenshtein.Keys.OrderBy(a => distLevenshtein[a].Item1)
series.AddRange(distLevenshtein.Keys.OrderBy(a => distLevenshtein[a].Item1.distance)
.ThenBy(a => distLevenshtein[a].Item2.Length)
.ThenBy(a => a.Contract.AniDBAnime.AniDBAnime.MainTitle)
.ToDictionary(a => a, a => distLevenshtein[a].Item2));

0 comments on commit f0a1f55

Please sign in to comment.