Accepts querytext, which should be a single tokens
separated by the boolean operators & and, |
or, and ! not, which can be grouped using parenthesis.
In other words, to_tsquery expects already parsed text.
Each token is reduced to a lexeme using the current or specified configuration.
Weight class can be assigned to each lexeme entry to restrict search region
(see setweight for explanation), for example

'fat:a & rats'

to_tsquery function could accept
text string. In this case querytext
should be quoted. This may be useful, for example, to use with thesaurus
dictionary. In example below, thesaurus contains rule
supernovae stars : sn.

Transforms unformatted text querytext to tsquery.
It is the same as to_tsquery, but accepts text
and will call parser to break it onto tokens.
plainto_tsquery assumes & boolean
operator between words and doesn't recognizes weight classes.

querytree(query TSQUERY) RETURNS text

This returns a query which actually used in searching in index. It could be
used to test for an empty query. Select below returns 'T', which
corresponds to empty query, since GIN index doesn't supports negate query and
full index scan is very ineffective.

Directly casting text to a tsquery
allows you to directly inject lexemes into a query, with whatever positions
and position weight flags you choose to specify. The text should be formatted
like the query would be printed by the output of a SELECT.

numnode(query TSQUERY) RETURNS INTEGER

This returns the number of nodes in query tree. This function could be used
to resolve if query is meaningful
( returns > 0) , or contains only stop-words (returns 0).

Query rewriting is a set of functions and operators for tsquery type.
It allows to control search at query time without reindexing
(opposite to thesaurus), for example, expand search using synonyms
(new york, big apple, nyc, gotham) or narrow search directing
user to some hot topic. Notice, that rewriting rules can be added online.

rewrite() function changes original query by replacing
part of the query by sample string of type tsquery, as it defined by rewrite
rule. Arguments of rewrite() function can be
column names of type tsquery.

Rewriting can be slow in case of many rewriting rules, since it checks every rule
for possible hit. To filter out obvious non-candidate rules there are containment
operators for tsquery type. In example below, we select only those
rules, which might contains in the original query.