refactor(search): 只展示 keyword 续接词,去掉 titles 段

产品决定:搜索建议只展示 ts_stat 高频词续接(如'美'→美国/美军/美国政府),
不要真实文章 id 提示(用户认为这种'文章#566871'是噪音,没连续性)。

改动:
- SearchSuggestionsResponse 去 title,只剩 query + keywords
- SearchService 只查 search_keywords,fallback 路径也只针对 keywords
- Feed.vue: 删掉 suggestTitles 状态 + SuggestTitleOption 类型联合,
  renderSuggestion 简化成 '词' 标签 + 词文本 + 右侧 weight 数字
- 0011 迁移: 删 search_title_suggestions 表 + 3 索引 + trigger + 函数
  (trigger 在每篇文章 INSERT/UPDATE 都会跑,删了能省掉无用性能损耗)
- 删除: app/models/search_title_suggestion.py + backfill_search_suggestions.py
  替换成: app/scripts/refresh_search_keywords.py(只跑一次词频刷新)
This commit is contained in:
mavis
2026-06-15 19:37:40 +08:00
parent db4fd8699b
commit 85c05c19a7
10 changed files with 277 additions and 366 deletions

View File

@@ -8,7 +8,6 @@ from app.models.article_read import ArticleRead # noqa: F401
from app.models.bookmark import Bookmark # noqa: F401
from app.models.llm_setting import LlmSetting # noqa: F401
from app.models.search_keyword import SearchKeyword # noqa: F401
from app.models.search_title_suggestion import SearchTitleSuggestion # noqa: F401
from app.models.source import Source, SourceKind # noqa: F401
from app.models.subscription import Subscription # noqa: F401
from app.models.user import User, UserRole # noqa: F401
@@ -20,7 +19,6 @@ __all__ = [
"Bookmark",
"LlmSetting",
"SearchKeyword",
"SearchTitleSuggestion",
"Source",
"SourceKind",
"Subscription",

View File

@@ -1,43 +0,0 @@
"""搜索建议 - 真实文章标题片段表(articles 写入 trigger 自动维护)。
- 数据源:articles.title_zh(优先)/ articles.title(短新闻回退)
- 用途:/api/v1/search/suggestions 返回"真实文章标题"建议(B 方案)
- 维护:PG trigger(articles INSERT/UPDATE OF title_zh/title/published_at 触发)
- 查询:prefix_keys @> ARRAY[''] 走 GIN 索引,按 published_at DESC 排序
"""
from __future__ import annotations
from datetime import datetime
from sqlalchemy import BigInteger, DateTime, ForeignKey, String, func
from sqlalchemy.dialects.postgresql import ARRAY, TEXT
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class SearchTitleSuggestion(Base):
__tablename__ = "search_title_suggestions"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
article_id: Mapped[int] = mapped_column(
BigInteger,
ForeignKey("articles.id", ondelete="CASCADE"),
nullable=False,
)
# 该条用的是哪边的文本:'zh' (title_zh) / 'src' (title 短新闻回退)
title_lang: Mapped[str] = mapped_column(String(8), nullable=False, default="zh")
# 预计算前缀数组(从第 1 字到全词)
prefix_keys: Mapped[list[str]] = mapped_column(ARRAY(TEXT), nullable=False)
published_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
def __repr__(self) -> str:
return f"<SearchTitleSuggestion article_id={self.article_id} lang={self.title_lang}>"