Files
backend_v2/scripts/diag_brand/main.go
toom1996 f7ae917603 update
2026-09-17 22:51:00 +08:00

55 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
const dsn = "postgres://fashion:fashion_dev_2026@127.0.0.1:5432/fashion?sslmode=disable"
func main() {
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
// 1) brand 3100 的走秀档案数(only_with_articles 子查询依赖这个)
var artCount int64
db.Raw(`SELECT COUNT(*) FROM brand_runway WHERE is_deleted=0 AND brand_id=3100`).Scan(&artCount)
fmt.Printf("brand 3100 走秀档案数 = %d\n", artCount)
// 2) 复现后端完整搜索:only_with_articles=1 + keyword=猿人头
kw := "%猿人头%"
type Row struct {
ID uint32
Name string
NameEn string
NameCn string
}
var rows []Row
db.Raw(`
SELECT id, name, name_en, name_cn FROM brand
WHERE is_deleted=0
AND id IN (SELECT DISTINCT brand_id FROM brand_runway WHERE is_deleted=0)
AND (name_en LIKE ? OR name_cn LIKE ?)`,
kw, kw).Scan(&rows)
fmt.Printf("\n[搜索 keyword=猿人头, only_with_articles=1] 命中 %d 条:\n", len(rows))
for _, r := range rows {
fmt.Printf(" id=%d | name=%q | name_en=%q | name_cn=%q\n", r.ID, r.Name, r.NameEn, r.NameCn)
}
// 3) 对比:only_with_articles=0(不过滤档案)时的命中
var rows2 []Row
db.Raw(`
SELECT id, name, name_en, name_cn FROM brand
WHERE is_deleted=0
AND (name_en LIKE ? OR name_cn LIKE ?)`,
kw, kw).Scan(&rows2)
fmt.Printf("\n[搜索 keyword=猿人头, only_with_articles=0] 命中 %d 条:\n", len(rows2))
for _, r := range rows2 {
fmt.Printf(" id=%d | name=%q | name_en=%q | name_cn=%q\n", r.ID, r.Name, r.NameEn, r.NameCn)
}
}