]> begriffs open source - ai-pg/blob - full-docs/txt/dict-xsyn.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / dict-xsyn.txt
1
2 F.13. dict_xsyn — example synonym full-text search dictionary #
3
4    F.13.1. Configuration
5    F.13.2. Usage
6
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.
11
12 F.13.1. Configuration #
13
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).
28
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,
32        thus:
33 word syn1 syn2 syn3
34
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.
37
38    Look at xsyn_sample.rules, which is installed in
39    $SHAREDIR/tsearch_data/, for an example.
40
41 F.13.2. Usage #
42
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
48
49    or create new dictionaries based on the template.
50
51    To test the dictionary, you can try
52 mydb=# SELECT ts_lexize('xsyn', 'word');
53       ts_lexize
54 -----------------------
55  {syn1,syn2,syn3}
56
57 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true);
58 ALTER TEXT SEARCH DICTIONARY
59
60 mydb=# SELECT ts_lexize('xsyn', 'word');
61       ts_lexize
62 -----------------------
63  {word,syn1,syn2,syn3}
64
65 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false, MATCH
66 SYNONYMS=true);
67 ALTER TEXT SEARCH DICTIONARY
68
69 mydb=# SELECT ts_lexize('xsyn', 'syn1');
70       ts_lexize
71 -----------------------
72  {syn1,syn2,syn3}
73
74 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true, MATCHO
75 RIG=false, KEEPSYNONYMS=false);
76 ALTER TEXT SEARCH DICTIONARY
77
78 mydb=# SELECT ts_lexize('xsyn', 'syn1');
79       ts_lexize
80 -----------------------
81  {word}
82
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;