]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/dict-xsyn.html
PG 18 docs from https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0-docs...
[ai-pg] / full-docs / src / sgml / html / dict-xsyn.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>F.13. dict_xsyn — example synonym full-text search dictionary</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="dict-int.html" title="F.12. dict_int — example full-text search dictionary for integers" /><link rel="next" href="earthdistance.html" title="F.14. earthdistance — calculate great-circle distances" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">F.13. dict_xsyn — example synonym full-text search dictionary</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="dict-int.html" title="F.12. dict_int —&#10;   example full-text search dictionary for integers">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules and Extensions">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules and Extensions</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="earthdistance.html" title="F.14. earthdistance — calculate great-circle distances">Next</a></td></tr></table><hr /></div><div class="sect1" id="DICT-XSYN"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.13. dict_xsyn — example synonym full-text search dictionary <a href="#DICT-XSYN" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="dict-xsyn.html#DICT-XSYN-CONFIG">F.13.1. Configuration</a></span></dt><dt><span class="sect2"><a href="dict-xsyn.html#DICT-XSYN-USAGE">F.13.2. Usage</a></span></dt></dl></div><a id="id-1.11.7.23.2" class="indexterm"></a><p>
3   <code class="filename">dict_xsyn</code> (Extended Synonym Dictionary) is an example of an
4   add-on dictionary template for full-text search.  This dictionary type
5   replaces words with groups of their synonyms, and so makes it possible to
6   search for a word using any of its synonyms.
7  </p><div class="sect2" id="DICT-XSYN-CONFIG"><div class="titlepage"><div><div><h3 class="title">F.13.1. Configuration <a href="#DICT-XSYN-CONFIG" class="id_link">#</a></h3></div></div></div><p>
8    A <code class="literal">dict_xsyn</code> dictionary accepts the following options:
9   </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
10      <code class="literal">matchorig</code> controls whether the original word is accepted by
11      the dictionary. Default is <code class="literal">true</code>.
12     </p></li><li class="listitem"><p>
13      <code class="literal">matchsynonyms</code> controls whether the synonyms are
14      accepted by the dictionary. Default is <code class="literal">false</code>.
15     </p></li><li class="listitem"><p>
16      <code class="literal">keeporig</code> controls whether the original word is included in
17      the dictionary's output. Default is <code class="literal">true</code>.
18     </p></li><li class="listitem"><p>
19      <code class="literal">keepsynonyms</code> controls whether the synonyms are included in
20      the dictionary's output. Default is <code class="literal">true</code>.
21     </p></li><li class="listitem"><p>
22      <code class="literal">rules</code> is the base name of the file containing the list of
23      synonyms.  This file must be stored in
24      <code class="filename">$SHAREDIR/tsearch_data/</code> (where <code class="literal">$SHAREDIR</code> means
25      the <span class="productname">PostgreSQL</span> installation's shared-data directory).
26      Its name must end in <code class="literal">.rules</code> (which is not to be included in
27      the <code class="literal">rules</code> parameter).
28     </p></li></ul></div><p>
29    The rules file has the following format:
30   </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
31      Each line represents a group of synonyms for a single word, which is
32      given first on the line. Synonyms are separated by whitespace, thus:
33 </p><pre class="programlisting">
34 word syn1 syn2 syn3
35 </pre><p>
36     </p></li><li class="listitem"><p>
37      The sharp (<code class="literal">#</code>) sign is a comment delimiter. It may appear at
38      any position in a line.  The rest of the line will be skipped.
39     </p></li></ul></div><p>
40    Look at <code class="filename">xsyn_sample.rules</code>, which is installed in
41    <code class="filename">$SHAREDIR/tsearch_data/</code>, for an example.
42   </p></div><div class="sect2" id="DICT-XSYN-USAGE"><div class="titlepage"><div><div><h3 class="title">F.13.2. Usage <a href="#DICT-XSYN-USAGE" class="id_link">#</a></h3></div></div></div><p>
43    Installing the <code class="literal">dict_xsyn</code> extension creates a text search
44    template <code class="literal">xsyn_template</code> and a dictionary <code class="literal">xsyn</code>
45    based on it, with default parameters.  You can alter the
46    parameters, for example
47
48 </p><pre class="programlisting">
49 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false);
50 ALTER TEXT SEARCH DICTIONARY
51 </pre><p>
52
53    or create new dictionaries based on the template.
54   </p><p>
55    To test the dictionary, you can try
56
57 </p><pre class="programlisting">
58 mydb=# SELECT ts_lexize('xsyn', 'word');
59       ts_lexize
60 -----------------------
61  {syn1,syn2,syn3}
62
63 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true);
64 ALTER TEXT SEARCH DICTIONARY
65
66 mydb=# SELECT ts_lexize('xsyn', 'word');
67       ts_lexize
68 -----------------------
69  {word,syn1,syn2,syn3}
70
71 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false, MATCHSYNONYMS=true);
72 ALTER TEXT SEARCH DICTIONARY
73
74 mydb=# SELECT ts_lexize('xsyn', 'syn1');
75       ts_lexize
76 -----------------------
77  {syn1,syn2,syn3}
78
79 mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true, MATCHORIG=false, KEEPSYNONYMS=false);
80 ALTER TEXT SEARCH DICTIONARY
81
82 mydb=# SELECT ts_lexize('xsyn', 'syn1');
83       ts_lexize
84 -----------------------
85  {word}
86 </pre><p>
87
88    Real-world usage will involve including it in a text search
89    configuration as described in <a class="xref" href="textsearch.html" title="Chapter 12. Full Text Search">Chapter 12</a>.
90    That might look like this:
91
92 </p><pre class="programlisting">
93 ALTER TEXT SEARCH CONFIGURATION english
94     ALTER MAPPING FOR word, asciiword WITH xsyn, english_stem;
95 </pre><p>
96
97   </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="dict-int.html" title="F.12. dict_int —&#10;   example full-text search dictionary for integers">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules and Extensions">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="earthdistance.html" title="F.14. earthdistance — calculate great-circle distances">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.12. dict_int —
98    example full-text search dictionary for integers </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> F.14. earthdistance — calculate great-circle distances</td></tr></table></div></body></html>