is not shown on output:
<programlisting>
SELECT 'a:1A fat:2B,4C cat:5D'::tsvector;
tsvector
----------------------------
'a':1A 'cat':5 'fat':2B,4C
</programlisting>
Weights are typically used to reflect document structure, for example
by marking title words differently from body words. Text search
ranking functions can assign different priorities to the different
weight markers.
</para>
<para>
It is important to understand that the
<type>tsvector</type> type itself does not perform any word
normalization; it assumes the words it is given are normalized
appropriately for the application. For example,
<programlisting>
SELECT 'The Fat Rats'::tsvector;
tsvector
--------------------
'Fat' 'Rats' 'The'
</programlisting>
For most English-text-searching applications the above words would
be considered non-normalized, but <type>tsvector</type> doesn't care.
Raw document text should usually be passed through
<function>to_tsvector</function> to normalize the words appropriately
for searching:
<programlisting>
SELECT to_tsvector('english', 'The Fat Rats');
to_tsvector
-----------------
'fat':2 'rat':3
</programlisting>
Again, see <xref linkend="textsearch"/> for more detail.
</para>
</sect2>
<sect2 id="datatype-tsquery">
<title><type>tsquery</type></title>
<indexterm>
<primary>tsquery (data type)</primary>
</indexterm>
<para>
A <type>tsquery</type> value stores lexemes that are to be
searched for, and can combine them using the Boolean operators
<literal>&</literal> (AND), <literal>|</literal> (OR), and
<literal>!</literal> (NOT), as well as the phrase search operator
<literal><-></literal> (FOLLOWED BY). There is also a variant
<literal><<replaceable>N</replaceable>></literal> of the FOLLOWED BY
operator, where <replaceable>N</replaceable> is an integer constant that
specifies the distance between the two lexemes being searched
for. <literal><-></literal> is equivalent to <literal><1></literal>.
</para>
<para>
Parentheses can be used to enforce grouping of these operators.
In the absence of parentheses, <literal>!</literal> (NOT) binds most tightly,
<literal><-></literal> (FOLLOWED BY) next most tightly, then
<literal>&</literal> (AND), with <literal>|</literal> (OR) binding
the least tightly.
</para>
<para>
Here are some examples:
<programlisting>
SELECT 'fat & rat'::tsquery;
tsquery
---------------
'fat' & 'rat'
SELECT 'fat & (rat | cat)'::tsquery;
tsquery
---------------------------
'fat' & ( 'rat' | 'cat' )
SELECT 'fat & rat & ! cat'::tsquery;
tsquery
------------------------
'fat' & 'rat' & !'cat'
</programlisting>
</para>
<para>
Optionally, lexemes in a <type>tsquery</type> can be labeled with
one or more weight letters, which restricts them to match only
<type>tsvector</type> lexemes with one of those weights:
<programlisting>
SELECT 'fat:ab & cat'::tsquery;
tsquery
------------------
'fat':AB & 'cat'
</programlisting>
</para>
<para>
Also, lexemes in a <type>tsquery</type> can be labeled with <literal>*</literal>
to specify prefix matching:
<programlisting>
SELECT 'super:*'::tsquery;
tsquery
-----------
'super':*
</programlisting>
This query will match any word in a <type>tsvector</type> that begins
with <quote>super</quote>.
</para>
<para>
Quoting rules for lexemes are the same as described previously for
lexemes in <type>tsvector</type>; and, as with <type>tsvector</type>,
any required normalization of words must be done before converting
to the <type>tsquery</type> type. The <function>to_tsquery</function>
function is convenient for performing such normalization:
<programlisting>
SELECT to_tsquery('Fat:ab