2 F.13. dict_xsyn — example synonym full-text search dictionary #
7 dict_xsyn (Extended Synonym Dictionary) is an example of an add-on
8 dictionary template for full-text search. This dictionary type replaces
9 words with groups of their synonyms, and so makes it possible to search
10 for a word using any of its synonyms.
12 F.13.1. Configuration #
14 A dict_xsyn dictionary accepts the following options:
15 * matchorig controls whether the original word is accepted by the
16 dictionary. Default is true.
17 * matchsynonyms controls whether the synonyms are accepted by the
18 dictionary. Default is false.
19 * keeporig controls whether the original word is included in the
20 dictionary's output. Default is true.
21 * keepsynonyms controls whether the synonyms are included in the
22 dictionary's output. Default is true.
23 * rules is the base name of the file containing the list of synonyms.
24 This file must be stored in $SHAREDIR/tsearch_data/ (where
25 $SHAREDIR means the PostgreSQL installation's shared-data
26 directory). Its name must end in .rules (which is not to be
27 included in the rules parameter).
29 The rules file has the following format:
30 * Each line represents a group of synonyms for a single word, which
31 is given first on the line. Synonyms are separated by whitespace,
35 * The sharp (#) sign is a comment delimiter. It may appear at any
36 position in a line. The rest of the line will be skipped.
38 Look at xsyn_sample.rules, which is installed in
39 $SHAREDIR/tsearch_data/, for an example.
43 Installing the dict_xsyn extension creates a text search template
44 xsyn_template and a dictionary xsyn based on it, with default
45 parameters. You can alter the parameters, for example
46 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false);
47 ALTER TEXT SEARCH DICTIONARY
49 or create new dictionaries based on the template.
51 To test the dictionary, you can try
52 mydb=# SELECT ts_lexize('xsyn', 'word');
54 -----------------------
57 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true);
58 ALTER TEXT SEARCH DICTIONARY
60 mydb=# SELECT ts_lexize('xsyn', 'word');
62 -----------------------
65 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false, MATCH
67 ALTER TEXT SEARCH DICTIONARY
69 mydb=# SELECT ts_lexize('xsyn', 'syn1');
71 -----------------------
74 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true, MATCHO
75 RIG=false, KEEPSYNONYMS=false);
76 ALTER TEXT SEARCH DICTIONARY
78 mydb=# SELECT ts_lexize('xsyn', 'syn1');
80 -----------------------
83 Real-world usage will involve including it in a text search
84 configuration as described in Chapter 12. That might look like this:
85 ALTER TEXT SEARCH CONFIGURATION english
86 ALTER MAPPING FOR word, asciiword WITH xsyn, english_stem;