thread-master/backend/internal/library/knowledge/patrol_search_test.go

59 lines
1.4 KiB
Go
Raw Permalink Normal View History

package knowledge
import (
"strings"
"testing"
)
func TestSelectBestSearchKeywordsRanksByIntentNotSavedOrder(t *testing.T) {
in := PatrolTagInput{
ProductName: "抗敏無香洗衣精",
ProductFeatures: "完全無香、抗敏、適合化療族群",
MatchTags: []string{"無香", "抗敏", "洗衣精"},
Questions: []string{"化療後想找不會刺激的洗衣精"},
Pillars: []string{"無香洗衣", "化療後衣物清潔"},
}
got := SelectBestSearchKeywords(
nil,
[]string{"洗衣機 推薦", "無香 洗衣精 請問"},
in,
nil,
4,
)
if len(got) == 0 {
t.Fatal("expected ranked keywords")
}
for _, kw := range got {
if strings.Contains(kw, "洗衣機") {
t.Fatalf("expected weak saved keyword to lose ranking, got %#v", got)
}
}
found := false
for _, kw := range got {
if strings.Contains(kw, "無香") || strings.Contains(kw, "化療") {
found = true
break
}
}
if !found {
t.Fatalf("expected intent-aligned keyword in %#v", got)
}
}
func TestSelectBestSearchKeywordsIncludesExplicitHint(t *testing.T) {
in := PatrolTagInput{
ProductName: "抗敏無香洗衣精",
MatchTags: []string{"無香", "洗衣精"},
}
got := SelectBestSearchKeywords(
[]string{"化療 無香 洗衣精"},
[]string{"洗衣機 推薦"},
in,
nil,
3,
)
if len(got) == 0 || got[0] != "化療 無香 洗衣精" {
t.Fatalf("expected explicit hint to rank first, got %#v", got)
}
}