The form <type>text</type> <literal>@@</literal> <type>text</type>
is equivalent to <literal>to_tsvector(x) @@ plainto_tsquery(y)</literal>.
</para>
<para>
Within a <type>tsquery</type>, the <literal>&</literal> (AND) operator
specifies that both its arguments must appear in the document to have a
match. Similarly, the <literal>|</literal> (OR) operator specifies that
at least one of its arguments must appear, while the <literal>!</literal> (NOT)
operator specifies that its argument must <emphasis>not</emphasis> appear in
order to have a match.
For example, the query <literal>fat & ! rat</literal> matches documents that
contain <literal>fat</literal> but not <literal>rat</literal>.
</para>
<para>
Searching for phrases is possible with the help of
the <literal><-></literal> (FOLLOWED BY) <type>tsquery</type> operator, which
matches only if its arguments have matches that are adjacent and in the
given order. For example:
<programlisting>
SELECT to_tsvector('fatal error') @@ to_tsquery('fatal <-> error');
?column?
----------
t
SELECT to_tsvector('error is not fatal') @@ to_tsquery('fatal <-> error');
?column?
----------
f
</programlisting>
There is a more general version of the FOLLOWED BY operator having the
form <literal><<replaceable>N</replaceable>></literal>,
where <replaceable>N</replaceable> is an integer standing for the difference between
the positions of the matching lexemes. <literal><1></literal> is
the same as <literal><-></literal>, while <literal><2></literal>
allows exactly one other lexeme to appear between the matches, and so
on. The <literal>phraseto_tsquery</literal> function makes use of this
operator to construct a <literal>tsquery</literal> that can match a multi-word
phrase when some of the words are stop words. For example:
<programlisting>
SELECT phraseto_tsquery('cats ate rats');
phraseto_tsquery
-------------------------------
'cat' <-> 'ate' <-> 'rat'
SELECT phraseto_tsquery('the cats ate the rats');
phraseto_tsquery
-------------------------------
'cat' <-> 'ate' <2> 'rat'
</programlisting>
</para>
<para>
A special case that's sometimes useful is that <literal><0></literal>
can be used to require that two patterns match the same word.
</para>
<para>
Parentheses can be used to control nesting of the <type>tsquery</type>
operators. Without parentheses, <literal>|</literal> binds least tightly,
then <literal>&</literal>, then <literal><-></literal>,
and <literal>!</literal> most tightly.
</para>
<para>
It's worth noticing that the AND/OR/NOT operators mean something subtly
different when they are within the arguments of a FOLLOWED BY operator
than when they are not, because within FOLLOWED BY the exact position of
the match is significant. For example, normally <literal>!x</literal> matches
only documents that do not contain <literal>x</literal> anywhere.
But <literal>!x <-> y</literal> matches <literal>y</literal> if it is not
immediately after an <literal>x</literal>; an occurrence of <literal>x</literal>
elsewhere in the document does not prevent a match. Another example is
that <literal>x & y</literal> normally only requires that <literal>x</literal>
and <literal>y</literal> both appear somewhere in the document, but
<literal>(x & y) <-> z</literal> requires <literal>x</literal>
and <literal>y</literal> to match at the same place, immediately before
a <literal>z</literal>. Thus this query behaves differently from
<literal>x <-> z & y <-> z</literal>, which will match a
document containing two separate sequences <literal>x z</literal> and
<literal>y z</literal>. (This specific query is useless as written,
since <literal>x</literal>