fix(search): ts_stat 改单参(text),避免 'a' mask 静默 0 行
zhparser 不标 A 权重(也不标 B/C/D),传 'a' mask 给 ts_stat(text, weights) 会过滤掉所有词 但不报错,静默 0 行。改成 ts_stat(text) 单参(等价 mask='abcd',聚合所有权重)。 修: - 0010 迁移里 refresh_search_keywords() 改用单参 ts_stat - 0010 迁移 downgrade 部分同步修 - 0009 迁移 refresh_search_keywords() 同步修 - services/search.py _fallback_keywords 改用 chinese_zh + 单参 ts_stat
This commit is contained in:
@@ -130,8 +130,9 @@ class SearchService:
|
||||
async def _fallback_keywords(self, q: str, limit: int) -> list[dict]:
|
||||
"""回退:ts_stat 实时聚合(慢但能用)。
|
||||
|
||||
- 从 articles.title_zh + body_zh_text 实时 to_tsvector
|
||||
- 适用:search_keywords 表空 + ts_stat 之前的全量聚合
|
||||
- 从 articles.title_zh + body_zh_text 实时 to_tsvector(chinese_zh)
|
||||
- 适用:search_keywords 表空 + worker 没刷新过
|
||||
- ts_stat(text) 单参 — 第二参 weights mask 不能传 'a'(zhparser 不标 A 权重会 0 行)
|
||||
"""
|
||||
from sqlalchemy import text
|
||||
|
||||
@@ -139,16 +140,13 @@ class SearchService:
|
||||
"""
|
||||
SELECT word, nentry::int AS weight
|
||||
FROM ts_stat(
|
||||
'simple',
|
||||
(
|
||||
SELECT to_tsvector(
|
||||
'simple',
|
||||
coalesce(title_zh, '') || ' ' || coalesce(body_zh_text, '')
|
||||
)
|
||||
FROM articles
|
||||
WHERE title_zh IS NOT NULL OR body_zh_text IS NOT NULL
|
||||
$$SELECT to_tsvector('chinese_zh',
|
||||
coalesce(title_zh, '') || ' ' || coalesce(body_zh_text, '')
|
||||
)
|
||||
)
|
||||
FROM articles
|
||||
WHERE title_zh IS NOT NULL OR body_zh_text IS NOT NULL
|
||||
LIMIT 500$$
|
||||
) AS s
|
||||
WHERE word LIKE :prefix
|
||||
ORDER BY nentry DESC
|
||||
LIMIT :lim
|
||||
|
||||
Reference in New Issue
Block a user