云数据库 GaussDB-分词器测试

时间:2023-11-01 16:22:50

分词器测试

函数ts_debug允许简单测试文本搜索分词器。

12345678
ts_debug([ config regconfig, ] document text,         OUT alias text,         OUT description text,         OUT token text,         OUT dictionaries regdictionary[],         OUT dictionary regdictionary,         OUT lexemes text[])         returns setof record

ts_debug显示document的每个token信息,token是由解析器生成,由指定的词典进行处理。如果忽略对应参数,则使用config指定的分词器或者default_text_search_config指定的分词器。

ts_debug为文本解析器标识的每个token返回一行记录。记录中的列分别是:

  • alias:text类型,token的别名。
  • description:text类型,token的描述。
  • token:text类型,token的文本内容。
  • dictionaries:regdictionary数组类型,是分词器为token选定的词典。
  • dictionary:regdictionary类型,用来识别token的词典。如果为空,则不做识别。
  • lexemes:text数组类型,词典识别token时生成的词素。如果为空,则不生成词素。空数组({})意味着token将被识别成停用词。

一个简单的例子:

 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728
openGauss=# SELECT * FROM ts_debug('english','a fat  cat sat on a mat - it ate a fat rats');   alias   |   description   | token |  dictionaries  |  dictionary  | lexemes -----------+-----------------+-------+----------------+--------------+--------- asciiword | Word, all ASCII | a     | {english_stem} | english_stem | {} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | fat   | {english_stem} | english_stem | {fat} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | cat   | {english_stem} | english_stem | {cat} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | sat   | {english_stem} | english_stem | {sat} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | on    | {english_stem} | english_stem | {} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | a     | {english_stem} | english_stem | {} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | mat   | {english_stem} | english_stem | {mat} blank     | Space symbols   |       | {}             |              |  blank     | Space symbols   | -     | {}             |              |  asciiword | Word, all ASCII | it    | {english_stem} | english_stem | {} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | ate   | {english_stem} | english_stem | {ate} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | a     | {english_stem} | english_stem | {} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | fat   | {english_stem} | english_stem | {fat} blank     | Space symbols   |       | {}             |              |  asciiword | Word, all ASCII | rats  | {english_stem} | english_stem | {rat}(24 rows)
support.huaweicloud.com/distributed-devg-v2-opengauss/gaussdb-v5r2c10-0505.html