@@ -797,13 +797,16 @@ UPDATE tt SET ti =
797
797
<para>
798
798
<productname>PostgreSQL</productname> provides the
799
799
functions <function>to_tsquery</function>,
800
- <function>plainto_tsquery</function>, and
801
- <function>phraseto_tsquery</function>
800
+ <function>plainto_tsquery</function>,
801
+ <function>phraseto_tsquery</function> and
802
+ <function>websearch_to_tsquery</function>
802
803
for converting a query to the <type>tsquery</type> data type.
803
804
<function>to_tsquery</function> offers access to more features
804
805
than either <function>plainto_tsquery</function> or
805
- <function>phraseto_tsquery</function>, but it is less forgiving
806
- about its input.
806
+ <function>phraseto_tsquery</function>, but it is less forgiving about its
807
+ input. <function>websearch_to_tsquery</function> is a simplified version
808
+ of <function>to_tsquery</function> with an alternative syntax, similar
809
+ to the one used by web search engines.
807
810
</para>
808
811
809
812
<indexterm>
@@ -962,6 +965,87 @@ SELECT phraseto_tsquery('english', 'The Fat & Rats:C');
962
965
</screen>
963
966
</para>
964
967
968
+ <synopsis>
969
+ websearch_to_tsquery(<optional> <replaceable class="parameter">config</replaceable> <type>regconfig</type>, </optional> <replaceable class="parameter">querytext</replaceable> <type>text</type>) returns <type>tsquery</type>
970
+ </synopsis>
971
+
972
+ <para>
973
+ <function>websearch_to_tsquery</function> creates a <type>tsquery</type>
974
+ value from <replaceable>querytext</replaceable> using an alternative
975
+ syntax in which simple unformatted text is a valid query.
976
+ Unlike <function>plainto_tsquery</function>
977
+ and <function>phraseto_tsquery</function>, it also recognizes certain
978
+ operators. Moreover, this function should never raise syntax errors,
979
+ which makes it possible to use raw user-supplied input for search.
980
+ The following syntax is supported:
981
+ <itemizedlist spacing="compact" mark="bullet">
982
+ <listitem>
983
+ <para>
984
+ <literal>unquoted text</literal>: text not inside quote marks will be
985
+ converted to terms separated by <literal>&</literal> operators, as
986
+ if processed by
987
+ <function>plainto_tsquery</function>.
988
+ </para>
989
+ </listitem>
990
+ <listitem>
991
+ <para>
992
+ <literal>"quoted text"</literal>: text inside quote marks will be
993
+ converted to terms separated by <literal><-></literal>
994
+ operators, as if processed by <function>phraseto_tsquery</function>.
995
+ </para>
996
+ </listitem>
997
+ <listitem>
998
+ <para>
999
+ <literal>OR</literal>: logical or will be converted to
1000
+ the <literal>|</literal> operator.
1001
+ </para>
1002
+ </listitem>
1003
+ <listitem>
1004
+ <para>
1005
+ <literal>-</literal>: the logical not operator, converted to the
1006
+ the <literal>!</literal> operator.
1007
+ </para>
1008
+ </listitem>
1009
+ </itemizedlist>
1010
+ </para>
1011
+ <para>
1012
+ Examples:
1013
+ <screen>
1014
+ select websearch_to_tsquery('english', 'The fat rats');
1015
+ websearch_to_tsquery
1016
+ -----------------
1017
+ 'fat' & 'rat'
1018
+ (1 row)
1019
+ </screen>
1020
+ <screen>
1021
+ select websearch_to_tsquery('english', '"supernovae stars" -crab');
1022
+ websearch_to_tsquery
1023
+ ----------------------------------
1024
+ 'supernova' <-> 'star' & !'crab'
1025
+ (1 row)
1026
+ </screen>
1027
+ <screen>
1028
+ select websearch_to_tsquery('english', '"sad cat" or "fat rat"');
1029
+ websearch_to_tsquery
1030
+ -----------------------------------
1031
+ 'sad' <-> 'cat' | 'fat' <-> 'rat'
1032
+ (1 row)
1033
+ </screen>
1034
+ <screen>
1035
+ select websearch_to_tsquery('english', 'signal -"segmentation fault"');
1036
+ websearch_to_tsquery
1037
+ ---------------------------------------
1038
+ 'signal' & !( 'segment' <-> 'fault' )
1039
+ (1 row)
1040
+ </screen>
1041
+ <screen>
1042
+ select websearch_to_tsquery('english', '""" )( dummy \\ query <->');
1043
+ websearch_to_tsquery
1044
+ ----------------------
1045
+ 'dummi' & 'queri'
1046
+ (1 row)
1047
+ </screen>
1048
+ </para>
965
1049
</sect2>
966
1050
967
1051
<sect2 id="textsearch-ranking">
0 commit comments