Improved anime search
This commit is contained in:
parent
f25501ca7d
commit
49f67d3a49
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user