Suggest fetches three times as many candidates and reranks them in the API: what the user plays, finishes and likes moves up a few positions and what they dislike moves down, with Meilisearch relevance still the base order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package search
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTranslit(t *testing.T) {
|
|
assert.Equal(t, "kino", Translit("Кино"))
|
|
assert.Equal(t, "shchedrin", Translit("Щедрин"))
|
|
assert.Equal(t, "кино", Translit("Kino"))
|
|
assert.Equal(t, "щедрин", Translit("shchedrin"))
|
|
assert.Equal(t, "", Translit("1984"))
|
|
}
|
|
|
|
func TestSwitchLayout(t *testing.T) {
|
|
assert.Equal(t, "привет", SwitchLayout("ghbdtn"))
|
|
assert.Equal(t, "hello", SwitchLayout("руддщ"))
|
|
assert.Equal(t, "кино", SwitchLayout("rbyj"))
|
|
assert.Equal(t, "", SwitchLayout("123"))
|
|
}
|
|
|
|
func TestPersonalizeLiftsFamiliarAndSinksDisliked(t *testing.T) {
|
|
liked, disliked := uuid.New(), uuid.New()
|
|
other := []string{uuid.NewString(), uuid.NewString(), uuid.NewString()}
|
|
found := []string{other[0], disliked.String(), other[1], other[2], liked.String()}
|
|
aff := map[uuid.UUID]float64{liked: 30, disliked: -10}
|
|
|
|
got := personalize(found, aff, 3)
|
|
assert.Equal(t, []string{liked.String(), other[0], other[1]}, got)
|
|
assert.Equal(t, found[:2], personalize(found, nil, 2), "без вкуса — порядок релевантности")
|
|
}
|