feat(search): 装 zhparser 中文分词 + 0010 迁移修正
- Dockerfile.postgres: 从 alpine 切到 debian bookworm,apt 装 postgresql-16-zhparser - docker-compose.yml: postgres 改用 build 指向 Dockerfile.postgres - 0010 迁移: CREATE EXTENSION zhparser + 建 chinese_zh text search config + 重建 articles.title_zh_tsv 用 chinese_zh + 重写 refresh_search_keywords()
This commit is contained in:
27
backend/Dockerfile.postgres
Normal file
27
backend/Dockerfile.postgres
Normal file
@@ -0,0 +1,27 @@
|
||||
# Postgres 16 + zhparser 中文分词扩展
|
||||
# 基础镜像从 alpine 切到 debian bookworm,为了 apt 能装 postgresql-16-zhparser
|
||||
# alpine 仓库没打包 zhparser,只能从源码编,代价不值
|
||||
#
|
||||
# 构建: docker build -f backend/Dockerfile.postgres -t diary-postgres:zh ./backend
|
||||
# 配合 docker-compose.yml 改 postgres 服务的 build 字段使用
|
||||
FROM postgres:16-bookworm
|
||||
|
||||
# 装 zhparser + scws(scws 是 zhparser 依赖的分词库)
|
||||
# postgresql-16-zhparser 包会同时拉 libscws 等依赖
|
||||
# bookworm 仓库里有现成二进制包,免编译
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
postgresql-16-zhparser \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 注意:
|
||||
# 1) zhparser 扩展本身不需要 postgresql.conf 改 shared_preload_libraries
|
||||
# (那是 pg_stat_statements / pg_cron 之类才需要)
|
||||
# 2) 扩展是建在 database 里的(用 CREATE EXTENSION zhparser;),不是 initdb 时装
|
||||
# 所以不需要改 entrypoint,迁移里 CREATE EXTENSION 即可
|
||||
# 3) 如果将来升级 PG 大版本,zhparser 包名会跟着变(postgresql-XX-zhparser)
|
||||
# Dockerfile 写死版本号,升级时要改
|
||||
|
||||
# 默认继承 postgres:16-bookworm 的 entrypoint / cmd
|
||||
# 数据 volume 复用 pg_data,数据兼容(只是多了个 extension)
|
||||
Reference in New Issue
Block a user