Improved anime search

This commit is contained in:
Eduard Urbach 2019-08-27 16:04:09 +09:00
parent f25501ca7d
commit 49f67d3a49
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
3 changed files with 7 additions and 2 deletions

View File

@ -24,6 +24,10 @@ func Anime(originalTerm string, maxLength int) []*arn.Anime {
add := func(anime *arn.Anime, similarity float64) {
similarity += float64(anime.Popularity.Total()) * popularityDamping
if anime.Type != "tv" && anime.Type != "movie" {
similarity -= 0.3
}
results = append(results, &Result{
obj: anime,
similarity: similarity,

View File

@ -34,13 +34,14 @@ var tests = map[string]string{
"fate night": "74y2cFiiR", // Fate/stay night
"stay night": "74y2cFiiR", // Fate/stay night
"re zero": "Un9XpFimg", // Re:Zero kara Hajimeru Isekai Seikatsu
"slime": "VhRKhKimR", // Tensei shitara Slime Datta Ken
}
func TestAnimeSearch(t *testing.T) {
for term, expectedAnimeID := range tests {
results := search.Anime(term, 1)
assert.Equal(t, len(results), 1)
assert.Equal(t, expectedAnimeID, results[0].ID)
assert.Equal(t, results[0].ID, expectedAnimeID)
}
}

View File

@ -49,7 +49,7 @@ func AdvancedStringSimilarity(a string, b string) float64 {
s += 0.6
if strings.HasPrefix(b, a) {
s += 5.0
s += 0.4
}
}