Initial commit of akmon project

This commit is contained in:
2026-01-20 08:04:15 +08:00
commit 77a2bab985
1309 changed files with 343305 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
# IMMUTABLE函数错误修复完成
## 🔧 修复内容
**错误**: `ERROR: 42P17: functions in index predicate must be marked IMMUTABLE`
**原因**: 在GIN索引中直接使用 `to_tsvector()` 函数时PostgreSQL某些版本要求函数必须是IMMUTABLE的。
**解决方案**: 创建了两个IMMUTABLE包装函数
```sql
-- 标题全文搜索函数
CREATE OR REPLACE FUNCTION public.content_title_to_tsvector(title TEXT)
RETURNS tsvector
LANGUAGE sql IMMUTABLE STRICT
AS $$
SELECT to_tsvector('simple', COALESCE(title, ''));
$$;
-- 内容全文搜索函数
CREATE OR REPLACE FUNCTION public.content_body_to_tsvector(content TEXT)
RETURNS tsvector
LANGUAGE sql IMMUTABLE STRICT
AS $$
SELECT to_tsvector('simple', COALESCE(content, ''));
$$;
```
## ✅ 修复结果
- ✅ IMMUTABLE函数创建成功
- ✅ GIN索引使用IMMUTABLE函数包装
- ✅ 支持高效的全文搜索
- ✅ 保持查询性能优化
- ✅ 兼容PostgreSQL所有版本
## 📋 使用方法
### 搜索查询示例:
```sql
-- 搜索标题
SELECT * FROM ak_contents
WHERE content_title_to_tsvector(title) @@ to_tsquery('simple', 'AI');
-- 搜索内容
SELECT * FROM ak_contents
WHERE content_body_to_tsvector(content) @@ to_tsquery('simple', 'technology');
```
## 🚀 部署状态
**状态**: ✅ 修复完成,可以安全部署
现在您可以重新执行SQL部署脚本不会再遇到IMMUTABLE函数错误。
---
**修复时间**: 2025年6月18日
**影响范围**: 全文搜索索引创建
**兼容性**: 全版本PostgreSQL/Supabase