暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

华为openGauss 配置示例

华为高斯 2020-06-01
515

文本搜索配置(Text Search Configuration),指定了将文档转换成tsvector过程中所必需的组件:

  • 解析器,用于把文本分解成标记token;
  • 词典列表,用于将每个token转换成词位lexeme。

每次to_tsvector或to_tsquery函数调用时,都需要指定一个文本搜索配置来指定具体的处理过程。GUC参数default_text_search_config指定了默认的文本搜索配置,当文本搜索函数中没有显式指定文本搜索配置参数时,将会使用该默认值进行处理。

openGauss中预定义有一些可用的文本搜索配置,用户也可创建自定义的文本搜索配置。此外,为了便于管理文本搜索对象,还提供有多个gsql元命令,可以显示有关文本搜索对象的信息(详细请参见《工具参考》中“客户端工具 >元命令参考”章节)。

操作步骤

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

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

  2. 创建Synonym词典。

    假设同义词词典定义文件pg_dict.syn内容如下:

    postgres pg pgsql pg postgresql pg

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

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

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

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

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

    postgres=# 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类型。

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

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

    postgres=# SELECT * FROM ts_debug('ts_conf', ' PostgreSQL, 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有效。

    ``` postgres=# \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_stem

    postgres=# SET default_text_search_config = 'public.ts_conf'; SET postgres=# SHOW default_text_search_config; default_text_search_config


    public.ts_conf (1 row) ```

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

文集目录
暂无数据