# 12.8.测试和调试文本搜索

12.8.1. 配置测试

12.8.2. 解析器测试

12.8.3. 字典测试

自定义文本搜索配置的行为很容易令人困惑。本节中描述的功能对于测试文本搜索对象非常有用。您可以测试完整的配置,或者单独测试解析器和字典。

# 12.8.1.配置测试

功能调试允许轻松测试文本搜索配置。

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

调试显示有关每个标记的信息*文件由解析器生成并由配置的字典处理。它使用配置*或默认文本搜索配置如果省略了这个论点。

调试为解析器在文本中标识的每个标记返回一行。返回的列是

  • 别名 文本-令牌类型的短名称

  • 描述 文本-令牌类型的描述

  • 代币 文本-令牌的文本

  • 字典 regdictionary[]-配置为此令牌类型选择的字典

  • 词典 regdictionary-识别标记的字典,或无效的如果没有

  • 词位 文本[]-识别标记的词典产生的词素,或无效的如果没有;空数组({})意味着它被认为是一个停止词

    下面是一个简单的例子:

SELECT * FROM ts_debug('english', 'a fat  cat sat on a mat - it ate a fat rats');
   alias   |   description   | token |  dictionaries  |  dictionary  | lexemes
### 12.8.2. Parser Testing

 The following functions allow direct testing of a text search parser.

[]()

ts_parse(parser_name text,document text,OUT tokid integer,OUT token text)返回记录集ts_parse(parser_oid,document text,OUT tokid integer,OUT token text)返回记录集

`ts_parse` parses the given *`document`* and returns a series of records, one for each token produced by parsing. Each record includes a `tokid` showing the assigned token type and a `token` which is the text of the token. For example:

从ts_parse中选择*('default','123-一个数字');tokid |令牌

# 12.8.3.字典测试

这个ts_lexize函数有助于字典测试。

ts_lexize(dict regdictionary, token text) returns text[]

ts_lexize如果输入*代币*是字典已知的,或者是空数组(如果字典已知标记但它是停止词),或者无效的如果是一个未知的词。

例如:

SELECT ts_lexize('english_stem', 'stars');
 ts_lexize
### Note

 The `ts_lexize` function expects a single *token*, not text. Here is a case where this can be confusing:

选择ts_lexize(‘同义词库’、‘超新星恒星’)为空?柱