2010-09-20 22:08:53 +02:00
|
|
|
<!-- doc/src/sgml/dict-int.sgml -->
|
2007-12-06 05:12:10 +01:00
|
|
|
|
2011-05-08 04:29:20 +02:00
|
|
|
<sect1 id="dict-int" xreflabel="dict_int">
|
2023-01-20 20:01:59 +01:00
|
|
|
<title>dict_int —
|
|
|
|
example full-text search dictionary for integers</title>
|
2007-12-06 05:12:10 +01:00
|
|
|
|
2007-12-02 22:13:34 +01:00
|
|
|
<indexterm zone="dict-int">
|
|
|
|
<primary>dict_int</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>dict_int</filename> is an example of an add-on dictionary template
|
2007-12-06 05:12:10 +01:00
|
|
|
for full-text search. The motivation for this example dictionary is to
|
|
|
|
control the indexing of integers (signed and unsigned), allowing such
|
|
|
|
numbers to be indexed while preventing excessive growth in the number of
|
|
|
|
unique words, which greatly affects the performance of searching.
|
2007-12-02 22:13:34 +01:00
|
|
|
</para>
|
|
|
|
|
2020-02-13 21:02:35 +01:00
|
|
|
<para>
|
|
|
|
This module is considered <quote>trusted</quote>, that is, it can be
|
|
|
|
installed by non-superusers who have <literal>CREATE</literal> privilege
|
|
|
|
on the current database.
|
|
|
|
</para>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="dict-int-config">
|
2007-12-02 22:13:34 +01:00
|
|
|
<title>Configuration</title>
|
2007-12-06 05:12:10 +01:00
|
|
|
|
2007-12-02 22:13:34 +01:00
|
|
|
<para>
|
2020-03-08 23:35:06 +01:00
|
|
|
The dictionary accepts three options:
|
2007-12-02 22:13:34 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <literal>maxlen</literal> parameter specifies the maximum number of
|
2007-12-06 05:12:10 +01:00
|
|
|
digits allowed in an integer word. The default value is 6.
|
2007-12-02 22:13:34 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <literal>rejectlong</literal> parameter specifies whether an overlength
|
|
|
|
integer should be truncated or ignored. If <literal>rejectlong</literal> is
|
|
|
|
<literal>false</literal> (the default), the dictionary returns the first
|
|
|
|
<literal>maxlen</literal> digits of the integer. If <literal>rejectlong</literal> is
|
|
|
|
<literal>true</literal>, the dictionary treats an overlength integer as a stop
|
2007-12-06 05:12:10 +01:00
|
|
|
word, so that it will not be indexed. Note that this also means that
|
|
|
|
such an integer cannot be searched for.
|
2007-12-02 22:13:34 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2020-03-08 23:35:06 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The <literal>absval</literal> parameter specifies whether leading
|
|
|
|
<quote><literal>+</literal></quote> or <quote><literal>-</literal></quote>
|
|
|
|
signs should be removed from integer words. The default
|
|
|
|
is <literal>false</literal>. When <literal>true</literal>, the sign is
|
|
|
|
removed before <literal>maxlen</literal> is applied.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2007-12-02 22:13:34 +01:00
|
|
|
</itemizedlist>
|
|
|
|
</sect2>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<sect2 id="dict-int-usage">
|
2007-12-02 22:13:34 +01:00
|
|
|
<title>Usage</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Installing the <literal>dict_int</literal> extension creates a text search
|
|
|
|
template <literal>intdict_template</literal> and a dictionary <literal>intdict</literal>
|
2007-12-02 22:13:34 +01:00
|
|
|
based on it, with the default parameters. You can alter the
|
|
|
|
parameters, for example
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
mydb# ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = 4, REJECTLONG = true);
|
|
|
|
ALTER TEXT SEARCH DICTIONARY
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
or create new dictionaries based on the template.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To test the dictionary, you can try
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
mydb# select ts_lexize('intdict', '12345678');
|
|
|
|
ts_lexize
|
|
|
|
-----------
|
|
|
|
{123456}
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
but real-world usage will involve including it in a text search
|
2017-11-23 15:39:47 +01:00
|
|
|
configuration as described in <xref linkend="textsearch"/>.
|
2007-12-02 22:13:34 +01:00
|
|
|
That might look like this:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
ALTER TEXT SEARCH CONFIGURATION english
|
|
|
|
ALTER MAPPING FOR int, uint WITH intdict;
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|