{"Entry":{"collection":"fts","key":"template-synonym","name":"synonym","aliases":[],"metadata":{"aliases":[],"category":"Dictionary templates","content_hash":"2ba0f874efe2b090ddafcead78d935171d50f41a68f43ec3f547ce6709755d8c","imported_at":"2026-09-30T00:40:47.669135+08:00","name":"synonym","name_zh":"","slug":"template-synonym","summary":"synonym dictionary: replace word by its synonym"}},"Definition":{"Collection":"fts","Key":"template-synonym","SourceDatabase":"center","Version":"18","SourceTable":"text_search_component","SourceKey":"template-synonym","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"aliases":[],"attributes":{"tmplinit":"dsynonym_init","tmpllexize":"dsynonym_lexize","tmplname":"synonym"},"comparison_data":{"tmplinit":"dsynonym_init","tmpllexize":"dsynonym_lexize","tmplname":"synonym"},"comparison_hash":"01c20906081775fc96faef281e0dd79723c3780554b4aa04d12402789f7a198e","description":["synonym dictionary: replace word by its synonym"],"facts":[{"label":"Tmplname","value":"synonym"},{"label":"Tmplinit","value":"dsynonym_init"},{"label":"Tmpllexize","value":"dsynonym_lexize"}],"manual_html":"\u003cdiv class=\"sect2\" id=\"TEXTSEARCH-SYNONYM-DICTIONARY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e12.6.3. Synonym Dictionary \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThis dictionary template is used to create dictionaries that replace a word with a synonym. Phrases are not supported (use the thesaurus template (\u003ca class=\"xref\" href=\"/docs/18/textsearch-dictionaries.html#TEXTSEARCH-THESAURUS\" title=\"12.6.4. Thesaurus Dictionary\"\u003eSection 12.6.4\u003c/a\u003e) for that). A synonym dictionary can be used to overcome linguistic problems, for example, to prevent an English stemmer dictionary from reducing the word \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eParis\u003c/span\u003e”\u003c/span\u003e to \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003epari\u003c/span\u003e”\u003c/span\u003e. It is enough to have a \u003ccode class=\"literal\"\u003eParis paris\u003c/code\u003e line in the synonym dictionary and put it before the \u003ccode class=\"literal\"\u003eenglish_stem\u003c/code\u003e dictionary. For example:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003eSELECT * FROM ts_debug('english', 'Paris');\n   alias   |   description   | token |  dictionaries  |  dictionary  | lexemes\n-----------+-----------------+-------+----------------+--------------+---------\n asciiword | Word, all ASCII | Paris | {english_stem} | english_stem | {pari}\n\nCREATE TEXT SEARCH DICTIONARY my_synonym (\n    TEMPLATE = synonym,\n    SYNONYMS = my_synonyms\n);\n\nALTER TEXT SEARCH CONFIGURATION english\n    ALTER MAPPING FOR asciiword\n    WITH my_synonym, english_stem;\n\nSELECT * FROM ts_debug('english', 'Paris');\n   alias   |   description   | token |       dictionaries        | dictionary | lexemes\n-----------+-----------------+-------+---------------------------+------------+---------\n asciiword | Word, all ASCII | Paris | {my_synonym,english_stem} | my_synonym | {paris}\n\u003c/pre\u003e\n\u003cp\u003eThe only parameter required by the \u003ccode class=\"literal\"\u003esynonym\u003c/code\u003e template is \u003ccode class=\"literal\"\u003eSYNONYMS\u003c/code\u003e, which is the base name of its configuration file — \u003ccode class=\"literal\"\u003emy_synonyms\u003c/code\u003e in the above example. The file's full name will be \u003ccode class=\"filename\"\u003e$SHAREDIR/tsearch_data/my_synonyms.syn\u003c/code\u003e (where \u003ccode class=\"literal\"\u003e$SHAREDIR\u003c/code\u003e means the \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e installation's shared-data directory). The file format is just one line per word to be substituted, with the word followed by its synonym, separated by white space. Blank lines and trailing spaces are ignored.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"literal\"\u003esynonym\u003c/code\u003e template also has an optional parameter \u003ccode class=\"literal\"\u003eCaseSensitive\u003c/code\u003e, which defaults to \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. When \u003ccode class=\"literal\"\u003eCaseSensitive\u003c/code\u003e is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e, words in the synonym file are folded to lower case, as are input tokens. When it is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e, words and tokens are not folded to lower case, but are compared as-is.\u003c/p\u003e\n\u003cp\u003eAn asterisk (\u003ccode class=\"literal\"\u003e*\u003c/code\u003e) 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 \u003ccode class=\"function\"\u003eto_tsvector()\u003c/code\u003e, but when it is used in \u003ccode class=\"function\"\u003eto_tsquery()\u003c/code\u003e, the result will be a query item with the prefix match marker (see \u003ca class=\"xref\" href=\"/docs/18/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES\" title=\"12.3.2. Parsing Queries\"\u003eSection 12.3.2\u003c/a\u003e). For example, suppose we have these entries in \u003ccode class=\"filename\"\u003e$SHAREDIR/tsearch_data/synonym_sample.syn\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epostgres        pgsql\npostgresql      pgsql\npostgre pgsql\ngogle   googl\nindices index*\n\u003c/pre\u003e\n\u003cp\u003eThen we will get these results:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003emydb=# CREATE TEXT SEARCH DICTIONARY syn (template=synonym, synonyms='synonym_sample');\nmydb=# SELECT ts_lexize('syn', 'indices');\n ts_lexize\n-----------\n {index}\n(1 row)\n\nmydb=# CREATE TEXT SEARCH CONFIGURATION tst (copy=simple);\nmydb=# ALTER TEXT SEARCH CONFIGURATION tst ALTER MAPPING FOR asciiword WITH syn;\nmydb=# SELECT to_tsvector('tst', 'indices');\n to_tsvector\n-------------\n 'index':1\n(1 row)\n\nmydb=# SELECT to_tsquery('tst', 'indices');\n to_tsquery\n------------\n 'index':*\n(1 row)\n\nmydb=# SELECT 'indexes are very useful'::tsvector;\n            tsvector\n---------------------------------\n 'are' 'indexes' 'useful' 'very'\n(1 row)\n\nmydb=# SELECT 'indexes are very useful'::tsvector @@ to_tsquery('tst', 'indices');\n ?column?\n----------\n t\n(1 row)\n\u003c/pre\u003e\n\u003c/div\u003e","manual_path":"/docs/18/textsearch-dictionaries.html#TEXTSEARCH-SYNONYM-DICTIONARY","related":[],"release":{"catalog_fingerprint":"65c93d6048ef30e61023a84f9680fa6a92b1c383b7eb226741170077eb078502","channel":"stable","label":"18.6","major":"18","ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sections":[],"signature":"","sources":[{"label":"Matching PostgreSQL source archive","sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"label":"PostgreSQL 18 English manual","path":"textsearch-dictionaries.html","sha256":"736b212545d12542777fa6d106bbf5b159fe5617123a208d36a8a572130c3fa6","url":"/docs/18/textsearch-dictionaries.html#TEXTSEARCH-SYNONYM-DICTIONARY"}],"tables":[]},"ManualEvidence":{"manual_path":"/docs/18/textsearch-dictionaries.html#TEXTSEARCH-SYNONYM-DICTIONARY","release":{"catalog_fingerprint":"65c93d6048ef30e61023a84f9680fa6a92b1c383b7eb226741170077eb078502","channel":"stable","label":"18.6","major":"18","ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sources":[{"label":"Matching PostgreSQL source archive","sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"label":"PostgreSQL 18 English manual","path":"textsearch-dictionaries.html","sha256":"736b212545d12542777fa6d106bbf5b159fe5617123a208d36a8a572130c3fa6","url":"/docs/18/textsearch-dictionaries.html#TEXTSEARCH-SYNONYM-DICTIONARY"}]},"MeasuredEvidence":{}},"Text":{"Collection":"fts","Key":"template-synonym","SourceDatabase":"center","Version":"18","Locale":"en","Title":"synonym","Summary":"synonym dictionary: replace word by its synonym","BodyHTML":"\u003cdiv id=\"TEXTSEARCH-SYNONYM-DICTIONARY\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003e12.6.3. Synonym Dictionary \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThis dictionary template is used to create dictionaries that replace a word with a synonym. Phrases are not supported (use the thesaurus template (\u003ca href=\"/docs/18/textsearch-dictionaries.html#TEXTSEARCH-THESAURUS\" rel=\"nofollow\"\u003eSection 12.6.4\u003c/a\u003e) for that). A synonym dictionary can be used to overcome linguistic problems, for example, to prevent an English stemmer dictionary from reducing the word \u003cspan\u003e“\u003cspan\u003eParis\u003c/span\u003e”\u003c/span\u003e to \u003cspan\u003e“\u003cspan\u003epari\u003c/span\u003e”\u003c/span\u003e. It is enough to have a \u003ccode\u003eParis paris\u003c/code\u003e line in the synonym dictionary and put it before the \u003ccode\u003eenglish_stem\u003c/code\u003e dictionary. For example:\u003c/p\u003e\n\u003cpre\u003eSELECT * FROM ts_debug(\u0026#39;english\u0026#39;, \u0026#39;Paris\u0026#39;);\n   alias   |   description   | token |  dictionaries  |  dictionary  | lexemes\n-----------+-----------------+-------+----------------+--------------+---------\n asciiword | Word, all ASCII | Paris | {english_stem} | english_stem | {pari}\n\nCREATE TEXT SEARCH DICTIONARY my_synonym (\n    TEMPLATE = synonym,\n    SYNONYMS = my_synonyms\n);\n\nALTER TEXT SEARCH CONFIGURATION english\n    ALTER MAPPING FOR asciiword\n    WITH my_synonym, english_stem;\n\nSELECT * FROM ts_debug(\u0026#39;english\u0026#39;, \u0026#39;Paris\u0026#39;);\n   alias   |   description   | token |       dictionaries        | dictionary | lexemes\n-----------+-----------------+-------+---------------------------+------------+---------\n asciiword | Word, all ASCII | Paris | {my_synonym,english_stem} | my_synonym | {paris}\n\u003c/pre\u003e\n\u003cp\u003eThe only parameter required by the \u003ccode\u003esynonym\u003c/code\u003e template is \u003ccode\u003eSYNONYMS\u003c/code\u003e, which is the base name of its configuration file — \u003ccode\u003emy_synonyms\u003c/code\u003e in the above example. The file\u0026#39;s full name will be \u003ccode\u003e$SHAREDIR/tsearch_data/my_synonyms.syn\u003c/code\u003e (where \u003ccode\u003e$SHAREDIR\u003c/code\u003e means the \u003cspan\u003ePostgreSQL\u003c/span\u003e installation\u0026#39;s shared-data directory). The file format is just one line per word to be substituted, with the word followed by its synonym, separated by white space. Blank lines and trailing spaces are ignored.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode\u003esynonym\u003c/code\u003e template also has an optional parameter \u003ccode\u003eCaseSensitive\u003c/code\u003e, which defaults to \u003ccode\u003efalse\u003c/code\u003e. When \u003ccode\u003eCaseSensitive\u003c/code\u003e is \u003ccode\u003efalse\u003c/code\u003e, words in the synonym file are folded to lower case, as are input tokens. When it is \u003ccode\u003etrue\u003c/code\u003e, words and tokens are not folded to lower case, but are compared as-is.\u003c/p\u003e\n\u003cp\u003eAn asterisk (\u003ccode\u003e*\u003c/code\u003e) 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 \u003ccode\u003eto_tsvector()\u003c/code\u003e, but when it is used in \u003ccode\u003eto_tsquery()\u003c/code\u003e, the result will be a query item with the prefix match marker (see \u003ca href=\"/docs/18/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES\" rel=\"nofollow\"\u003eSection 12.3.2\u003c/a\u003e). For example, suppose we have these entries in \u003ccode\u003e$SHAREDIR/tsearch_data/synonym_sample.syn\u003c/code\u003e:\u003c/p\u003e\n\u003cpre\u003epostgres        pgsql\npostgresql      pgsql\npostgre pgsql\ngogle   googl\nindices index*\n\u003c/pre\u003e\n\u003cp\u003eThen we will get these results:\u003c/p\u003e\n\u003cpre\u003emydb=# CREATE TEXT SEARCH DICTIONARY syn (template=synonym, synonyms=\u0026#39;synonym_sample\u0026#39;);\nmydb=# SELECT ts_lexize(\u0026#39;syn\u0026#39;, \u0026#39;indices\u0026#39;);\n ts_lexize\n-----------\n {index}\n(1 row)\n\nmydb=# CREATE TEXT SEARCH CONFIGURATION tst (copy=simple);\nmydb=# ALTER TEXT SEARCH CONFIGURATION tst ALTER MAPPING FOR asciiword WITH syn;\nmydb=# SELECT to_tsvector(\u0026#39;tst\u0026#39;, \u0026#39;indices\u0026#39;);\n to_tsvector\n-------------\n \u0026#39;index\u0026#39;:1\n(1 row)\n\nmydb=# SELECT to_tsquery(\u0026#39;tst\u0026#39;, \u0026#39;indices\u0026#39;);\n to_tsquery\n------------\n \u0026#39;index\u0026#39;:*\n(1 row)\n\nmydb=# SELECT \u0026#39;indexes are very useful\u0026#39;::tsvector;\n            tsvector\n---------------------------------\n \u0026#39;are\u0026#39; \u0026#39;indexes\u0026#39; \u0026#39;useful\u0026#39; \u0026#39;very\u0026#39;\n(1 row)\n\nmydb=# SELECT \u0026#39;indexes are very useful\u0026#39;::tsvector @@ to_tsquery(\u0026#39;tst\u0026#39;, \u0026#39;indices\u0026#39;);\n ?column?\n----------\n t\n(1 row)\n\u003c/pre\u003e\n\u003c/div\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"0f04f67f22c56d37a5988536f723786fc072374aad204bbcb8ada9bcd9a838a4","Payload":{"description":["synonym dictionary: replace word by its synonym"],"manual_html":"\u003cdiv class=\"sect2\" id=\"TEXTSEARCH-SYNONYM-DICTIONARY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e12.6.3. Synonym Dictionary \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThis dictionary template is used to create dictionaries that replace a word with a synonym. Phrases are not supported (use the thesaurus template (\u003ca class=\"xref\" href=\"/docs/18/textsearch-dictionaries.html#TEXTSEARCH-THESAURUS\" title=\"12.6.4. Thesaurus Dictionary\"\u003eSection 12.6.4\u003c/a\u003e) for that). A synonym dictionary can be used to overcome linguistic problems, for example, to prevent an English stemmer dictionary from reducing the word \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eParis\u003c/span\u003e”\u003c/span\u003e to \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003epari\u003c/span\u003e”\u003c/span\u003e. It is enough to have a \u003ccode class=\"literal\"\u003eParis paris\u003c/code\u003e line in the synonym dictionary and put it before the \u003ccode class=\"literal\"\u003eenglish_stem\u003c/code\u003e dictionary. For example:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003eSELECT * FROM ts_debug('english', 'Paris');\n   alias   |   description   | token |  dictionaries  |  dictionary  | lexemes\n-----------+-----------------+-------+----------------+--------------+---------\n asciiword | Word, all ASCII | Paris | {english_stem} | english_stem | {pari}\n\nCREATE TEXT SEARCH DICTIONARY my_synonym (\n    TEMPLATE = synonym,\n    SYNONYMS = my_synonyms\n);\n\nALTER TEXT SEARCH CONFIGURATION english\n    ALTER MAPPING FOR asciiword\n    WITH my_synonym, english_stem;\n\nSELECT * FROM ts_debug('english', 'Paris');\n   alias   |   description   | token |       dictionaries        | dictionary | lexemes\n-----------+-----------------+-------+---------------------------+------------+---------\n asciiword | Word, all ASCII | Paris | {my_synonym,english_stem} | my_synonym | {paris}\n\u003c/pre\u003e\n\u003cp\u003eThe only parameter required by the \u003ccode class=\"literal\"\u003esynonym\u003c/code\u003e template is \u003ccode class=\"literal\"\u003eSYNONYMS\u003c/code\u003e, which is the base name of its configuration file — \u003ccode class=\"literal\"\u003emy_synonyms\u003c/code\u003e in the above example. The file's full name will be \u003ccode class=\"filename\"\u003e$SHAREDIR/tsearch_data/my_synonyms.syn\u003c/code\u003e (where \u003ccode class=\"literal\"\u003e$SHAREDIR\u003c/code\u003e means the \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e installation's shared-data directory). The file format is just one line per word to be substituted, with the word followed by its synonym, separated by white space. Blank lines and trailing spaces are ignored.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"literal\"\u003esynonym\u003c/code\u003e template also has an optional parameter \u003ccode class=\"literal\"\u003eCaseSensitive\u003c/code\u003e, which defaults to \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. When \u003ccode class=\"literal\"\u003eCaseSensitive\u003c/code\u003e is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e, words in the synonym file are folded to lower case, as are input tokens. When it is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e, words and tokens are not folded to lower case, but are compared as-is.\u003c/p\u003e\n\u003cp\u003eAn asterisk (\u003ccode class=\"literal\"\u003e*\u003c/code\u003e) 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 \u003ccode class=\"function\"\u003eto_tsvector()\u003c/code\u003e, but when it is used in \u003ccode class=\"function\"\u003eto_tsquery()\u003c/code\u003e, the result will be a query item with the prefix match marker (see \u003ca class=\"xref\" href=\"/docs/18/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES\" title=\"12.3.2. Parsing Queries\"\u003eSection 12.3.2\u003c/a\u003e). For example, suppose we have these entries in \u003ccode class=\"filename\"\u003e$SHAREDIR/tsearch_data/synonym_sample.syn\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epostgres        pgsql\npostgresql      pgsql\npostgre pgsql\ngogle   googl\nindices index*\n\u003c/pre\u003e\n\u003cp\u003eThen we will get these results:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003emydb=# CREATE TEXT SEARCH DICTIONARY syn (template=synonym, synonyms='synonym_sample');\nmydb=# SELECT ts_lexize('syn', 'indices');\n ts_lexize\n-----------\n {index}\n(1 row)\n\nmydb=# CREATE TEXT SEARCH CONFIGURATION tst (copy=simple);\nmydb=# ALTER TEXT SEARCH CONFIGURATION tst ALTER MAPPING FOR asciiword WITH syn;\nmydb=# SELECT to_tsvector('tst', 'indices');\n to_tsvector\n-------------\n 'index':1\n(1 row)\n\nmydb=# SELECT to_tsquery('tst', 'indices');\n to_tsquery\n------------\n 'index':*\n(1 row)\n\nmydb=# SELECT 'indexes are very useful'::tsvector;\n            tsvector\n---------------------------------\n 'are' 'indexes' 'useful' 'very'\n(1 row)\n\nmydb=# SELECT 'indexes are very useful'::tsvector @@ to_tsquery('tst', 'indices');\n ?column?\n----------\n t\n(1 row)\n\u003c/pre\u003e\n\u003c/div\u003e","related":[],"sections":[],"tables":[]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
