Full-Text Search in PostgreSQL: A Gentle Introduction | ||||
---|---|---|---|---|
Prev | Fast Backward | Chapter 2. FTS Operators and Functions | Fast Forward | Next |
CREATE FUNCTION headline([ id int4, | ts_name text, ] document text, query TSQUERY, [ options text ]) RETURNS text
Every form of the the headline()
function accepts a
document along with a query, and returns one or more ellipse-separated
excerpts from the document in which terms from the query are highlighted.
The configuration with which to parse the document can be specified by either
its id or ts_name;
if none is specified that the current configuration is used instead.
An options string if provided should be a comma-separated list of one or more 'option=value' pairs. The available options are:
StartSel, StopSel -- the strings with which query words appearing in the document should be delimited to distinguish them from other excerpted words.
MaxWords, MinWords -- limits on the shortest and longest headlines you will accept.
ShortWord -- this prevents your headline from beginning or ending with a word which has this many characters or less. The default value of 3 should eliminate most English conjunctions and articles.
HighlightAll -- boolean flag, if TRUE, than the whole document will be highlighted.
Any unspecified options receive these defaults:
StartSel=<b>, StopSel=</b>, MaxWords=35, MinWords=15, ShortWord=3, HighlightAll=FALSE
Notice, that cascade dropping of headline
function
cause dropping of parser, used in fulltext configuration
tsname.
select headline('a b c', 'c'::tsquery); headline -------------- a b <b>c</b> =# select headline('a b c', 'c'::tsquery, 'StartSel=<,StopSel=>'); headline ---------- a b <c>