summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/html/textsearch-configuration.html
blob: bbe4178a8933710fa9d099fbd119517e3d0a2e27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>12.7. Configuration Example</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="textsearch-dictionaries.html" title="12.6. Dictionaries" /><link rel="next" href="textsearch-debugging.html" title="12.8. Testing and Debugging Text Search" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">12.7. Configuration Example</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="textsearch-dictionaries.html" title="12.6. Dictionaries">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="textsearch.html" title="Chapter 12. Full Text Search">Up</a></td><th width="60%" align="center">Chapter 12. Full Text Search</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 15.7 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="textsearch-debugging.html" title="12.8. Testing and Debugging Text Search">Next</a></td></tr></table><hr /></div><div class="sect1" id="TEXTSEARCH-CONFIGURATION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">12.7. Configuration Example</h2></div></div></div><p>
    A text search configuration specifies all options necessary to transform a
    document into a <code class="type">tsvector</code>: the parser to use to break text
    into tokens, and the dictionaries to use to transform each token into a
    lexeme.  Every call of
    <code class="function">to_tsvector</code> or <code class="function">to_tsquery</code>
    needs a text search configuration to perform its processing.
    The configuration parameter
    <a class="xref" href="runtime-config-client.html#GUC-DEFAULT-TEXT-SEARCH-CONFIG">default_text_search_config</a>
    specifies the name of the default configuration, which is the
    one used by text search functions if an explicit configuration
    parameter is omitted.
    It can be set in <code class="filename">postgresql.conf</code>, or set for an
    individual session using the <code class="command">SET</code> command.
   </p><p>
    Several predefined text search configurations are available, and
    you can create custom configurations easily.  To facilitate management
    of text search objects, a set of <acronym class="acronym">SQL</acronym> commands
    is available, and there are several <span class="application">psql</span> commands that display information
    about text search objects (<a class="xref" href="textsearch-psql.html" title="12.10. psql Support">Section 12.10</a>).
   </p><p>
    As an example we will create a configuration
    <code class="literal">pg</code>, starting by duplicating the built-in
    <code class="literal">english</code> configuration:

</p><pre class="programlisting">
CREATE TEXT SEARCH CONFIGURATION public.pg ( COPY = pg_catalog.english );
</pre><p>
   </p><p>
    We will use a PostgreSQL-specific synonym list
    and store it in <code class="filename">$SHAREDIR/tsearch_data/pg_dict.syn</code>.
    The file contents look like:

</p><pre class="programlisting">
postgres    pg
pgsql       pg
postgresql  pg
</pre><p>

    We define the synonym dictionary like this:

</p><pre class="programlisting">
CREATE TEXT SEARCH DICTIONARY pg_dict (
    TEMPLATE = synonym,
    SYNONYMS = pg_dict
);
</pre><p>

    Next we register the <span class="productname">Ispell</span> dictionary
    <code class="literal">english_ispell</code>, which has its own configuration files:

</p><pre class="programlisting">
CREATE TEXT SEARCH DICTIONARY english_ispell (
    TEMPLATE = ispell,
    DictFile = english,
    AffFile = english,
    StopWords = english
);
</pre><p>

    Now we can set up the mappings for words in configuration
    <code class="literal">pg</code>:

</p><pre class="programlisting">
ALTER TEXT SEARCH CONFIGURATION pg
    ALTER MAPPING FOR asciiword, asciihword, hword_asciipart,
                      word, hword, hword_part
    WITH pg_dict, english_ispell, english_stem;
</pre><p>

    We choose not to index or search some token types that the built-in
    configuration does handle:

</p><pre class="programlisting">
ALTER TEXT SEARCH CONFIGURATION pg
    DROP MAPPING FOR email, url, url_path, sfloat, float;
</pre><p>
   </p><p>
    Now we can test our configuration:

</p><pre class="programlisting">
SELECT * FROM ts_debug('public.pg', '
PostgreSQL, the highly scalable, SQL compliant, open source object-relational
database management system, is now undergoing beta testing of the next
version of our software.
');
</pre><p>
   </p><p>
    The next step is to set the session to use the new configuration, which was
    created in the <code class="literal">public</code> schema:

</p><pre class="screen">
=&gt; \dF
   List of text search configurations
 Schema  | Name | Description
---------+------+-------------
 public  | pg   |

SET default_text_search_config = 'public.pg';
SET

SHOW default_text_search_config;
 default_text_search_config
----------------------------
 public.pg
</pre><p>
  </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="textsearch-dictionaries.html" title="12.6. Dictionaries">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="textsearch.html" title="Chapter 12. Full Text Search">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="textsearch-debugging.html" title="12.8. Testing and Debugging Text Search">Next</a></td></tr><tr><td width="40%" align="left" valign="top">12.6. Dictionaries </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 15.7 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 12.8. Testing and Debugging Text Search</td></tr></table></div></body></html>