Home Explore Blog CI



postgresql

5th chunk of `doc/src/sgml/pgtrgm.sgml`
5ca92af28b106783f1a1738be37bf55a5902958471398f430000000100000fa2

      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <type>text</type> <literal>&lt;&lt;&lt;-&gt;</literal> <type>text</type>
        <returnvalue>real</returnvalue>
       </para>
       <para>
        Returns the <quote>distance</quote> between the arguments, that is
        one minus the <function>strict_word_similarity()</function> value.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <type>text</type> <literal>&lt;-&gt;&gt;&gt;</literal> <type>text</type>
        <returnvalue>real</returnvalue>
       </para>
       <para>
        Commutator of the <literal>&lt;&lt;&lt;-&gt;</literal> operator.
       </para></entry>
      </row>
     </tbody>
    </tgroup>
  </table>
 </sect2>

 <sect2 id="pgtrgm-guc">
  <title>GUC Parameters</title>

  <variablelist>
   <varlistentry id="guc-pgtrgm-similarity-threshold" xreflabel="pg_trgm.similarity_threshold">
    <term>
     <varname>pg_trgm.similarity_threshold</varname> (<type>real</type>)
     <indexterm>
      <primary><varname>pg_trgm.similarity_threshold</varname> configuration parameter</primary>
     </indexterm>
    </term>
    <listitem>
     <para>
      Sets the current similarity threshold that is used by the <literal>%</literal>
      operator.  The threshold must be between 0 and 1 (default is 0.3).
     </para>
    </listitem>
   </varlistentry>
   <varlistentry id="guc-pgtrgm-word-similarity-threshold" xreflabel="pg_trgm.word_similarity_threshold">
    <term>
     <varname>pg_trgm.word_similarity_threshold</varname> (<type>real</type>)
     <indexterm>
      <primary><varname>pg_trgm.word_similarity_threshold</varname> configuration parameter</primary>
     </indexterm>
    </term>
    <listitem>
     <para>
      Sets the current word similarity threshold that is used by the
      <literal>&lt;%</literal> and <literal>%&gt;</literal> operators.  The threshold
      must be between 0 and 1 (default is 0.6).
     </para>
    </listitem>
   </varlistentry>
   <varlistentry id="guc-pgtrgm-strict-word-similarity-threshold" xreflabel="pg_trgm.strict_word_similarity_threshold">
    <term>
     <varname>pg_trgm.strict_word_similarity_threshold</varname> (<type>real</type>)
     <indexterm>
      <primary><varname>pg_trgm.strict_word_similarity_threshold</varname> configuration parameter</primary>
     </indexterm>
    </term>
    <listitem>
     <para>
      Sets the current strict word similarity threshold that is used by the
      <literal>&lt;&lt;%</literal> and <literal>%&gt;&gt;</literal> operators.  The threshold
      must be between 0 and 1 (default is 0.5).
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </sect2>

 <sect2 id="pgtrgm-index">
  <title>Index Support</title>

  <para>
   The <filename>pg_trgm</filename> module provides GiST and GIN index
   operator classes that allow you to create an index over a text column for
   the purpose of very fast similarity searches.  These index types support
   the above-described similarity operators, and additionally support
   trigram-based index searches for <literal>LIKE</literal>, <literal>ILIKE</literal>,
   <literal>~</literal>, <literal>~*</literal> and <literal>=</literal> queries.
   The similarity comparisons are case-insensitive in a default build of
   <filename>pg_trgm</filename>.
   Inequality operators are not supported.
   Note that those indexes may not be as efficient as regular B-tree indexes
   for equality operator.
  </para>

  <para>
   Example:

<programlisting>
CREATE TABLE test_trgm (t text);
CREATE INDEX trgm_idx ON test_trgm USING GIST (t gist_trgm_ops);
</programlisting>
or
<programlisting>
CREATE INDEX trgm_idx ON test_trgm USING GIN (t gin_trgm_ops);
</programlisting>
  </para>

  <para>
   <literal>gist_trgm_ops</literal> GiST opclass approximates a set of
   trigrams as a bitmap signature.  Its optional integer parameter
   <literal>siglen</literal>

Title: pg_trgm GUC Parameters and Index Support
Summary
This section describes the configurable parameters (GUCs) for the `pg_trgm` extension, including `pg_trgm.similarity_threshold`, `pg_trgm.word_similarity_threshold`, and `pg_trgm.strict_word_similarity_threshold`. It also explains how to create GiST and GIN indexes on text columns to enable fast similarity searches using trigrams and support for LIKE, ILIKE, ~, ~*, and = queries. The example shows the syntax for creating such indexes.