gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

108 行
6.0KB

  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>12.7. Configuration Example</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 V1.79.1" /><link rel="prev" href="textsearch-dictionaries.html" title="12.6. Dictionaries" /><link rel="next" href="textsearch-debugging.html" title="12.8. Testing and Debugging Text Search" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">12.7. Configuration Example</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="textsearch-dictionaries.html" title="12.6. Dictionaries">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="textsearch.html" title="Chapter 12. Full Text Search">Up</a></td><th width="60%" align="center">Chapter 12. Full Text Search</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="textsearch-debugging.html" title="12.8. Testing and Debugging Text Search">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="TEXTSEARCH-CONFIGURATION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">12.7. Configuration Example</h2></div></div></div><p>
  3. A text search configuration specifies all options necessary to transform a
  4. document into a <code class="type">tsvector</code>: the parser to use to break text
  5. into tokens, and the dictionaries to use to transform each token into a
  6. lexeme. Every call of
  7. <code class="function">to_tsvector</code> or <code class="function">to_tsquery</code>
  8. needs a text search configuration to perform its processing.
  9. The configuration parameter
  10. <a class="xref" href="runtime-config-client.html#GUC-DEFAULT-TEXT-SEARCH-CONFIG">default_text_search_config</a>
  11. specifies the name of the default configuration, which is the
  12. one used by text search functions if an explicit configuration
  13. parameter is omitted.
  14. It can be set in <code class="filename">postgresql.conf</code>, or set for an
  15. individual session using the <code class="command">SET</code> command.
  16. </p><p>
  17. Several predefined text search configurations are available, and
  18. you can create custom configurations easily. To facilitate management
  19. of text search objects, a set of <acronym class="acronym">SQL</acronym> commands
  20. is available, and there are several <span class="application">psql</span> commands that display information
  21. about text search objects (<a class="xref" href="textsearch-psql.html" title="12.10. psql Support">Section 12.10</a>).
  22. </p><p>
  23. As an example we will create a configuration
  24. <code class="literal">pg</code>, starting by duplicating the built-in
  25. <code class="literal">english</code> configuration:
  26. </p><pre class="programlisting">
  27. CREATE TEXT SEARCH CONFIGURATION public.pg ( COPY = pg_catalog.english );
  28. </pre><p>
  29. </p><p>
  30. We will use a PostgreSQL-specific synonym list
  31. and store it in <code class="filename">$SHAREDIR/tsearch_data/pg_dict.syn</code>.
  32. The file contents look like:
  33. </p><pre class="programlisting">
  34. postgres pg
  35. pgsql pg
  36. postgresql pg
  37. </pre><p>
  38. We define the synonym dictionary like this:
  39. </p><pre class="programlisting">
  40. CREATE TEXT SEARCH DICTIONARY pg_dict (
  41. TEMPLATE = synonym,
  42. SYNONYMS = pg_dict
  43. );
  44. </pre><p>
  45. Next we register the <span class="productname">Ispell</span> dictionary
  46. <code class="literal">english_ispell</code>, which has its own configuration files:
  47. </p><pre class="programlisting">
  48. CREATE TEXT SEARCH DICTIONARY english_ispell (
  49. TEMPLATE = ispell,
  50. DictFile = english,
  51. AffFile = english,
  52. StopWords = english
  53. );
  54. </pre><p>
  55. Now we can set up the mappings for words in configuration
  56. <code class="literal">pg</code>:
  57. </p><pre class="programlisting">
  58. ALTER TEXT SEARCH CONFIGURATION pg
  59. ALTER MAPPING FOR asciiword, asciihword, hword_asciipart,
  60. word, hword, hword_part
  61. WITH pg_dict, english_ispell, english_stem;
  62. </pre><p>
  63. We choose not to index or search some token types that the built-in
  64. configuration does handle:
  65. </p><pre class="programlisting">
  66. ALTER TEXT SEARCH CONFIGURATION pg
  67. DROP MAPPING FOR email, url, url_path, sfloat, float;
  68. </pre><p>
  69. </p><p>
  70. Now we can test our configuration:
  71. </p><pre class="programlisting">
  72. SELECT * FROM ts_debug('public.pg', '
  73. PostgreSQL, the highly scalable, SQL compliant, open source object-relational
  74. database management system, is now undergoing beta testing of the next
  75. version of our software.
  76. ');
  77. </pre><p>
  78. </p><p>
  79. The next step is to set the session to use the new configuration, which was
  80. created in the <code class="literal">public</code> schema:
  81. </p><pre class="screen">
  82. =&gt; \dF
  83. List of text search configurations
  84. Schema | Name | Description
  85. ---------+------+-------------
  86. public | pg |
  87. SET default_text_search_config = 'public.pg';
  88. SET
  89. SHOW default_text_search_config;
  90. default_text_search_config
  91. ----------------------------
  92. public.pg
  93. </pre><p>
  94. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="textsearch-dictionaries.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="textsearch.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="textsearch-debugging.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">12.6. Dictionaries </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 12.8. Testing and Debugging Text Search</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1