1
<!-- doc/src/sgml/dict-xsyn.sgml -->
4
<title>dict_xsyn</title>
6
<indexterm zone="dict-xsyn">
7
<primary>dict_xsyn</primary>
11
<filename>dict_xsyn</> (Extended Synonym Dictionary) is an example of an
12
add-on dictionary template for full-text search. This dictionary type
13
replaces words with groups of their synonyms, and so makes it possible to
14
search for a word using any of its synonyms.
18
<title>Configuration</title>
21
A <literal>dict_xsyn</> dictionary accepts the following options:
26
<literal>matchorig</> controls whether the original word is accepted by
27
the dictionary. Default is <literal>true</>.
32
<literal>matchsynonyms</> controls whether the synonyms are
33
accepted by the dictionary. Default is <literal>false</>.
38
<literal>keeporig</> controls whether the original word is included in
39
the dictionary's output. Default is <literal>true</>.
44
<literal>keepsynonyms</> controls whether the synonyms are included in
45
the dictionary's output. Default is <literal>true</>.
50
<literal>rules</> is the base name of the file containing the list of
51
synonyms. This file must be stored in
52
<filename>$SHAREDIR/tsearch_data/</> (where <literal>$SHAREDIR</> means
53
the <productname>PostgreSQL</> installation's shared-data directory).
54
Its name must end in <literal>.rules</> (which is not to be included in
55
the <literal>rules</> parameter).
60
The rules file has the following format:
65
Each line represents a group of synonyms for a single word, which is
66
given first on the line. Synonyms are separated by whitespace, thus:
74
The sharp (<literal>#</>) sign is a comment delimiter. It may appear at
75
any position in a line. The rest of the line will be skipped.
81
Look at <filename>xsyn_sample.rules</>, which is installed in
82
<filename>$SHAREDIR/tsearch_data/</>, for an example.
90
Installing the <literal>dict_xsyn</> extension creates a text search
91
template <literal>xsyn_template</> and a dictionary <literal>xsyn</>
92
based on it, with default parameters. You can alter the
93
parameters, for example
96
mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false);
97
ALTER TEXT SEARCH DICTIONARY
100
or create new dictionaries based on the template.
104
To test the dictionary, you can try
107
mydb=# SELECT ts_lexize('xsyn', 'word');
109
-----------------------
112
mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true);
113
ALTER TEXT SEARCH DICTIONARY
115
mydb=# SELECT ts_lexize('xsyn', 'word');
117
-----------------------
118
{word,syn1,syn2,syn3}
120
mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false, MATCHSYNONYMS=true);
121
ALTER TEXT SEARCH DICTIONARY
123
mydb=# SELECT ts_lexize('xsyn', 'syn1');
125
-----------------------
128
mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true, MATCHORIG=false, KEEPSYNONYMS=false);
129
ALTER TEXT SEARCH DICTIONARY
131
mydb=# SELECT ts_lexize('xsyn', 'syn1');
133
-----------------------
137
Real-world usage will involve including it in a text search
138
configuration as described in <xref linkend="textsearch">.
139
That might look like this:
142
ALTER TEXT SEARCH CONFIGURATION english
143
ALTER MAPPING FOR word, asciiword WITH xsyn, english_stem;