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

时间:2024-01-23 20:09:31

操作步骤

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

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

  2. 创建Synonym词典。

    假设同义词词典定义文件gs_dict.syn内容如下:
    1
    2
    gaussdb    gs
    gauss      gs
    

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

    1
    2
    3
    4
    5
    gaussdb=# CREATE TEXT SEARCH DICTIONARY gs_dict (
         TEMPLATE = synonym,
         SYNONYMS = gs_dict,
         FILEPATH = 'file:///home/dicts'
     );
    

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

    1
    2
    3
    4
    5
    6
    7
    gaussdb=# CREATE TEXT SEARCH DICTIONARY english_ispell (
        TEMPLATE = ispell,
        DictFile = english,
        AffFile = english,
        StopWords = english,
        FILEPATH = 'file:///home/dicts' 
    );
    

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

    1
    2
    3
    4
    gaussdb=# ALTER TEXT SEARCH CONFIGURATION ts_conf
        ALTER MAPPING FOR asciiword, asciihword, hword_asciipart,
                          word, hword, hword_part
        WITH gs_dict, english_ispell, english_stem;
    

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

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

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

    1
    2
    3
    4
    5
    gaussdb=# SELECT * FROM ts_debug('ts_conf', '
     GaussDB , the highly scalable, SQL compliant, open source object-relational
    database management system, is now undergoing beta testing of the next
    version of our software.
    ');
    

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

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    gaussdb=# \dF+ ts_conf
          Text search configuration "public.ts_conf"
    Parser: "pg_catalog.default"
          Token      |            Dictionaries             
    -----------------+-------------------------------------
     asciihword      | gs_dict,english_ispell,english_stem
     asciiword       | gs_dict,english_ispell,english_stem
     file            | simple
     host            | simple
     hword           | gs_dict,english_ispell,english_stem
     hword_asciipart | gs_dict,english_ispell,english_stem
     hword_numpart   | simple
     hword_part      | gs_dict,english_ispell,english_stem
     int             | simple
     numhword        | simple
     numword         | simple
     uint            | simple
     version         | simple
     word            | gs_dict,english_ispell,english_stem
    
    gaussdb=# SET default_text_search_config = 'public.ts_conf';
    SET
    gaussdb=# SHOW default_text_search_config;
     default_text_search_config 
    ----------------------------
     public.ts_conf
    (1 row)
    

support.huaweicloud.com/distributed-devg-v3-gaussdb/gaussdb-12-0442.html