Synonym Dictionary
A synonym dictionary is used to define, identify, and convert synonyms of tokens. Phrases are not supported (use the thesaurus dictionary in Thesaurus Dictionary).
Examples
- A synonym dictionary can be used to overcome linguistic problems, for example, to prevent an English stemmer dictionary from reducing the word "Paris" to "pari". It is enough to have a Paris paris line in the synonym dictionary and put it before the english_stem dictionary.
1
SELECT * FROM ts_debug('english', 'Paris');
1 2 3 4 5 6 7 8 9 10 11
CREATE TEXT SEARCH DICTIONARY my_synonym ( TEMPLATE = synonym, SYNONYMS = my_synonyms, FILEPATH = 'obs://bucket01/obs.example.com accesskey=xxxxx secretkey=xxxxx region=ap-southeast-1' ); ALTER TEXT SEARCH CONFIGURATION english ALTER MAPPING FOR asciiword WITH my_synonym, english_stem; SELECT * FROM ts_debug('english', 'Paris');
1
SELECT * FROM ts_debug('english', 'paris');
1
ALTER TEXT SEARCH DICTIONARY my_synonym ( CASESENSITIVE=true);
1
SELECT * FROM ts_debug('english', 'paris');
The full name of the synonym dictionary file is my_synonyms.syn, and the dictionary is stored in 'obs://bucket01/obs.example.com accesskey=xxxxx secretkey=xxxxx region=ap-southeast-1'. For details about the syntax and parameters for creating a synonym dictionary, see CREATE TEXT SEARCH DICTIONARY.
- An asterisk (*) can be placed at the end of a synonym in the configuration file. This indicates that the synonym is a prefix. The asterisk is ignored when the entry is used in to_tsvector(), but when it is used in to_tsquery(), the result will be a query item with the prefix match marker (see Manipulating Queries).
Assume that the content in the dictionary file synonym_sample.syn is as follows:
1 2 3 4 5
postgres pgsql postgresql pgsql postgre pgsql gogle googl indices index*
Create and use a dictionary.
1 2 3 4 5 6
CREATE TEXT SEARCH DICTIONARY syn ( TEMPLATE = synonym, SYNONYMS = synonym_sample ); SELECT ts_lexize('syn','indices');
1 2 3 4 5
CREATE TEXT SEARCH CONFIGURATION tst (copy=simple); ALTER TEXT SEARCH CONFIGURATION tst ALTER MAPPING FOR asciiword WITH syn; SELECT to_tsvector('tst','indices');
1
SELECT to_tsquery('tst','indices');
1
SELECT 'indexes are very useful'::tsvector;
1
SELECT 'indexes are very useful'::tsvector @@ to_tsquery('tst','indices');
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot