ts_headline returns fragments of a text document with terms matching a full-text query highlighted. Use it when a search result needs readable excerpts for display or further processing. section 6.5
Highlight a movie description
SELECT id, name, description, ts_headline(description, to_tsquery('pirates')) AS fragments, ts_rank(lexemes, to_tsquery('pirates')) AS rank FROM omdb.movies WHERE lexemes @@ to_tsquery('pirates:B') ORDER BY rank DESC LIMIT 1; The highest-ranked result highlights a matching term in a description fragment, such as <b>pirate</b> Captain Jack is in a battle with the ocean itself.
Customize fragments
Set MaxFragments=3, MinWords=5, MaxWords=10, and FragmentDelimiter=<ft_end> to return more controlled excerpts separated by a custom delimiter.
