1. 介绍
PostgreSQL的模糊查询功能十分强大,可以通过pg_bigm插件来支持前模糊、后模糊和前后模糊场景的模糊查询的场景。
pg_bigm是将对象进行切词,每2个字节为一组进行切割,可以支持任意字数模糊查询
2. 编译安装
依赖安装
apt-get update -y
#postgresql-server-dev-all 不装会报错 bigm_op.c:14:10: fatal error: postgres.h: No such file or directory
#libicu-dev 不装会报错 unicode/ucol.h: No such file or directory
apt-get -y install make gcc g++ curl libicu-dev postgresql-server-dev-all
pg_bigm的安装
版本:pg_bigm 1.2
wget https://osdn.net/dl/pgbigm/pg_bigm-1.2-20200228.tar.gz
tar zxf pg_bigm-1.2-20200228.tar.gz
cd pg_bigm-1.2-20200228
find / -name pg_config
/usr/lib/postgresql/14/bin/pg_config
/usr/bin/pg_config
make USE_PGXS=1 PG_CONFIG=/usr/lib/postgresql/14/bin/pg_config
make USE_PGXS=1 PG_CONFIG=/usr/lib/postgresql/14/bin/pg_config install
USE_PGXS:构建pg_bigm时必须始终指定USE_PGXS = 1。
PG_CONFIG:指定pg_config的路径(存在于PostgreSQL安装的bin目录中)。如果PATH环境变量包含pg_config的路径,则无需指定PG_CONFIG。
#登录
psql -U postgres
#列出数据库
\l
#或者
SELECT * FROM pg_database ORDER BY datname;
#切换数据库
\c ***;
#创建插件
create extension pg_bigm;
#查看插件
\dx pg_bigm
List of installed extensions
Name | Version | Schema | Description
---------+---------+--------+---------------------------------------------------
---------------
pg_bigm | 1.2 | public | text similarity measurement and index searching ba
sed on bigrams
(1 row)
3. docker中安装
使用dockerfile或者在PostgreSQL镜像中直接执行都可
FROM postgres:14.6
ADD pg_bigm-1.2-20200228.tar.gz /usr/share/
RUN apt-get update -y && apt-get -y install make gcc g++ curl libicu-dev postgresql-server-dev-all telnet
WORKDIR /usr/share/pg_bigm-1.2-20200228
RUN make USE_PGXS=1 PG_CONFIG=/usr/lib/postgresql/14/bin/pg_config && make USE_PGXS=1 PG_CONFIG=/usr/lib/postgresql/14/bin/pg_config install
build生成镜像
docker build -t *** .