From eb76dd5248988c8101d9414aef0215f01f81cf00 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 28 Jun 2021 22:02:09 -0400 Subject: [PATCH] Added searchEngine support in Newznab/Torznab caps Fixes #5849 Co-Authored-By: Taloth --- .../NewznabCapabilitiesProviderFixture.cs | 25 ++++++++++++++++++- .../Indexers/Newznab/NewznabCapabilities.cs | 4 +++ .../Newznab/NewznabCapabilitiesProvider.cs | 20 +++++++++++---- .../Newznab/NewznabRequestGenerator.cs | 23 ++++++++++++++++- 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs index ff9731ac4..847a22a81 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Xml; using FluentAssertions; using Moq; @@ -95,5 +95,28 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests result.Should().NotBeNull(); } + + [Test] + public void should_use_default_searchengine_if_missing() + { + GivenCapsResponse(_caps); + + var caps = Subject.GetCapabilities(_settings); + + caps.TextSearchEngine.Should().Be("sphinx"); + caps.MovieTextSearchEngine.Should().Be("sphinx"); + } + + [Test] + public void should_use_specified_searchengine() + { + GivenCapsResponse(_caps.Replace(" Categories { get; set; } public NewznabCapabilities() @@ -18,6 +20,8 @@ namespace NzbDrone.Core.Indexers.Newznab SupportedSearchParameters = new[] { "q" }; SupportedMovieSearchParameters = new[] { "q", "imdbid", "imdbtitle", "imdbyear" }; SupportsAggregateIdSearch = false; + TextSearchEngine = "sphinx"; // This should remain 'sphinx' for older newznab installs + MovieTextSearchEngine = "sphinx"; // This should remain 'sphinx' for older newznab installs Categories = new List(); } } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs index 51074704a..2da51815c 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs @@ -118,9 +118,14 @@ namespace NzbDrone.Core.Indexers.Newznab { capabilities.SupportedSearchParameters = null; } - else if (xmlBasicSearch.Attribute("supportedParams") != null) + else { - capabilities.SupportedSearchParameters = xmlBasicSearch.Attribute("supportedParams").Value.Split(','); + if (xmlBasicSearch.Attribute("supportedParams") != null) + { + capabilities.SupportedSearchParameters = xmlBasicSearch.Attribute("supportedParams").Value.Split(','); + } + + capabilities.TextSearchEngine = xmlBasicSearch.Attribute("searchEngine")?.Value ?? capabilities.TextSearchEngine; } var xmlMovieSearch = xmlSearching.Element("movie-search"); @@ -128,10 +133,15 @@ namespace NzbDrone.Core.Indexers.Newznab { capabilities.SupportedMovieSearchParameters = null; } - else if (xmlMovieSearch.Attribute("supportedParams") != null) + else { - capabilities.SupportedMovieSearchParameters = xmlMovieSearch.Attribute("supportedParams").Value.Split(','); - capabilities.SupportsAggregateIdSearch = true; + if (xmlMovieSearch.Attribute("supportedParams") != null) + { + capabilities.SupportedMovieSearchParameters = xmlMovieSearch.Attribute("supportedParams").Value.Split(','); + capabilities.SupportsAggregateIdSearch = true; + } + + capabilities.MovieTextSearchEngine = xmlMovieSearch.Attribute("searchEngine")?.Value ?? capabilities.MovieTextSearchEngine; } } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs index 7c302023d..a725a9756 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs @@ -65,6 +65,26 @@ namespace NzbDrone.Core.Indexers.Newznab } } + private string TextSearchEngine + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.TextSearchEngine; + } + } + + private string MovieTextSearchEngine + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.MovieTextSearchEngine; + } + } + public virtual IndexerPageableRequestChain GetRecentRequests() { var pageableRequests = new IndexerPageableRequestChain(); @@ -135,7 +155,8 @@ namespace NzbDrone.Core.Indexers.Newznab if (SupportsSearch) { chain.AddTier(); - foreach (var queryTitle in searchCriteria.QueryTitles) + var queryTitles = TextSearchEngine == "raw" ? searchCriteria.SceneTitles : searchCriteria.QueryTitles; + foreach (var queryTitle in queryTitles) { var searchQuery = queryTitle;