mirror of
https://github.com/Readarr/Readarr
synced 2025-12-26 18:22:32 +01:00
New: Try matching with "Unabridged" removed from title
This commit is contained in:
parent
6325432a34
commit
bdcee8c7c1
3 changed files with 38 additions and 2 deletions
|
|
@ -163,6 +163,22 @@ public void test_add_string_empty_options_empty_value()
|
|||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void test_add_string_multiple_options_multiple_values_match()
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddString("string", new List<string> { "cat", "dog" }, new List<string> { "dog", "mouse" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 0.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void test_add_string_multiple_options_multiple_values_no_match()
|
||||
{
|
||||
var dist = new Distance();
|
||||
dist.AddString("string", new List<string> { "cat", "dog" }, new List<string> { "y", "z" });
|
||||
dist.Penalties.Should().BeEquivalentTo(new Dictionary<string, List<double>> { { "string", new List<double> { 1.0 } } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void test_distance()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -173,6 +173,22 @@ public void AddString(string key, List<string> values, string target)
|
|||
}
|
||||
}
|
||||
|
||||
public void AddString(string key, List<string> values, List<string> options)
|
||||
{
|
||||
if (!values.Any() && !options.Any())
|
||||
{
|
||||
Add(key, 0.0);
|
||||
}
|
||||
else if (!values.Any() || !options.Any())
|
||||
{
|
||||
Add(key, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Add(key, values.Min(v => options.Min(o => StringScore(v, o))));
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBool(string key, bool expr)
|
||||
{
|
||||
Add(key, expr ? 1.0 : 0.0);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ public static class DistanceCalculator
|
|||
|
||||
private static readonly RegexReplace StripSeriesRegex = new RegexReplace(@"\([^\)].+?\)$", string.Empty, RegexOptions.Compiled);
|
||||
|
||||
private static readonly RegexReplace CleanTitleCruft = new RegexReplace(@"\((?:unabridged)\)", string.Empty, RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
public static Distance BookDistance(List<LocalBook> localTracks, Edition edition)
|
||||
{
|
||||
var dist = new Distance();
|
||||
|
|
@ -68,8 +70,10 @@ public static Distance BookDistance(List<LocalBook> localTracks, Edition edition
|
|||
}
|
||||
}
|
||||
|
||||
dist.AddString("book", title, titleOptions);
|
||||
Logger.Trace("book: '{0}' vs '{1}'; {2}", title, titleOptions.ConcatToString("' or '"), dist.NormalizedDistance());
|
||||
var fileTitles = new[] { title, CleanTitleCruft.Replace(title) }.Distinct().ToList();
|
||||
|
||||
dist.AddString("book", fileTitles, titleOptions);
|
||||
Logger.Trace("book: '{0}' vs '{1}'; {2}", fileTitles.ConcatToString("' or '"), titleOptions.ConcatToString("' or '"), dist.NormalizedDistance());
|
||||
|
||||
var isbn = localTracks.MostCommon(x => x.FileTrackInfo.Isbn);
|
||||
if (isbn.IsNotNullOrWhiteSpace() && edition.Isbn13.IsNotNullOrWhiteSpace())
|
||||
|
|
|
|||
Loading…
Reference in a new issue