Home Explore Blog CI



postgresql

13th chunk of `doc/src/sgml/textsearch.sgml`
76e359af0e9e949d2b79ecd5e6ebe9e486f839201b23335f0000000100000fa4

-----------------
 'fat' & 'rat'
</screen>

    Note that <function>plainto_tsquery</function> will not
    recognize <type>tsquery</type> operators, weight labels,
    or prefix-match labels in its input:

<screen>
SELECT plainto_tsquery('english', 'The Fat &amp; Rats:C');
   plainto_tsquery
---------------------
 'fat' &amp; 'rat' &amp; 'c'
</screen>

    Here, all the input punctuation was discarded.
   </para>

   <indexterm>
    <primary>phraseto_tsquery</primary>
   </indexterm>

<synopsis>
phraseto_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>phraseto_tsquery</function> behaves much like
    <function>plainto_tsquery</function>, except that it inserts
    the <literal>&lt;-&gt;</literal> (FOLLOWED BY) operator between
    surviving words instead of the <literal>&amp;</literal> (AND) operator.
    Also, stop words are not simply discarded, but are accounted for by
    inserting <literal>&lt;<replaceable>N</replaceable>&gt;</literal> operators rather
    than <literal>&lt;-&gt;</literal> operators.  This function is useful
    when searching for exact lexeme sequences, since the FOLLOWED BY
    operators check lexeme order not just the presence of all the lexemes.
   </para>

   <para>
    Example:

<screen>
SELECT phraseto_tsquery('english', 'The Fat Rats');
 phraseto_tsquery
------------------
 'fat' &lt;-&gt; 'rat'
</screen>

    Like <function>plainto_tsquery</function>, the
    <function>phraseto_tsquery</function> function will not
    recognize <type>tsquery</type> operators, weight labels,
    or prefix-match labels in its input:

<screen>
SELECT phraseto_tsquery('english', 'The Fat &amp; Rats:C');
      phraseto_tsquery
-----------------------------
 'fat' &lt;-&gt; 'rat' &lt;-&gt; '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 will 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>&amp;</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>&lt;-&gt;</literal>
        operators, as if processed by <function>phraseto_tsquery</function>.
      </para>
     </listitem>
     <listitem>
      <para>
       <literal>OR</literal>: the word <quote>or</quote> will be converted to
       the <literal>|</literal> operator.
      </para>
     </listitem>
     <listitem>
      <para>
       <literal>-</literal>: a dash will be converted to
       the <literal>!</literal> operator.
      </para>
     </listitem>
    </itemizedlist>

    Other punctuation is ignored.  So
    like <function>plainto_tsquery</function>
    and <function>phraseto_tsquery</function>,
    the <function>websearch_to_tsquery</function> function will not
    recognize <type>tsquery</type> operators, weight labels, or prefix-match
    labels in its input.

Title: phraseto_tsquery and websearch_to_tsquery functions
Summary
This section details the `phraseto_tsquery` and `websearch_to_tsquery` functions. `phraseto_tsquery` is similar to `plainto_tsquery` but uses the FOLLOWED BY operator (`<->`) instead of AND. It also accounts for stop words by inserting `<N>` operators. Like `plainto_tsquery`, it doesn't recognize `tsquery` operators, weight labels, or prefix-match labels. `websearch_to_tsquery` creates a `tsquery` using an alternative syntax suitable for web search, never raising syntax errors. It converts unquoted text to AND-separated terms, quoted text to FOLLOWED BY-separated terms, and recognizes `OR` and `-` operators. Other punctuation is ignored, and it doesn't recognize `tsquery` operators, weight labels, or prefix-match labels.