From 80beea9bdb3da2ff41d281b59eb03a1d97b186c4 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 25 Jul 2021 22:58:31 -0400 Subject: [PATCH] Fixed: Don't return results with categories that were not searched --- .../IndexerSearch/NzbSearchService.cs | 17 ++++++++++++++++- src/NzbDrone.Core/Indexers/IndexerBase.cs | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs b/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs index 394fda350..2aeb7cf4c 100644 --- a/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs @@ -171,12 +171,27 @@ namespace NzbDrone.Core.IndexerSearch { var indexerReports = await searchAction(indexer); + var releases = indexerReports.Releases; + + //Filter results to only those in searched categories + if (criteriaBase.Categories.Length > 0) + { + var expandedQueryCats = ((IndexerDefinition)indexer.Definition).Capabilities.Categories.ExpandTorznabQueryCategories(criteriaBase.Categories); + + releases = releases.Where(result => result.Categories?.Any() != true || expandedQueryCats.Intersect(result.Categories.Select(c => c.Id)).Any()).ToList(); + + if (releases.Count != indexerReports.Releases.Count) + { + _logger.Trace("{0} {1} Releases which didn't contain search categories [{2}] were filtered", indexerReports.Releases.Count - releases.Count, indexer.Name, string.Join(", ", expandedQueryCats)); + } + } + foreach (var query in indexerReports.Queries) { _eventAggregator.PublishEvent(new IndexerQueryEvent(indexer.Definition.Id, criteriaBase, query.ElapsedTime, query.StatusCode == 200, query.Releases.Count())); } - return indexerReports.Releases; + return releases; } catch (Exception e) { diff --git a/src/NzbDrone.Core/Indexers/IndexerBase.cs b/src/NzbDrone.Core/Indexers/IndexerBase.cs index 7cec8fddc..2e10802a0 100644 --- a/src/NzbDrone.Core/Indexers/IndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/IndexerBase.cs @@ -97,6 +97,7 @@ namespace NzbDrone.Core.Indexers result.ForEach(c => { + //Set common props c.IndexerId = Definition.Id; c.Indexer = Definition.Name; c.DownloadProtocol = Protocol;