@@ -3885,12 +3885,12 @@ SELECT 'a:1A fat:2B,4C cat:5D'::tsvector;
3885
3885
3886
3886
<para>
3887
3887
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,
3891
3891
3892
3892
<programlisting>
3893
- select 'The Fat Rats'::tsvector;
3893
+ SELECT 'The Fat Rats'::tsvector;
3894
3894
tsvector
3895
3895
--------------------
3896
3896
'Fat' 'Rats' 'The'
@@ -3929,12 +3929,20 @@ SELECT to_tsvector('english', 'The Fat Rats');
3929
3929
<literal><-></> (FOLLOWED BY). There is also a variant
3930
3930
<literal><<replaceable>N</>></literal> of the FOLLOWED BY
3931
3931
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
3933
3933
for. <literal><-></> is equivalent to <literal><1></>.
3934
3934
</para>
3935
3935
3936
3936
<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:
3938
3946
3939
3947
<programlisting>
3940
3948
SELECT 'fat & rat'::tsquery;
@@ -3951,17 +3959,21 @@ SELECT 'fat & rat & ! cat'::tsquery;
3951
3959
tsquery
3952
3960
------------------------
3953
3961
'fat' & 'rat' & !'cat'
3962
+
3963
+ SELECT '(fat | rat) <-> cat'::tsquery;
3964
+ tsquery
3965
+ -----------------------------------
3966
+ 'fat' <-> 'cat' | 'rat' <-> 'cat'
3954
3967
</programlisting>
3955
3968
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.
3959
3971
</para>
3960
3972
3961
3973
<para>
3962
3974
Optionally, lexemes in a <type>tsquery</type> can be labeled with
3963
3975
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:
3965
3977
3966
3978
<programlisting>
3967
3979
SELECT 'fat:ab & cat'::tsquery;
@@ -3981,25 +3993,7 @@ SELECT 'super:*'::tsquery;
3981
3993
'super':*
3982
3994
</programlisting>
3983
3995
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</>.
4003
3997
</para>
4004
3998
4005
3999
<para>
@@ -4015,6 +4009,24 @@ SELECT to_tsquery('Fat:ab & Cats');
4015
4009
------------------
4016
4010
'fat':AB & 'cat'
4017
4011
</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</>.
4018
4030
</para>
4019
4031
4020
4032
</sect2>
0 commit comments