Home Explore Blog CI



postgresql

14th chunk of `doc/src/sgml/textsearch.sgml`
1dc3eea2cfb210ae63ba8b9a323794798d7e6c4b6e9775570000000100000fa7
 <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.
   </para>

   <para>
    Examples:
<screen>
SELECT websearch_to_tsquery('english', 'The fat rats');
 websearch_to_tsquery
----------------------
 'fat' &amp; 'rat'
(1 row)

SELECT websearch_to_tsquery('english', '"supernovae stars" -crab');
       websearch_to_tsquery
----------------------------------
 'supernova' &lt;-&gt; 'star' &amp; !'crab'
(1 row)

SELECT websearch_to_tsquery('english', '"sad cat" or "fat rat"');
       websearch_to_tsquery
-----------------------------------
 'sad' &lt;-&gt; 'cat' | 'fat' &lt;-&gt; 'rat'
(1 row)

SELECT websearch_to_tsquery('english', 'signal -"segmentation fault"');
         websearch_to_tsquery
---------------------------------------
 'signal' &amp; !( 'segment' &lt;-&gt; 'fault' )
(1 row)

SELECT websearch_to_tsquery('english', '""" )( dummy \\ query &lt;-&gt;');
 websearch_to_tsquery
----------------------
 'dummi' &amp; 'queri'
(1 row)
</screen>
    </para>
  </sect2>

  <sect2 id="textsearch-ranking">
   <title>Ranking Search Results</title>

   <para>
    Ranking attempts to measure how relevant documents are to a particular
    query, so that when there are many matches the most relevant ones can be
    shown first.  <productname>PostgreSQL</productname> provides two
    predefined ranking functions, which take into account lexical, proximity,
    and structural information; that is, they consider how often the query
    terms appear in the document, how close together the terms are in the
    document, and how important is the part of the document where they occur.
    However, the concept of relevancy is vague and very application-specific.
    Different applications might require additional information for ranking,
    e.g., document modification time.  The built-in ranking functions are only
    examples.  You can write your own ranking functions and/or combine their
    results with additional factors to fit your specific needs.
   </para>

   <para>
    The two ranking functions currently available are:

    <variablelist>

     <varlistentry>

      <term>
       <indexterm>
        <primary>ts_rank</primary>
       </indexterm>

       <literal>ts_rank(<optional> <replaceable class="parameter">weights</replaceable> <type>float4[]</type>, </optional> <replaceable class="parameter">vector</replaceable> <type>tsvector</type>, <replaceable class="parameter">query</replaceable> <type>tsquery</type> <optional>, <replaceable class="parameter">normalization</replaceable> <type>integer</type> </optional>) returns <type>float4</type></literal>
      </term>

      <listitem>
       <para>
        Ranks vectors based on the frequency of their matching lexemes.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>

      <term>
      <indexterm>
       <primary>ts_rank_cd</primary>
      </indexterm>

       <literal>ts_rank_cd(<optional> <replaceable class="parameter">weights</replaceable> <type>float4[]</type>, </optional> <replaceable class="parameter">vector</replaceable>

Title: websearch_to_tsquery examples and Ranking Search Results
Summary
This section provides examples of using the `websearch_to_tsquery` function, demonstrating how it handles unquoted text, quoted text, OR operators, and negation. It also introduces the concept of ranking search results, which involves measuring the relevance of documents to a particular query. PostgreSQL provides two predefined ranking functions, `ts_rank` and `ts_rank_cd`, that take into account lexical, proximity, and structural information. These functions serve as examples, and users can create their own ranking functions tailored to their specific needs.