2 12.7. Configuration Example #
4 A text search configuration specifies all options necessary to
5 transform a document into a tsvector: the parser to use to break text
6 into tokens, and the dictionaries to use to transform each token into a
7 lexeme. Every call of to_tsvector or to_tsquery needs a text search
8 configuration to perform its processing. The configuration parameter
9 default_text_search_config specifies the name of the default
10 configuration, which is the one used by text search functions if an
11 explicit configuration parameter is omitted. It can be set in
12 postgresql.conf, or set for an individual session using the SET
15 Several predefined text search configurations are available, and you
16 can create custom configurations easily. To facilitate management of
17 text search objects, a set of SQL commands is available, and there are
18 several psql commands that display information about text search
19 objects (Section 12.10).
21 As an example we will create a configuration pg, starting by
22 duplicating the built-in english configuration:
23 CREATE TEXT SEARCH CONFIGURATION public.pg ( COPY = pg_catalog.english );
25 We will use a PostgreSQL-specific synonym list and store it in
26 $SHAREDIR/tsearch_data/pg_dict.syn. The file contents look like:
31 We define the synonym dictionary like this:
32 CREATE TEXT SEARCH DICTIONARY pg_dict (
37 Next we register the Ispell dictionary english_ispell, which has its
38 own configuration files:
39 CREATE TEXT SEARCH DICTIONARY english_ispell (
46 Now we can set up the mappings for words in configuration pg:
47 ALTER TEXT SEARCH CONFIGURATION pg
48 ALTER MAPPING FOR asciiword, asciihword, hword_asciipart,
49 word, hword, hword_part
50 WITH pg_dict, english_ispell, english_stem;
52 We choose not to index or search some token types that the built-in
53 configuration does handle:
54 ALTER TEXT SEARCH CONFIGURATION pg
55 DROP MAPPING FOR email, url, url_path, sfloat, float;
57 Now we can test our configuration:
58 SELECT * FROM ts_debug('public.pg', '
59 PostgreSQL, the highly scalable, SQL compliant, open source object-relational
60 database management system, is now undergoing beta testing of the next
61 version of our software.
64 The next step is to set the session to use the new configuration, which
65 was created in the public schema:
67 List of text search configurations
68 Schema | Name | Description
69 ---------+------+-------------
72 SET default_text_search_config = 'public.pg';
75 SHOW default_text_search_config;
76 default_text_search_config
77 ----------------------------