@@ -3861,12 +3861,12 @@ SELECT 'a:1A fat:2B,4C cat:5D'::tsvector;
3861
3861
3862
3862
<para>
3863
3863
It is important to understand that the
3864
- <type>tsvector</type> type itself does not perform anynormalization;
3865
- it assumes the words it is given are normalized appropriately
3866
- for the application. For example,
3864
+ <type>tsvector</type> type itself does not perform anyword
3865
+ normalization; it assumes the words it is given are normalized
3866
+ appropriately for the application. For example,
3867
3867
3868
3868
<programlisting>
3869
- select 'The Fat Rats'::tsvector;
3869
+ SELECT 'The Fat Rats'::tsvector;
3870
3870
tsvector
3871
3871
--------------------
3872
3872
'Fat' 'Rats' 'The'
@@ -3899,11 +3899,26 @@ SELECT to_tsvector('english', 'The Fat Rats');
3899
3899
3900
3900
<para>
3901
3901
A <type>tsquery</type> value stores lexemes that are to be
3902
- searched for, and combines them honoring the Boolean operators
3903
- <literal>&</literal> (AND), <literal>|</literal> (OR),
3904
- <literal>!</> (NOT) and <literal><-></> (FOLLOWED BY) phrase search
3905
- operator. Parentheses can be used to enforce grouping
3906
- of the operators:
3902
+ searched for, and can combine them using the Boolean operators
3903
+ <literal>&</literal> (AND), <literal>|</literal> (OR), and
3904
+ <literal>!</> (NOT), as well as the phrase search operator
3905
+ <literal><-></> (FOLLOWED BY). There is also a variant
3906
+ <literal><<replaceable>N</>></literal> of the FOLLOWED BY
3907
+ operator, where <replaceable>N</> is an integer constant that
3908
+ specifies the distance between the two lexemes being searched
3909
+ for. <literal><-></> is equivalent to <literal><1></>.
3910
+ </para>
3911
+
3912
+ <para>
3913
+ Parentheses can be used to enforce grouping of these operators.
3914
+ In the absence of parentheses, <literal>!</> (NOT) binds most tightly,
3915
+ <literal><-></literal> (FOLLOWED BY) next most tightly, then
3916
+ <literal>&</literal> (AND), with <literal>|</literal> (OR) binding
3917
+ the least tightly.
3918
+ </para>
3919
+
3920
+ <para>
3921
+ Here are some examples:
3907
3922
3908
3923
<programlisting>
3909
3924
SELECT 'fat & rat'::tsquery;
@@ -3920,17 +3935,21 @@ SELECT 'fat & rat & ! cat'::tsquery;
3920
3935
tsquery
3921
3936
------------------------
3922
3937
'fat' & 'rat' & !'cat'
3938
+
3939
+ SELECT '(fat | rat) <-> cat'::tsquery;
3940
+ tsquery
3941
+ -----------------------------------
3942
+ 'fat' <-> 'cat' | 'rat' <-> 'cat'
3923
3943
</programlisting>
3924
3944
3925
- In the absence of parentheses, <literal>!</> (NOT) binds most tightly,
3926
- and <literal>&</literal> (AND) and <literal><-></literal> (FOLLOWED BY)
3927
- both bind more tightly than <literal>|</literal> (OR).
3945
+ The last example demonstrates that <type>tsquery</type> sometimes
3946
+ rearranges nested operators into a logically equivalent formulation.
3928
3947
</para>
3929
3948
3930
3949
<para>
3931
3950
Optionally, lexemes in a <type>tsquery</type> can be labeled with
3932
3951
one or more weight letters, which restricts them to match only
3933
- <type>tsvector</> lexemes withmatching weights:
3952
+ <type>tsvector</> lexemes withone of those weights:
3934
3953
3935
3954
<programlisting>
3936
3955
SELECT 'fat:ab & cat'::tsquery;
@@ -3950,25 +3969,7 @@ SELECT 'super:*'::tsquery;
3950
3969
'super':*
3951
3970
</programlisting>
3952
3971
This query will match any word in a <type>tsvector</> that begins
3953
- with <quote>super</>. Note that prefixes are first processed by
3954
- text search configurations, which means this comparison returns
3955
- true:
3956
- <programlisting>
3957
- SELECT to_tsvector( 'postgraduate' ) @@ to_tsquery( 'postgres:*' );
3958
- ?column?
3959
- ----------
3960
- t
3961
- (1 row)
3962
- </programlisting>
3963
- because <literal>postgres</> gets stemmed to <literal>postgr</>:
3964
- <programlisting>
3965
- SELECT to_tsquery('postgres:*');
3966
- to_tsquery
3967
- ------------
3968
- 'postgr':*
3969
- (1 row)
3970
- </programlisting>
3971
- which then matches <literal>postgraduate</>.
3972
+ with <quote>super</>.
3972
3973
</para>
3973
3974
3974
3975
<para>
@@ -3984,6 +3985,24 @@ SELECT to_tsquery('Fat:ab & Cats');
3984
3985
------------------
3985
3986
'fat':AB & 'cat'
3986
3987
</programlisting>
3988
+
3989
+ Note that <function>to_tsquery</> will process prefixes in the same way
3990
+ as other words, which means this comparison returns true:
3991
+
3992
+ <programlisting>
3993
+ SELECT to_tsvector( 'postgraduate' ) @@ to_tsquery( 'postgres:*' );
3994
+ ?column?
3995
+ ----------
3996
+ t
3997
+ </programlisting>
3998
+ because <literal>postgres</> gets stemmed to <literal>postgr</>:
3999
+ <programlisting>
4000
+ SELECT to_tsvector( 'postgraduate' ), to_tsquery( 'postgres:*' );
4001
+ to_tsvector | to_tsquery
4002
+ ---------------+------------
4003
+ 'postgradu':1 | 'postgr':*
4004
+ </programlisting>
4005
+ which will match the stemmed form of <literal>postgraduate</>.
3987
4006
</para>
3988
4007
3989
4008
</sect2>