fix(search): drop ineffective trgm GIN index; correct misleading comment

ILIKE '%...%' 双侧通配符无法命中 trgm GIN(仅前缀模式命中),索引建了等于
白建且误导(L1)。删除以避免误导,搜索暂靠 LIMIT + 限流兜底;tsvector 全文
检索作为后续独立升级。
This commit is contained in:
xfy 2026-06-18 13:42:23 +08:00
parent d1e08ec402
commit b34803e57d
2 changed files with 8 additions and 1 deletions

View File

@ -0,0 +1,5 @@
-- 删除对 ILIKE '%...%'(双侧通配符)无效的 trgm GIN 索引L1
-- pg_trgm 的 GIN 索引只在前缀模式('xxx%')命中,双侧模糊匹配无法利用它,
-- 索引建了等于白建且误导。搜索改由 LIMIT + 限流兜底的全表扫承担;
-- 后续可升级为 tsvector 全文检索(独立大改动)。
DROP INDEX IF EXISTS idx_posts_search_trgm;

View File

@ -61,7 +61,9 @@ pub async fn search_posts(query: String) -> Result<PostListResponse, ServerFnErr
.replace('%', "\\%")
.replace('_', "\\_");
// 使用 ILIKE 做前缀模糊匹配,并按 word_similarity 降序、发布时间降序排序。
// 使用 ILIKE 做子串模糊匹配(双侧 %)。注意:此查询无法利用 trgm GIN
// 索引(仅前缀模式命中),走全表扫,靠 LIMIT 50 + search 限流兜底。
// 后续可升级为 tsvector 全文检索(独立大改动)。
let rows = client
.query(
"SELECT