# 12.8. Testing and Debugging Text Search
The behavior of a custom text search configuration can easily become confusing. The functions described in this section are useful for testing text search objects. You can test a complete configuration, or test parsers and dictionaries separately.
# 12.8.1. Configuration Testing
The function ts_debug
allows easy testing of a text search configuration.
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
displays information about every token of document
as produced by the parser and processed by the configured dictionaries. It uses the configuration specified by config
, or default_text_search_config
if that argument is omitted.
ts_debug
returns one row for each token identified in the text by the parser. The columns returned are
alias
text
— short name of the token typedescription
text
— description of the token typetoken
text
— text of the tokendictionaries
regdictionary[]
— the dictionaries selected by the configuration for this token typedictionary
regdictionary
— the dictionary that recognized the token, orNULL
if none didlexemes
text[]
— the lexeme(s) produced by the dictionary that recognized the token, orNULL
if none did; an empty array ({}
) means it was recognized as a stop word
Here is a simple example:
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) returns setof record ts_parse(parser_oid oid, document text, OUT tokid integer, OUT token text) returns setof record
`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:
SELECT * FROM ts_parse('default', '123 - a number'); tokid | token
# 12.8.3. Dictionary Testing
The ts_lexize
function facilitates dictionary testing.
ts_lexize(dict regdictionary, token text) returns text[]
ts_lexize
returns an array of lexemes if the input token
is known to the dictionary, or an empty array if the token is known to the dictionary but it is a stop word, or NULL
if it is an unknown word.
Examples:
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:
SELECT ts_lexize('thesaurus_astro', 'supernovae stars') is null; ?column?