c89cad6643
- Rename UI/prompt labels: "品牌主问题" → "优化关键词", "搜索问题" → "搜索词" - Add brand/competitor entity exclusion filter in question expansion (AI distill path) - Refactor combination question text normalization, remove manual question-mark appending - Update prompts to emphasize commercial-intent search queries over editorial phrasing - Sync prompt changes across server/configs, deploy, and k3s configs - Update i18n, frontend views (BrandQuestionCreate, TemplateWizard), and test fixtures Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
71 lines
2.7 KiB
Go
71 lines
2.7 KiB
Go
package app
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestQuestionCombinationRegionTermsFromIPRegion(t *testing.T) {
|
|
got := questionCombinationRegionTermsFromIPRegion("中国|0|安徽省|合肥市|电信")
|
|
want := []string{"合肥", "华东"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("region terms = %#v, want %#v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestBuildQuestionCombinationFillFallback(t *testing.T) {
|
|
description := "GEO 与 AI 搜索优化平台"
|
|
got := buildQuestionCombinationFillFallback(&questionBrandContext{
|
|
BrandName: "GeoRankly",
|
|
Description: &description,
|
|
}, []string{"上海", "华东"}, QuestionCombinationFillRequest{})
|
|
|
|
if !reflect.DeepEqual(got.Region, []string{"上海", "华东"}) {
|
|
t.Fatalf("region = %#v", got.Region)
|
|
}
|
|
wantPrefix := []string{"性价比高的", "口碑好的", "专业的", "靠谱的"}
|
|
if !reflect.DeepEqual(got.Prefix, wantPrefix) {
|
|
t.Fatalf("prefix fallback = %#v, want %#v", got.Prefix, wantPrefix)
|
|
}
|
|
wantCore := []string{"品牌词", "AI搜索", "获客", "中小企业"}
|
|
if !reflect.DeepEqual(got.Core, wantCore) {
|
|
t.Fatalf("core fallback = %#v, want %#v", got.Core, wantCore)
|
|
}
|
|
wantIndustry := []string{"GEO优化", "AI搜索优化", "品牌推广", "搜索营销"}
|
|
if !reflect.DeepEqual(got.Industry, wantIndustry) {
|
|
t.Fatalf("industry fallback = %#v, want %#v", got.Industry, wantIndustry)
|
|
}
|
|
if len(got.Prefix) != 4 || len(got.Industry) != 4 || len(got.Suffix) != 4 {
|
|
t.Fatalf("expected four hot terms for non-region columns, got %#v", got)
|
|
}
|
|
wantSuffix := []string{"哪家好", "怎么选", "推荐", "避坑"}
|
|
if !reflect.DeepEqual(got.Suffix, wantSuffix) {
|
|
t.Fatalf("suffix fallback = %#v, want %#v", got.Suffix, wantSuffix)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeQuestionTextRemovesPunctuation(t *testing.T) {
|
|
got := normalizeQuestionText(" 合肥全屋定制哪家好? ")
|
|
if got != "合肥全屋定制哪家好" {
|
|
t.Fatalf("normalizeQuestionText() = %q, want %q", got, "合肥全屋定制哪家好")
|
|
}
|
|
}
|
|
|
|
func TestCompactQuestionCombinationTermsRemovesPunctuation(t *testing.T) {
|
|
got := compactQuestionCombinationTerms([]string{"官网?", "怎么选?", "推荐!", "对比"}, 4)
|
|
want := []string{"官网", "怎么选", "推荐", "对比"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("compactQuestionCombinationTerms() = %#v, want %#v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestQuestionContainsExcludedEntityMatchesCompanyShortName(t *testing.T) {
|
|
brandName := "安徽海翔家居用品销售有限公司"
|
|
if !questionContainsExcludedEntity("安徽海翔家居全屋定制口碑怎么样", brandName, nil) {
|
|
t.Fatal("expected candidate containing company short name to be excluded")
|
|
}
|
|
if questionContainsExcludedEntity("合肥全屋定制哪家好", brandName, nil) {
|
|
t.Fatal("expected generic user search term to be allowed")
|
|
}
|
|
}
|