Skip to main content

TrendSonar修改页面分类菜单的方法,例如把 “文娱体育” 改为 “智慧灯杆”

这就是把上一轮的原因结论落成修复动作。方法分三步(配置、存量数据、缓存),核心是两个数据源都要改。先重读可视化规范,然后给你方法和示意图。

修复分类菜单的方法(以「文娱体育」→「智慧灯杆」为例)

核心思路:分类菜单有两条数据来源,要一起改——配置管"AI 以后怎么分",数据库存量管"页面上现在显示什么"。

<html style="margin:0;padding:0;"><div style="width:100%;box-sizing:border-box;font-family:'PingFang SC','Microsoft YaHei',Segoe UI,sans-serif;background:#f8fafc;padding:14px 8px;">
<svg viewBox="0 0 1000 480" width="100%" height="auto" xmlns="[http://www.w3.org/2000/svg](http://www.w3.org/2000/svg)">
  <defs>
    <marker id="ar" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
      <path d="M0,0 L10,5 L0,10 z" fill="#475569"/>
    </marker>
  </defs>
  <text x="500" y="30" text-anchor="middle" font-size="19" font-weight="700" fill="#0f172a">把「文娱体育」改成「智慧灯杆」——三步到位</text>

  <!-- 步骤1 -->
  <rect x="40" y="60" width="290" height="150" rx="12" fill="#ffffff" stroke="#10b981" stroke-width="1.5"/>
  <text x="60" y="90" font-size="15" font-weight="700" fill="#065f46">① 改配置</text>
  <text x="60" y="114" font-size="13.5" fill="#334155">data/config.yaml</text>
  <text x="60" y="134" font-size="13.5" fill="#334155">NEWS_CATEGORIES:</text>
  <text x="60" y="154" font-size="13.5" fill="#b91c1c">删「文娱体育」</text>
  <text x="60" y="174" font-size="13.5" fill="#065f46">加「智慧灯杆」</text>
  <text x="60" y="198" font-size="12.5" fill="#64748b">影响:新新闻 AI 分类候选、专题/报告页筛选</text>

  <line x1="330" y1="135" x2="370" y2="135" stroke="#475569" stroke-width="2" marker-end="url(#ar)"/>

  <!-- 步骤2 -->
  <rect x="375" y="60" width="290" height="150" rx="12" fill="#ffffff" stroke="#d97706" stroke-width="1.5"/>
  <text x="395" y="90" font-size="15" font-weight="700" fill="#92400e">② 改存量数据(关键)</text>
  <text x="395" y="116" font-size="13.5" fill="#334155">UPDATE news</text>
  <text x="395" y="136" font-size="13.5" fill="#334155">SET category='智慧灯杆'</text>
  <text x="395" y="156" font-size="13.5" fill="#334155">WHERE category='文娱体育';</text>
  <text x="395" y="178" font-size="12.5" fill="#64748b">当前影响 98 条存量新闻</text>
  <text x="395" y="198" font-size="12.5" fill="#64748b">影响:首页分类 Tab + 新闻角标</text>

  <line x1="665" y1="135" x2="705" y2="135" stroke="#475569" stroke-width="2" marker-end="url(#ar)"/>

  <!-- 步骤3 -->
  <rect x="710" y="60" width="250" height="150" rx="12" fill="#ffffff" stroke="#3b82f6" stroke-width="1.5"/>
  <text x="730" y="90" font-size="15" font-weight="700" fill="#1e40af">③ 重启清缓存</text>
  <text x="730" y="114" font-size="13.5" fill="#334155">docker compose</text>
  <text x="730" y="134" font-size="13.5" fill="#334155">restart trendsonar</text>
  <text x="730" y="160" font-size="12.5" fill="#64748b">清掉 /api/categories</text>
  <text x="730" y="178" font-size="12.5" fill="#64748b">内存缓存(短 TTL)</text>
  <text x="730" y="198" font-size="12.5" fill="#64748b">页面立即生效</text>

  <!-- 结果 -->
  <rect x="150" y="240" width="700" height="58" rx="10" fill="#ecfdf5" stroke="#10b981" stroke-width="1.5"/>
  <text x="500" y="266" text-anchor="middle" font-size="15" font-weight="700" fill="#065f46">完成后:首页 Tab、新闻角标、专题/报告页全部显示「智慧灯杆」</text>
  <text x="500" y="288" text-anchor="middle" font-size="13" fill="#475569">以后 AI 对新新闻分类时,「智慧灯杆」也是合法候选分类</text>

  <!-- 可选 -->
  <rect x="150" y="320" width="700" height="120" rx="10" fill="#f8fafc" stroke="#cbd5e1" stroke-width="1.5" stroke-dasharray="6,4"/>
  <text x="172" y="350" font-size="14.5" font-weight="700" fill="#334155">可选第 4 步:/admin → 重新分析全部分类</text>
  <text x="172" y="376" font-size="13.5" fill="#475569">让 AI 按新分类列表对存量新闻重新判断归属(不只是改名)</text>
  <text x="172" y="398" font-size="13.5" fill="#b45309">效果最准,但消耗 token(全量约 537 条)——预算充值后再跑</text>
  <text x="172" y="420" font-size="13.5" fill="#475569">注意:改名会把旧「文娱体育」新闻直接标成「智慧灯杆」,内容未必匹配该主题</text>
</svg>
</div></html>

具体命令(在服务器上执行)

cd /opt/trendsonar

# ① 改配置:NEWS_CATEGORIES 删「文娱体育」、加「智慧灯杆」
python3 - <<'PY'
import json
p = 'data/config.yaml'
d = json.load(open(p, encoding='utf-8'))
cats = d['NEWS_CATEGORIES']
cats = [c for c in cats if c != '文娱体育']
if '智慧灯杆' not in cats:
    cats.append('智慧灯杆')
d['NEWS_CATEGORIES'] = cats
json.dump(d, open(p, 'w', encoding='utf-8'), ensure_ascii=False, indent=2)
print(d['NEWS_CATEGORIES'])
PY

# ② 存量 98 条改名
docker exec trendsonar-postgres psql -U trendsonar -d trendsonar -c \
  "UPDATE news SET category='智慧灯杆' WHERE category='文娱体育';"

# ③ 重启清缓存
docker compose restart trendsonar

两点提醒

  1. 改名是"改标签"不是"AI 重新分类":原来属于文娱体育的 98 条新闻会直接变成智慧灯杆,内容上未必真属于这个主题。如果希望 AI 重新判断这些新闻的归属,用可选的第 4 步(后台"重新分析全部分类",耗 token)。
  2. 分类名会进入 AI 的分类提示词,改成「智慧灯杆」后,AI 在分析新新闻时会把它作为候选之一。

需要我现在就在服务器上按这个例子(文娱体育 → 智慧灯杆)执行吗?还是你要换别的分类名?