2010-09-20 22:08:53 +02:00
|
|
|
<!-- doc/src/sgml/unaccent.sgml -->
|
2010-08-25 04:12:00 +02:00
|
|
|
|
2009-08-18 12:34:39 +02:00
|
|
|
<sect1 id="unaccent">
|
|
|
|
<title>unaccent</title>
|
|
|
|
|
|
|
|
<indexterm zone="unaccent">
|
|
|
|
<primary>unaccent</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2010-08-25 04:12:00 +02:00
|
|
|
<filename>unaccent</> is a text search dictionary that removes accents
|
|
|
|
(diacritic signs) from lexemes.
|
|
|
|
It's a filtering dictionary, which means its output is
|
|
|
|
always passed to the next dictionary (if any), unlike the normal
|
|
|
|
behavior of dictionaries. This allows accent-insensitive processing
|
|
|
|
for full text search.
|
2009-08-18 12:34:39 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2010-08-25 04:12:00 +02:00
|
|
|
The current implementation of <filename>unaccent</> cannot be used as a
|
|
|
|
normalizing dictionary for the <filename>thesaurus</filename> dictionary.
|
2009-08-18 12:34:39 +02:00
|
|
|
</para>
|
2010-08-25 04:12:00 +02:00
|
|
|
|
2009-08-18 12:34:39 +02:00
|
|
|
<sect2>
|
|
|
|
<title>Configuration</title>
|
|
|
|
|
|
|
|
<para>
|
2010-08-25 04:12:00 +02:00
|
|
|
An <literal>unaccent</> dictionary accepts the following options:
|
2009-08-18 12:34:39 +02:00
|
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>RULES</> is the base name of the file containing the list of
|
|
|
|
translation rules. This file must be stored in
|
|
|
|
<filename>$SHAREDIR/tsearch_data/</> (where <literal>$SHAREDIR</> means
|
|
|
|
the <productname>PostgreSQL</> installation's shared-data directory).
|
|
|
|
Its name must end in <literal>.rules</> (which is not to be included in
|
|
|
|
the <literal>RULES</> parameter).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
|
|
The rules file has the following format:
|
|
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2010-08-25 04:12:00 +02:00
|
|
|
Each line represents a pair, consisting of a character with accent
|
|
|
|
followed by a character without accent. The first is translated into
|
|
|
|
the second. For example,
|
2010-07-29 21:34:41 +02:00
|
|
|
<programlisting>
|
2009-08-20 14:12:37 +02:00
|
|
|
À A
|
|
|
|
Á A
|
2010-08-25 04:12:00 +02:00
|
|
|
 A
|
2009-08-20 14:12:37 +02:00
|
|
|
à A
|
2010-08-25 04:12:00 +02:00
|
|
|
Ä A
|
|
|
|
Å A
|
|
|
|
Æ A
|
2010-07-29 21:34:41 +02:00
|
|
|
</programlisting>
|
2009-08-18 12:34:39 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
|
|
|
|
<para>
|
2010-08-25 04:12:00 +02:00
|
|
|
A more complete example, which is directly useful for most European
|
|
|
|
languages, can be found in <filename>unaccent.rules</>, which is installed
|
|
|
|
in <filename>$SHAREDIR/tsearch_data/</> when the <filename>unaccent</>
|
|
|
|
module is installed.
|
2009-08-18 12:34:39 +02:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Usage</title>
|
|
|
|
|
|
|
|
<para>
|
2011-02-14 07:10:44 +01:00
|
|
|
Installing the <literal>unaccent</> extension creates a text
|
2010-08-25 04:12:00 +02:00
|
|
|
search template <literal>unaccent</> and a dictionary <literal>unaccent</>
|
2010-08-25 23:42:55 +02:00
|
|
|
based on it. The <literal>unaccent</> dictionary has the default
|
|
|
|
parameter setting <literal>RULES='unaccent'</>, which makes it immediately
|
|
|
|
usable with the standard <filename>unaccent.rules</> file.
|
|
|
|
If you wish, you can alter the parameter, for example
|
2009-08-18 12:34:39 +02:00
|
|
|
|
|
|
|
<programlisting>
|
2010-08-25 04:12:00 +02:00
|
|
|
mydb=# ALTER TEXT SEARCH DICTIONARY unaccent (RULES='my_rules');
|
2009-08-18 12:34:39 +02:00
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
or create new dictionaries based on the template.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2010-08-25 04:12:00 +02:00
|
|
|
To test the dictionary, you can try:
|
2009-08-18 12:34:39 +02:00
|
|
|
<programlisting>
|
2010-08-25 04:12:00 +02:00
|
|
|
mydb=# select ts_lexize('unaccent','Hôtel');
|
|
|
|
ts_lexize
|
2009-08-18 12:34:39 +02:00
|
|
|
-----------
|
|
|
|
{Hotel}
|
|
|
|
(1 row)
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
2010-08-25 04:12:00 +02:00
|
|
|
|
2009-08-18 12:34:39 +02:00
|
|
|
<para>
|
2010-08-25 04:12:00 +02:00
|
|
|
Here is an example showing how to insert the
|
|
|
|
<filename>unaccent</> dictionary into a text search configuration:
|
2009-08-18 12:34:39 +02:00
|
|
|
<programlisting>
|
2010-08-25 04:12:00 +02:00
|
|
|
mydb=# CREATE TEXT SEARCH CONFIGURATION fr ( COPY = french );
|
|
|
|
mydb=# ALTER TEXT SEARCH CONFIGURATION fr
|
2009-08-20 14:12:37 +02:00
|
|
|
ALTER MAPPING FOR hword, hword_part, word
|
|
|
|
WITH unaccent, french_stem;
|
2010-08-25 04:12:00 +02:00
|
|
|
mydb=# select to_tsvector('fr','Hôtels de la Mer');
|
|
|
|
to_tsvector
|
2009-08-18 12:34:39 +02:00
|
|
|
-------------------
|
|
|
|
'hotel':1 'mer':4
|
|
|
|
(1 row)
|
|
|
|
|
2010-08-25 04:12:00 +02:00
|
|
|
mydb=# select to_tsvector('fr','Hôtel de la Mer') @@ to_tsquery('fr','Hotels');
|
|
|
|
?column?
|
2009-08-18 12:34:39 +02:00
|
|
|
----------
|
|
|
|
t
|
|
|
|
(1 row)
|
2010-08-25 04:12:00 +02:00
|
|
|
|
|
|
|
mydb=# select ts_headline('fr','Hôtel de la Mer',to_tsquery('fr','Hotels'));
|
|
|
|
ts_headline
|
2009-08-18 12:34:39 +02:00
|
|
|
------------------------
|
2010-08-25 04:12:00 +02:00
|
|
|
<b>Hôtel</b> de la Mer
|
2009-08-18 12:34:39 +02:00
|
|
|
(1 row)
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
2010-08-25 04:12:00 +02:00
|
|
|
<title>Functions</title>
|
2009-08-18 12:34:39 +02:00
|
|
|
|
|
|
|
<para>
|
2010-08-25 04:12:00 +02:00
|
|
|
The <function>unaccent()</> function removes accents (diacritic signs) from
|
|
|
|
a given string. Basically, it's a wrapper around the
|
|
|
|
<filename>unaccent</> dictionary, but it can be used outside normal
|
|
|
|
text search contexts.
|
2009-08-18 12:34:39 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>unaccent</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2010-07-29 21:34:41 +02:00
|
|
|
<synopsis>
|
2010-08-25 04:12:00 +02:00
|
|
|
unaccent(<optional><replaceable class="PARAMETER">dictionary</replaceable>, </optional> <replaceable class="PARAMETER">string</replaceable>) returns <type>text</type>
|
2010-07-29 21:34:41 +02:00
|
|
|
</synopsis>
|
2009-08-18 12:34:39 +02:00
|
|
|
|
|
|
|
<para>
|
2010-08-25 04:12:00 +02:00
|
|
|
For example:
|
2009-08-18 12:34:39 +02:00
|
|
|
<programlisting>
|
2010-08-25 04:12:00 +02:00
|
|
|
SELECT unaccent('unaccent', 'Hôtel');
|
|
|
|
SELECT unaccent('Hôtel');
|
2009-08-18 12:34:39 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|