From b34803e57d3b4076e6a6bde201477e75a724a87d Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 18 Jun 2026 13:42:23 +0800 Subject: [PATCH] fix(search): drop ineffective trgm GIN index; correct misleading comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ILIKE '%...%' 双侧通配符无法命中 trgm GIN(仅前缀模式命中),索引建了等于 白建且误导(L1)。删除以避免误导,搜索暂靠 LIMIT + 限流兜底;tsvector 全文 检索作为后续独立升级。 --- migrations/014_drop_ineffective_trgm_index.sql | 5 +++++ src/api/posts/search.rs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 migrations/014_drop_ineffective_trgm_index.sql diff --git a/migrations/014_drop_ineffective_trgm_index.sql b/migrations/014_drop_ineffective_trgm_index.sql new file mode 100644 index 0000000..fe477c6 --- /dev/null +++ b/migrations/014_drop_ineffective_trgm_index.sql @@ -0,0 +1,5 @@ +-- 删除对 ILIKE '%...%'(双侧通配符)无效的 trgm GIN 索引(L1)。 +-- pg_trgm 的 GIN 索引只在前缀模式('xxx%')命中,双侧模糊匹配无法利用它, +-- 索引建了等于白建且误导。搜索改由 LIMIT + 限流兜底的全表扫承担; +-- 后续可升级为 tsvector 全文检索(独立大改动)。 +DROP INDEX IF EXISTS idx_posts_search_trgm; diff --git a/src/api/posts/search.rs b/src/api/posts/search.rs index 50ac5aa..b2250b6 100644 --- a/src/api/posts/search.rs +++ b/src/api/posts/search.rs @@ -61,7 +61,9 @@ pub async fn search_posts(query: String) -> Result