Home Explore Blog CI



postgresql

3rd chunk of `doc/src/sgml/unaccent.sgml`
61522a5efb9bb09bbc9e66d9f987ae94674e3bc2363880e90000000100000caa
  </itemizedlist>

  <para>
   A more complete example, which is directly useful for most European
   languages, can be found in <filename>unaccent.rules</filename>, which is installed
   in <filename>$SHAREDIR/tsearch_data/</filename> when the <filename>unaccent</filename>
   module is installed.  This rules file translates characters with accents
   to the same characters without accents, and it also expands ligatures
   into the equivalent series of simple characters (for example, &AElig; to
   AE).
  </para>
 </sect2>

 <sect2 id="unaccent-usage">
  <title>Usage</title>

  <para>
   Installing the <literal>unaccent</literal> extension creates a text
   search template <literal>unaccent</literal> and a dictionary <literal>unaccent</literal>
   based on it.  The <literal>unaccent</literal> dictionary has the default
   parameter setting <literal>RULES='unaccent'</literal>, which makes it immediately
   usable with the standard <filename>unaccent.rules</filename> file.
   If you wish, you can alter the parameter, for example

<programlisting>
mydb=# ALTER TEXT SEARCH DICTIONARY unaccent (RULES='my_rules');
</programlisting>

   or create new dictionaries based on the template.
  </para>

  <para>
   To test the dictionary, you can try:
<programlisting>
mydb=# select ts_lexize('unaccent','H&ocirc;tel');
 ts_lexize
-----------
 {Hotel}
(1 row)
</programlisting>
  </para>

  <para>
   Here is an example showing how to insert the
   <filename>unaccent</filename> dictionary into a text search configuration:
<programlisting>
mydb=# CREATE TEXT SEARCH CONFIGURATION fr ( COPY = french );
mydb=# ALTER TEXT SEARCH CONFIGURATION fr
        ALTER MAPPING FOR hword, hword_part, word
        WITH unaccent, french_stem;
mydb=# select to_tsvector('fr','H&ocirc;tels de la Mer');
    to_tsvector
-------------------
 'hotel':1 'mer':4
(1 row)

mydb=# select to_tsvector('fr','H&ocirc;tel de la Mer') @@ to_tsquery('fr','Hotels');
 ?column?
----------
 t
(1 row)

mydb=# select ts_headline('fr','H&ocirc;tel de la Mer',to_tsquery('fr','Hotels'));
      ts_headline
------------------------
 &lt;b&gt;H&ocirc;tel&lt;/b&gt; de la Mer
(1 row)
</programlisting>
  </para>
 </sect2>

 <sect2 id="unaccent-functions">
 <title>Functions</title>

 <para>
  The <function>unaccent()</function> function removes accents (diacritic signs) from
  a given string.  Basically, it's a wrapper around
  <filename>unaccent</filename>-type dictionaries, but it can be used outside normal
  text search contexts.
 </para>

 <indexterm>
  <primary>unaccent</primary>
 </indexterm>

<synopsis>
unaccent(<optional><replaceable class="parameter">dictionary</replaceable> <type>regdictionary</type>, </optional> <replaceable class="parameter">string</replaceable> <type>text</type>) returns <type>text</type>
</synopsis>

 <para>
  If the <replaceable class="parameter">dictionary</replaceable> argument is
  omitted, the text search dictionary named <literal>unaccent</literal> and
  appearing in the same schema as the <function>unaccent()</function>
  function itself is used.
 </para>

 <para>
  For example:
<programlisting>
SELECT unaccent('unaccent', 'H&ocirc;tel');
SELECT unaccent('H&ocirc;tel');
</programlisting>
 </para>
 </sect2>

</sect1>

Title: Using the Unaccent Dictionary and Functions
Summary
The unaccent dictionary and functions provide a way to remove accents and perform text search operations, with examples showing how to install, alter, and use the dictionary, as well as how to use the unaccent function to remove accents from strings, and how to integrate it into text search configurations.