dict_xsyn
dict_xsyn (extended synonym dictionary) is an example of an additional full-text search dictionary template. This dictionary type replaces words with their synonym groups, making it possible to search using any synonym.
1. Configuration
A dict_xsyn dictionary accepts the following options:
-
matchorig controls whether the dictionary accepts the original word. Default is true.
-
matchsynonyms controls whether the dictionary accepts synonyms. Default is false.
-
keeporig controls whether the original word is included in the dictionary's output. Default is true.
-
keepsynonyms controls whether synonyms are included in the dictionary's output. Default is true.
-
rules is the base name of the file containing the list of synonyms. This file must be stored in $SHAREDIR/tsearch_data/ (where $SHAREDIR represents the Halo installation's shared data directory). Its name must end with .rules (this is not included in the rules parameter).
The rules file has the following format:
-
Each line represents a synonym group for a single word, which is given first on the line. Synonyms are separated by whitespace, like this: word syn1 syn2 syn3
-
A hash mark (#) is a comment delimiter. It can appear anywhere on a line. The rest of the line will be skipped. For example, see the xsyn_sample.rules file installed in $SHAREDIR/tsearch_data/.
2. Usage
Installing the dict_xsyn extension creates a text search template xsyn_template and a dictionary xsyn based on it, using default parameters. You can modify the parameters, for example:
ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false);
ALTER TEXT SEARCH DICTIONARY Or create new dictionaries based on the template.
To test the dictionary, you can try:
test=## SELECT ts_lexize('xsyn', 'word');
ts_lexize
-----------
(1 row)
ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true);
ALTER TEXT SEARCH DICTIONARY
SELECT ts_lexize('xsyn', 'word');
ts_lexize
-----------------------
{word,syn1,syn2,syn3}
ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false, MATCHSYNONYMS=true);
ALTER TEXT SEARCH DICTIONARY
SELECT ts_lexize('xsyn', 'syn1');
ts_lexize
-----------------------
{syn1,syn2,syn3}
ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true, MATCHORIG=false, KEEPSYNONYMS=false);
ALTER TEXT SEARCH DICTIONARY
SELECT ts_lexize('xsyn', 'syn1');
ts_lexize
-----------------------
{word}
It looks like this: ALTER TEXT SEARCH CONFIGURATION english
ALTER MAPPING FOR word, asciiword WITH xsyn, english_stem;