云数据库 GaussDB-配置示例:操作步骤

时间:2023-11-01 16:18:33

操作步骤

  1. 创建一个文本搜索配置ts_conf,复制预定义的文本搜索配置english。

    12
    gaussdb=# CREATE TEXT SEARCH CONFIGURATION ts_conf ( COPY = pg_catalog.english );CREATE TEXT SEARCH CONFIGURATION

  2. 创建Synonym词典。

    假设同义词词典定义文件pg_dict.syn内容如下:
    123
    postgres    pg pgsql       pg postgresql  pg

    执行如下语句创建Synonym词典:

    12345
    gaussdb=# CREATE TEXT SEARCH DICTIONARY pg_dict (     TEMPLATE = synonym,     SYNONYMS = pg_dict,     FILEPATH = 'file:///home/dicts' );

  3. 创建一个Ispell词典english_ispell(词典定义文件来自开源词典)。

    1234567
    gaussdb=# CREATE TEXT SEARCH DICTIONARY english_ispell (    TEMPLATE = ispell,    DictFile = english,    AffFile = english,    StopWords = english,    FILEPATH = 'file:///home/dicts' );

  4. 设置文本搜索配置ts_conf,修改某些类型的token对应的词典列表。关于token类型的详细信息,请参见解析器

    1234
    gaussdb=# ALTER TEXT SEARCH CONFIGURATION ts_conf    ALTER MAPPING FOR asciiword, asciihword, hword_asciipart,                      word, hword, hword_part    WITH pg_dict, english_ispell, english_stem;

  5. 在文本搜索配置中,选择设置不索引或搜索某些token类型。

    12
    gaussdb=# ALTER TEXT SEARCH CONFIGURATION ts_conf    DROP MAPPING FOR email, url, url_path, sfloat, float;

  6. 使用文本检索调测函数ts_debug()对所创建的词典配置ts_conf进行测试。

    12345
    gaussdb=# SELECT * FROM ts_debug('ts_conf', 'PostgreSQL, the highly scalable, SQL compliant, open source object-relationaldatabase management system, is now undergoing beta testing of the nextversion of our software.');

  7. 可以设置当前session使用ts_conf作为默认的文本搜索配置。此设置仅在当前session有效。

     1 2 3 4 5 6 7 8 9101112131415161718192021222324252627
    gaussdb=# \dF+ ts_conf      Text search configuration "public.ts_conf"Parser: "pg_catalog.default"      Token      |            Dictionaries             -----------------+------------------------------------- asciihword      | pg_dict,english_ispell,english_stem asciiword       | pg_dict,english_ispell,english_stem file            | simple host            | simple hword           | pg_dict,english_ispell,english_stem hword_asciipart | pg_dict,english_ispell,english_stem hword_numpart   | simple hword_part      | pg_dict,english_ispell,english_stem int             | simple numhword        | simple numword         | simple uint            | simple version         | simple word            | pg_dict,english_ispell,english_stemgaussdb=# SET default_text_search_config = 'public.ts_conf';SETgaussdb=# SHOW default_text_search_config; default_text_search_config ---------------------------- public.ts_conf(1 row)

support.huaweicloud.com/centralized-devg-v3-opengauss/gaussdb-12-0450.html