mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Add websearch_to_tsquery
Error-tolerant conversion function with web-like syntax for search query, it simplifies constraining search engine with close to habitual interface for users. Bump catalog version Authors: Victor Drobny, Dmitry Ivanov with editorization by me Reviewed by: Aleksander Alekseev, Tomas Vondra, Thomas Munro, Aleksandr Parfenov Discussion: https://www.postgresql.org/message-id/flat/fe931111ff7e9ad79196486ada79e268@postgrespro.ru
This commit is contained in:
@ -9630,6 +9630,18 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
|
||||
<entry><literal>phraseto_tsquery('english', 'The Fat Rats')</literal></entry>
|
||||
<entry><literal>'fat' <-> 'rat'</literal></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>
|
||||
<indexterm>
|
||||
<primary>websearch_to_tsquery</primary>
|
||||
</indexterm>
|
||||
<literal><function>websearch_to_tsquery(<optional> <replaceable class="parameter">config</replaceable> <type>regconfig</type> , </optional> <replaceable class="parameter">query</replaceable> <type>text</type>)</function></literal>
|
||||
</entry>
|
||||
<entry><type>tsquery</type></entry>
|
||||
<entry>produce <type>tsquery</type> from a web search style query</entry>
|
||||
<entry><literal>websearch_to_tsquery('english', '"fat rat" or rat')</literal></entry>
|
||||
<entry><literal>'fat' <-> 'rat' | 'rat'</literal></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>
|
||||
<indexterm>
|
||||
|
@ -797,13 +797,16 @@ UPDATE tt SET ti =
|
||||
<para>
|
||||
<productname>PostgreSQL</productname> provides the
|
||||
functions <function>to_tsquery</function>,
|
||||
<function>plainto_tsquery</function>, and
|
||||
<function>phraseto_tsquery</function>
|
||||
<function>plainto_tsquery</function>,
|
||||
<function>phraseto_tsquery</function> and
|
||||
<function>websearch_to_tsquery</function>
|
||||
for converting a query to the <type>tsquery</type> data type.
|
||||
<function>to_tsquery</function> offers access to more features
|
||||
than either <function>plainto_tsquery</function> or
|
||||
<function>phraseto_tsquery</function>, but it is less forgiving
|
||||
about its input.
|
||||
<function>phraseto_tsquery</function>, but it is less forgiving about its
|
||||
input. <function>websearch_to_tsquery</function> is a simplified version
|
||||
of <function>to_tsquery</function> with an alternative syntax, similar
|
||||
to the one used by web search engines.
|
||||
</para>
|
||||
|
||||
<indexterm>
|
||||
@ -962,6 +965,87 @@ SELECT phraseto_tsquery('english', 'The Fat & Rats:C');
|
||||
</screen>
|
||||
</para>
|
||||
|
||||
<synopsis>
|
||||
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>
|
||||
</synopsis>
|
||||
|
||||
<para>
|
||||
<function>websearch_to_tsquery</function> creates a <type>tsquery</type>
|
||||
value from <replaceable>querytext</replaceable> using an alternative
|
||||
syntax in which simple unformatted text is a valid query.
|
||||
Unlike <function>plainto_tsquery</function>
|
||||
and <function>phraseto_tsquery</function>, it also recognizes certain
|
||||
operators. Moreover, this function should never raise syntax errors,
|
||||
which makes it possible to use raw user-supplied input for search.
|
||||
The following syntax is supported:
|
||||
<itemizedlist spacing="compact" mark="bullet">
|
||||
<listitem>
|
||||
<para>
|
||||
<literal>unquoted text</literal>: text not inside quote marks will be
|
||||
converted to terms separated by <literal>&</literal> operators, as
|
||||
if processed by
|
||||
<function>plainto_tsquery</function>.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<literal>"quoted text"</literal>: text inside quote marks will be
|
||||
converted to terms separated by <literal><-></literal>
|
||||
operators, as if processed by <function>phraseto_tsquery</function>.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<literal>OR</literal>: logical or will be converted to
|
||||
the <literal>|</literal> operator.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<literal>-</literal>: the logical not operator, converted to the
|
||||
the <literal>!</literal> operator.
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
Examples:
|
||||
<screen>
|
||||
select websearch_to_tsquery('english', 'The fat rats');
|
||||
websearch_to_tsquery
|
||||
-----------------
|
||||
'fat' & 'rat'
|
||||
(1 row)
|
||||
</screen>
|
||||
<screen>
|
||||
select websearch_to_tsquery('english', '"supernovae stars" -crab');
|
||||
websearch_to_tsquery
|
||||
----------------------------------
|
||||
'supernova' <-> 'star' & !'crab'
|
||||
(1 row)
|
||||
</screen>
|
||||
<screen>
|
||||
select websearch_to_tsquery('english', '"sad cat" or "fat rat"');
|
||||
websearch_to_tsquery
|
||||
-----------------------------------
|
||||
'sad' <-> 'cat' | 'fat' <-> 'rat'
|
||||
(1 row)
|
||||
</screen>
|
||||
<screen>
|
||||
select websearch_to_tsquery('english', 'signal -"segmentation fault"');
|
||||
websearch_to_tsquery
|
||||
---------------------------------------
|
||||
'signal' & !( 'segment' <-> 'fault' )
|
||||
(1 row)
|
||||
</screen>
|
||||
<screen>
|
||||
select websearch_to_tsquery('english', '""" )( dummy \\ query <->');
|
||||
websearch_to_tsquery
|
||||
----------------------
|
||||
'dummi' & 'queri'
|
||||
(1 row)
|
||||
</screen>
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="textsearch-ranking">
|
||||
|
Reference in New Issue
Block a user