liveBook · Manning

Token

As explained in Just Use Postgres!

A token is a smaller text component produced by parsing a document, such as a word, number, or phrase.

A token is a smaller text component produced when a document is parsed for full-text search. Tokens can be words, numbers, phrases, or parser-visible symbols; later processing converts relevant tokens into lexemes. section 6.1 section 6.1.1

Inspect tokens with ts_debug

Run SELECT token, description, lexemes, dictionary FROM ts_debug('5 explorers are traveling to a distant galaxy');. Postgres reports 5 as an unsigned integer, words such as explorers as ASCII words, and spaces as space symbols. The same output shows later normalization: explorers becomes explor, traveling becomes travel, and stop words such as are produce no lexeme. section 6.1.1

Listing 6.1 Analyzing tokenization and normalization with ts_debug
SELECT token, description, lexemes, dictionary
FROM ts_debug('5 explorers are traveling to a distant galaxy');

Use the runnable listing to inspect how Postgres splits a sentence and records each token type, lexeme, and dictionary. section 6.1.1

Tokenization fits into a larger search-processing flow:

  • Parse the document into tokens, normalize tokens into lexemes, store or index the lexemes, then search them. section 6.1
  • Let the configured parser and dictionaries determine token types and normalization behavior. section 6.1.2

How Just Use Postgres! covers it

How deep it goes
Explains parsing, token types, and normalization outcomes, but stops short of implementing a custom parser.
Examples
Uses the sentence “5 explorers are traveling to a distant galaxy” with ts_debug output and English and Russian configurations.
What you can do after
Diagnose tokenization and normalization with PostgreSQL’s ts_debug function and inspect the resulting parser classifications.
How it connects
Connects tokenization with parsers, lexemes, dictionaries, normalization, and text search configurations.

Also explained in

Compare how 31 books explain token →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.