PostgreSQL 全文搜索

PostgreSQL 全文搜索 在数据量较小的项目中可以使用 PostgreSQL 自带的全文搜索(Full Text Search)支持,代替非常重的 ElasticSearch,减少开发和维护成本,简单又好用,记录下最近的学习 实现全文搜索主要分为几步,分词、向量化、创建索引(倒排索引)、匹配查询 分词 默认自带的分词配置是不支持中文的,但可以安装第三方扩展来支持,检查支持的配置库在 psql 中使用 \dF 命令,\dFp 列出解析器 。 postgres=> \dF List of text search configurations Schema | Name | Description ------------+------------+--------------------------------------- pg_catalog | danish | configuration for danish language pg_catalog | dutch | configuration for dutch language pg_catalog | english | configuration for english language pg_catalog | portuguese | configuration for portuguese language pg_catalog | russian | configuration for russian language pg_catalog | simple | simple configuration pg_catalog | spanish | configuration for spanish language postgres-# \dFp List of text search parsers Schema | Name | Description ------------+---------+--------------------- pg_catalog | default | default word parser 安装支持中文的扩展 支持中文的扩展有以下这两个...

February 11, 2023 · 4 min · 692 words · Fython