Skip to content

Commit

Permalink
Fixed: Sorting in Interactive search duplicates results
Browse files Browse the repository at this point in the history
Fixes #5760
Fixes #5765

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
Co-Authored-By: Taloth <Taloth@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 31, 2021
1 parent 539fcb9 commit a1db7a8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs
Expand Up @@ -56,9 +56,14 @@ public List<DownloadDecision> MovieSearch(int movieId, bool userInvokedSearch, b

public List<DownloadDecision> MovieSearch(Movie movie, bool userInvokedSearch, bool interactiveSearch)
{
var downloadDecisions = new List<DownloadDecision>();

var searchSpec = Get<MovieSearchCriteria>(movie, userInvokedSearch, interactiveSearch);

return Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
var decisions = Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
downloadDecisions.AddRange(decisions);

return DeDupeDecisions(downloadDecisions);
}

private TSpec Get<TSpec>(Movie movie, bool userInvokedSearch, bool interactiveSearch)
Expand Down Expand Up @@ -132,5 +137,11 @@ private List<DownloadDecision> Dispatch(Func<IIndexer, IEnumerable<ReleaseInfo>>

return _makeDownloadDecision.GetSearchDecision(reports, criteriaBase).ToList();
}

private List<DownloadDecision> DeDupeDecisions(List<DownloadDecision> decisions)
{
// De-dupe reports by guid so duplicate results aren't returned. Pick the one with the least rejections.
return decisions.GroupBy(d => d.RemoteMovie.Release.Guid).Select(d => d.OrderBy(v => v.Rejections.Count()).First()).ToList();
}
}
}

0 comments on commit a1db7a8

Please sign in to comment.