Don't allow single character prefixes to produce a match

master
Nick Krichevsky 2021-08-25 01:15:28 -04:00
parent 714f75028c
commit 2f4695510a
3 changed files with 17 additions and 1 deletions

View File

@ -18,7 +18,9 @@ func FindBestMatch(candidate string, index []string) (string, error) {
haveCommonPrefix := []string{}
for _, indexEntry := range index {
prefix := getLongestCommonPrefix(candidate, indexEntry)
if len(prefix) > 0 {
// Single character prefixes aren't that helpful.
// I don't want to get into threshold territory by playing with a number higher than this, though
if len(prefix) > 1 {
haveCommonPrefix = append(haveCommonPrefix, indexEntry)
}
}

View File

@ -71,6 +71,13 @@ func TestFindBestMatch(t *testing.T) {
expectedMatch: "",
expectedError: ErrNoMatches,
},
{
// This has the common prefix of "s" but we don't actually really care about a prefix like that
candidate: "super-weird",
index: []string{"something-odd", "nothing"},
expectedMatch: "",
expectedError: ErrNoMatches,
},
}
for _, test := range tt {

View File

@ -39,6 +39,13 @@ func TestFindBestFolder(t *testing.T) {
"",
match.ErrNoMatches,
},
{
"Does not use single-character prefixes as a reference",
"SpongeBob.SquarePants.S03.iT.WEB-DL.AAC2.0.H.264-NOGR",
[]string{"The-Good-Place", "Stranger-Things", "Brooklyn-Nine-Nine", "The-IT-Crowd"},
"",
match.ErrNoMatches,
},
}
for _, test := range table {