postgresql_16:3.9.8.3 Dictionary Testing
PostgreSQL 16 > The SQL Language > Full Text Search > Testing and Debugging Text Search > 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 ----------- {star} SELECT ts_lexize('english_stem', 'a'); 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? ---------- t The thesaurus dictionary thesaurus_astro does know the phrase supernovae stars, but ts_lexize fails since it does not parse the input text but treats it as a single token. Use plainto_tsquery or to_tsvector to test thesaurus dictionaries, for example: SELECT plainto_tsquery('supernovae stars'); plainto_tsquery ----------------- 'sn'