Fixed: Add series searching improvements
This commit is contained in:
parent
2efed23450
commit
e3893083bc
|
@ -0,0 +1,71 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.MetadataSource;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.MetadataSourceTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class TraktSearchSeriesComparerFixture : CoreTest
|
||||||
|
{
|
||||||
|
private List<Series> _series;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_series = new List<Series>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithSeries(string title)
|
||||||
|
{
|
||||||
|
_series.Add(new Series { Title = title });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_prefer_the_walking_dead_over_talking_dead_when_searching_for_the_walking_dead()
|
||||||
|
{
|
||||||
|
WithSeries("Talking Dead");
|
||||||
|
WithSeries("The Walking Dead");
|
||||||
|
|
||||||
|
_series.Sort(new TraktSearchSeriesComparer("the walking dead"));
|
||||||
|
|
||||||
|
_series.First().Title.Should().Be("The Walking Dead");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_prefer_the_walking_dead_over_talking_dead_when_searching_for_walking_dead()
|
||||||
|
{
|
||||||
|
WithSeries("Talking Dead");
|
||||||
|
WithSeries("The Walking Dead");
|
||||||
|
|
||||||
|
_series.Sort(new TraktSearchSeriesComparer("walking dead"));
|
||||||
|
|
||||||
|
_series.First().Title.Should().Be("The Walking Dead");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_prefer_blacklist_over_the_blacklist_when_searching_for_blacklist()
|
||||||
|
{
|
||||||
|
WithSeries("The Blacklist");
|
||||||
|
WithSeries("Blacklist");
|
||||||
|
|
||||||
|
_series.Sort(new TraktSearchSeriesComparer("blacklist"));
|
||||||
|
|
||||||
|
_series.First().Title.Should().Be("Blacklist");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_prefer_the_blacklist_over_blacklist_when_searching_for_the_blacklist()
|
||||||
|
{
|
||||||
|
WithSeries("Blacklist");
|
||||||
|
WithSeries("The Blacklist");
|
||||||
|
|
||||||
|
_series.Sort(new TraktSearchSeriesComparer("the blacklist"));
|
||||||
|
|
||||||
|
_series.First().Title.Should().Be("The Blacklist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -225,6 +225,7 @@
|
||||||
<Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecificationFixture.cs" />
|
<Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecificationFixture.cs" />
|
||||||
<Compile Include="MediaFiles\ImportApprovedEpisodesFixture.cs" />
|
<Compile Include="MediaFiles\ImportApprovedEpisodesFixture.cs" />
|
||||||
<Compile Include="MediaFiles\MediaFileRepositoryFixture.cs" />
|
<Compile Include="MediaFiles\MediaFileRepositoryFixture.cs" />
|
||||||
|
<Compile Include="MetadataSourceTests\TraktSearchSeriesComparerFixture.cs" />
|
||||||
<Compile Include="ParserTests\MiniSeriesEpisodeParserFixture.cs" />
|
<Compile Include="ParserTests\MiniSeriesEpisodeParserFixture.cs" />
|
||||||
<Compile Include="Qualities\RevisionComparableFixture.cs" />
|
<Compile Include="Qualities\RevisionComparableFixture.cs" />
|
||||||
<Compile Include="RemotePathMappingsTests\RemotePathMappingServiceFixture.cs" />
|
<Compile Include="RemotePathMappingsTests\RemotePathMappingServiceFixture.cs" />
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
{
|
{
|
||||||
private static readonly Regex RegexCleanPunctuation = new Regex("[-._:]", RegexOptions.Compiled);
|
private static readonly Regex RegexCleanPunctuation = new Regex("[-._:]", RegexOptions.Compiled);
|
||||||
private static readonly Regex RegexCleanCountryYearPostfix = new Regex(@"(?<=.+)( \([A-Z]{2}\)| \(\d{4}\)| \([A-Z]{2}\) \(\d{4}\))$", RegexOptions.Compiled);
|
private static readonly Regex RegexCleanCountryYearPostfix = new Regex(@"(?<=.+)( \([A-Z]{2}\)| \(\d{4}\)| \([A-Z]{2}\) \(\d{4}\))$", RegexOptions.Compiled);
|
||||||
|
private static readonly Regex ArticleRegex = new Regex(@"^(a|an|the)\s", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
|
||||||
public String SearchQuery { get; private set; }
|
public String SearchQuery { get; private set; }
|
||||||
|
|
||||||
|
@ -37,6 +38,14 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
// Prefer exact matches
|
// Prefer exact matches
|
||||||
|
result = Compare(x, y, s => CleanPunctuation(s.Title).Equals(CleanPunctuation(SearchQuery)));
|
||||||
|
if (result != 0) return -result;
|
||||||
|
|
||||||
|
// Remove Articles (a/an/the)
|
||||||
|
result = Compare(x, y, s => CleanArticles(s.Title).Equals(CleanArticles(SearchQuery)));
|
||||||
|
if (result != 0) return -result;
|
||||||
|
|
||||||
|
// Prefer close matches
|
||||||
result = Compare(x, y, s => CleanPunctuation(s.Title).LevenshteinDistance(CleanPunctuation(SearchQuery)) <= 1);
|
result = Compare(x, y, s => CleanPunctuation(s.Title).LevenshteinDistance(CleanPunctuation(SearchQuery)) <= 1);
|
||||||
if (result != 0) return -result;
|
if (result != 0) return -result;
|
||||||
|
|
||||||
|
@ -47,7 +56,7 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
// Compare prefix matches by year "(CSI: ..."
|
// Compare prefix matches by year "(CSI: ..."
|
||||||
result = CompareWithYear(x, y, s => s.Title.ToLowerInvariant().StartsWith(_searchQueryWithoutYear + ":"));
|
result = CompareWithYear(x, y, s => s.Title.ToLowerInvariant().StartsWith(_searchQueryWithoutYear + ":"));
|
||||||
if (result != 0) return -result;
|
if (result != 0) return -result;
|
||||||
|
|
||||||
return Compare(x, y, s => SearchQuery.LevenshteinDistanceClean(s.Title) - GetYearFactor(s));
|
return Compare(x, y, s => SearchQuery.LevenshteinDistanceClean(s.Title) - GetYearFactor(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +103,13 @@ namespace NzbDrone.Core.MetadataSource
|
||||||
return title.ToLowerInvariant();
|
return title.ToLowerInvariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String CleanArticles(String title)
|
||||||
|
{
|
||||||
|
title = ArticleRegex.Replace(title, "");
|
||||||
|
|
||||||
|
return title.Trim().ToLowerInvariant();
|
||||||
|
}
|
||||||
|
|
||||||
private Int32 GetYearFactor(Series series)
|
private Int32 GetYearFactor(Series series)
|
||||||
{
|
{
|
||||||
if (_year.HasValue)
|
if (_year.HasValue)
|
||||||
|
|
|
@ -167,6 +167,7 @@ define(
|
||||||
if (!this.isClosed) {
|
if (!this.isClosed) {
|
||||||
this.ui.searchBar.show();
|
this.ui.searchBar.show();
|
||||||
this.searchResult.show(new ErrorView({term: this.collection.term}));
|
this.searchResult.show(new ErrorView({term: this.collection.term}));
|
||||||
|
this.collection.term = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue