@@ -3885,12 +3885,12 @@ SELECT 'a:1A fat:2B,4C cat:5D'::tsvector;
38853885
38863886 <para>
38873887 It is important to understand that the
3888- <type>tsvector</type> type itself does not perform any normalization;
3889- it assumes the words it is given are normalized appropriately
3890- for the application. For example,
3888+ <type>tsvector</type> type itself does not perform any word
3889+ normalization; it assumes the words it is given are normalized
3890+ appropriately for the application. For example,
38913891
38923892<programlisting>
3893- select 'The Fat Rats'::tsvector;
3893+ SELECT 'The Fat Rats'::tsvector;
38943894 tsvector
38953895--------------------
38963896 'Fat' 'Rats' 'The'
@@ -3929,12 +3929,20 @@ SELECT to_tsvector('english', 'The Fat Rats');
39293929 <literal><-></> (FOLLOWED BY). There is also a variant
39303930 <literal><<replaceable>N</>></literal> of the FOLLOWED BY
39313931 operator, where <replaceable>N</> is an integer constant that
3932- specifies a maximum distance between the two lexemes being searched
3932+ specifies the distance between the two lexemes being searched
39333933 for. <literal><-></> is equivalent to <literal><1></>.
39343934 </para>
39353935
39363936 <para>
3937- Parentheses can be used to enforce grouping of the operators:
3937+ Parentheses can be used to enforce grouping of these operators.
3938+ In the absence of parentheses, <literal>!</> (NOT) binds most tightly,
3939+ <literal><-></literal> (FOLLOWED BY) next most tightly, then
3940+ <literal>&</literal> (AND), with <literal>|</literal> (OR) binding
3941+ the least tightly.
3942+ </para>
3943+
3944+ <para>
3945+ Here are some examples:
39383946
39393947<programlisting>
39403948SELECT 'fat & rat'::tsquery;
@@ -3951,17 +3959,21 @@ SELECT 'fat & rat & ! cat'::tsquery;
39513959 tsquery
39523960------------------------
39533961 'fat' & 'rat' & !'cat'
3962+
3963+ SELECT '(fat | rat) <-> cat'::tsquery;
3964+ tsquery
3965+ -----------------------------------
3966+ 'fat' <-> 'cat' | 'rat' <-> 'cat'
39543967</programlisting>
39553968
3956- In the absence of parentheses, <literal>!</> (NOT) binds most tightly,
3957- and <literal>&</literal> (AND) and <literal><-></literal> (FOLLOWED BY)
3958- both bind more tightly than <literal>|</literal> (OR).
3969+ The last example demonstrates that <type>tsquery</type> sometimes
3970+ rearranges nested operators into a logically equivalent formulation.
39593971 </para>
39603972
39613973 <para>
39623974 Optionally, lexemes in a <type>tsquery</type> can be labeled with
39633975 one or more weight letters, which restricts them to match only
3964- <type>tsvector</> lexemes with matching weights:
3976+ <type>tsvector</> lexemes with one of those weights:
39653977
39663978<programlisting>
39673979SELECT 'fat:ab & cat'::tsquery;
@@ -3981,25 +3993,7 @@ SELECT 'super:*'::tsquery;
39813993 'super':*
39823994</programlisting>
39833995 This query will match any word in a <type>tsvector</> that begins
3984- with <quote>super</>. Note that prefixes are first processed by
3985- text search configurations, which means this comparison returns
3986- true:
3987- <programlisting>
3988- SELECT to_tsvector( 'postgraduate' ) @@ to_tsquery( 'postgres:*' );
3989- ?column?
3990- ----------
3991- t
3992- (1 row)
3993- </programlisting>
3994- because <literal>postgres</> gets stemmed to <literal>postgr</>:
3995- <programlisting>
3996- SELECT to_tsquery('postgres:*');
3997- to_tsquery
3998- ------------
3999- 'postgr':*
4000- (1 row)
4001- </programlisting>
4002- which then matches <literal>postgraduate</>.
3996+ with <quote>super</>.
40033997 </para>
40043998
40053999 <para>
@@ -4015,6 +4009,24 @@ SELECT to_tsquery('Fat:ab & Cats');
40154009------------------
40164010 'fat':AB & 'cat'
40174011</programlisting>
4012+
4013+ Note that <function>to_tsquery</> will process prefixes in the same way
4014+ as other words, which means this comparison returns true:
4015+
4016+ <programlisting>
4017+ SELECT to_tsvector( 'postgraduate' ) @@ to_tsquery( 'postgres:*' );
4018+ ?column?
4019+ ----------
4020+ t
4021+ </programlisting>
4022+ because <literal>postgres</> gets stemmed to <literal>postgr</>:
4023+ <programlisting>
4024+ SELECT to_tsvector( 'postgraduate' ), to_tsquery( 'postgres:*' );
4025+ to_tsvector | to_tsquery
4026+ ---------------+------------
4027+ 'postgradu':1 | 'postgr':*
4028+ </programlisting>
4029+ which will match the stemmed form of <literal>postgraduate</>.
40184030 </para>
40194031
40204032 </sect2>
0 commit comments