12.7 配置示例
文件检索配置指定将文档转换为tsvector所需的所有选项:用于将文本解析为token的解析器,然后将token转换为词位的词典。default_text_search_config指定默认配置。
示例:
CREATE TEXT SEARCH CONFIGURATION public.pg ( COPY =
pg_catalog.english );
定义文件,其内容:
postgres pg
pgsql pg
postgresql pg
创建同义词词典:
CREATE TEXT SEARCH DICTIONARY pg_dict (
TEMPLATE = synonym,
SYNONYMS = pg_dict
);
接下来注册Ispell词典:
CREATE TEXT SEARCH DICTIONARY english_ispell (
TEMPLATE = ispell,
DictFile = english,
AffFile = english,
StopWords = english
);
接下来设置配置pg中的词匹配:
ALTER TEXT SEARCH CONFIGURATION pg
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart,
word, hword, hword_part
WITH pg_dict, english_ispell, english_stem;
去掉部分匹配类型:
ALTER TEXT SEARCH CONFIGURATION pg
DROP MAPPING FOR email, url, url_path, sfloat, float;
测试配置:
SELECT * FROM ts_debug('public.pg', '
PostgreSQL, the highly scalable, SQL compliant, open source objectrelational
database management system, is now undergoing beta testing of the
next
version of our software.
');
接下来设置会话使用该配置;
=> \dF
List of text search configurations
Schema | Name | Description
---------+------+-------------
public | pg |
SET default_text_search_config = 'public.pg';
SET
SHOW default_text_search_config;
default_text_search_config
----------------------------
public.pg