gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

387 lines
25KB

  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.4. Additional Features</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-controls.html" title="12.3. Controlling Text Search" /><link rel="next" href="textsearch-parsers.html" title="12.5. Parsers" /></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.4. Additional Features</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="textsearch-controls.html" title="12.3. Controlling Text Search">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-parsers.html" title="12.5. Parsers">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="TEXTSEARCH-FEATURES"><div class="titlepage"><div><div><h2 class="title" style="clear: both">12.4. Additional Features</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="textsearch-features.html#TEXTSEARCH-MANIPULATE-TSVECTOR">12.4.1. Manipulating Documents</a></span></dt><dt><span class="sect2"><a href="textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY">12.4.2. Manipulating Queries</a></span></dt><dt><span class="sect2"><a href="textsearch-features.html#TEXTSEARCH-UPDATE-TRIGGERS">12.4.3. Triggers for Automatic Updates</a></span></dt><dt><span class="sect2"><a href="textsearch-features.html#TEXTSEARCH-STATISTICS">12.4.4. Gathering Document Statistics</a></span></dt></dl></div><p>
  3. This section describes additional functions and operators that are
  4. useful in connection with text search.
  5. </p><div class="sect2" id="TEXTSEARCH-MANIPULATE-TSVECTOR"><div class="titlepage"><div><div><h3 class="title">12.4.1. Manipulating Documents</h3></div></div></div><p>
  6. <a class="xref" href="textsearch-controls.html#TEXTSEARCH-PARSING-DOCUMENTS" title="12.3.1. Parsing Documents">Section 12.3.1</a> showed how raw textual
  7. documents can be converted into <code class="type">tsvector</code> values.
  8. <span class="productname">PostgreSQL</span> also provides functions and
  9. operators that can be used to manipulate documents that are already
  10. in <code class="type">tsvector</code> form.
  11. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  12. <a id="id-1.5.11.7.3.3.1.1.1" class="indexterm"></a>
  13. <code class="literal"><code class="type">tsvector</code> || <code class="type">tsvector</code></code>
  14. </span></dt><dd><p>
  15. The <code class="type">tsvector</code> concatenation operator
  16. returns a vector which combines the lexemes and positional information
  17. of the two vectors given as arguments. Positions and weight labels
  18. are retained during the concatenation.
  19. Positions appearing in the right-hand vector are offset by the largest
  20. position mentioned in the left-hand vector, so that the result is
  21. nearly equivalent to the result of performing <code class="function">to_tsvector</code>
  22. on the concatenation of the two original document strings. (The
  23. equivalence is not exact, because any stop-words removed from the
  24. end of the left-hand argument will not affect the result, whereas
  25. they would have affected the positions of the lexemes in the
  26. right-hand argument if textual concatenation were used.)
  27. </p><p>
  28. One advantage of using concatenation in the vector form, rather than
  29. concatenating text before applying <code class="function">to_tsvector</code>, is that
  30. you can use different configurations to parse different sections
  31. of the document. Also, because the <code class="function">setweight</code> function
  32. marks all lexemes of the given vector the same way, it is necessary
  33. to parse the text and do <code class="function">setweight</code> before concatenating
  34. if you want to label different parts of the document with different
  35. weights.
  36. </p></dd><dt><span class="term">
  37. <a id="id-1.5.11.7.3.3.2.1.1" class="indexterm"></a>
  38. <code class="literal">setweight(<em class="replaceable"><code>vector</code></em> <code class="type">tsvector</code>, <em class="replaceable"><code>weight</code></em> <code class="type">"char"</code>) returns <code class="type">tsvector</code></code>
  39. </span></dt><dd><p>
  40. <code class="function">setweight</code> returns a copy of the input vector in which every
  41. position has been labeled with the given <em class="replaceable"><code>weight</code></em>, either
  42. <code class="literal">A</code>, <code class="literal">B</code>, <code class="literal">C</code>, or
  43. <code class="literal">D</code>. (<code class="literal">D</code> is the default for new
  44. vectors and as such is not displayed on output.) These labels are
  45. retained when vectors are concatenated, allowing words from different
  46. parts of a document to be weighted differently by ranking functions.
  47. </p><p>
  48. Note that weight labels apply to <span class="emphasis"><em>positions</em></span>, not
  49. <span class="emphasis"><em>lexemes</em></span>. If the input vector has been stripped of
  50. positions then <code class="function">setweight</code> does nothing.
  51. </p></dd><dt><span class="term">
  52. <a id="id-1.5.11.7.3.3.3.1.1" class="indexterm"></a>
  53. <code class="literal">length(<em class="replaceable"><code>vector</code></em> <code class="type">tsvector</code>) returns <code class="type">integer</code></code>
  54. </span></dt><dd><p>
  55. Returns the number of lexemes stored in the vector.
  56. </p></dd><dt><span class="term">
  57. <a id="id-1.5.11.7.3.3.4.1.1" class="indexterm"></a>
  58. <code class="literal">strip(<em class="replaceable"><code>vector</code></em> <code class="type">tsvector</code>) returns <code class="type">tsvector</code></code>
  59. </span></dt><dd><p>
  60. Returns a vector that lists the same lexemes as the given vector, but
  61. lacks any position or weight information. The result is usually much
  62. smaller than an unstripped vector, but it is also less useful.
  63. Relevance ranking does not work as well on stripped vectors as
  64. unstripped ones. Also,
  65. the <code class="literal">&lt;-&gt;</code> (FOLLOWED BY) <code class="type">tsquery</code> operator
  66. will never match stripped input, since it cannot determine the
  67. distance between lexeme occurrences.
  68. </p></dd></dl></div><p>
  69. A full list of <code class="type">tsvector</code>-related functions is available
  70. in <a class="xref" href="functions-textsearch.html#TEXTSEARCH-FUNCTIONS-TABLE" title="Table 9.42. Text Search Functions">Table 9.42</a>.
  71. </p></div><div class="sect2" id="TEXTSEARCH-MANIPULATE-TSQUERY"><div class="titlepage"><div><div><h3 class="title">12.4.2. Manipulating Queries</h3></div></div></div><p>
  72. <a class="xref" href="textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES" title="12.3.2. Parsing Queries">Section 12.3.2</a> showed how raw textual
  73. queries can be converted into <code class="type">tsquery</code> values.
  74. <span class="productname">PostgreSQL</span> also provides functions and
  75. operators that can be used to manipulate queries that are already
  76. in <code class="type">tsquery</code> form.
  77. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  78. <code class="literal"><code class="type">tsquery</code> &amp;&amp; <code class="type">tsquery</code></code>
  79. </span></dt><dd><p>
  80. Returns the AND-combination of the two given queries.
  81. </p></dd><dt><span class="term">
  82. <code class="literal"><code class="type">tsquery</code> || <code class="type">tsquery</code></code>
  83. </span></dt><dd><p>
  84. Returns the OR-combination of the two given queries.
  85. </p></dd><dt><span class="term">
  86. <code class="literal">!! <code class="type">tsquery</code></code>
  87. </span></dt><dd><p>
  88. Returns the negation (NOT) of the given query.
  89. </p></dd><dt><span class="term">
  90. <code class="literal"><code class="type">tsquery</code> &lt;-&gt; <code class="type">tsquery</code></code>
  91. </span></dt><dd><p>
  92. Returns a query that searches for a match to the first given query
  93. immediately followed by a match to the second given query, using
  94. the <code class="literal">&lt;-&gt;</code> (FOLLOWED BY)
  95. <code class="type">tsquery</code> operator. For example:
  96. </p><pre class="screen">
  97. SELECT to_tsquery('fat') &lt;-&gt; to_tsquery('cat | rat');
  98. ?column?
  99. -----------------------------------
  100. 'fat' &lt;-&gt; 'cat' | 'fat' &lt;-&gt; 'rat'
  101. </pre><p>
  102. </p></dd><dt><span class="term">
  103. <a id="id-1.5.11.7.4.3.5.1.1" class="indexterm"></a>
  104. <code class="literal">tsquery_phrase(<em class="replaceable"><code>query1</code></em> <code class="type">tsquery</code>, <em class="replaceable"><code>query2</code></em> <code class="type">tsquery</code> [, <em class="replaceable"><code>distance</code></em> <code class="type">integer</code> ]) returns <code class="type">tsquery</code></code>
  105. </span></dt><dd><p>
  106. Returns a query that searches for a match to the first given query
  107. followed by a match to the second given query at a distance of at
  108. <em class="replaceable"><code>distance</code></em> lexemes, using
  109. the <code class="literal">&lt;<em class="replaceable"><code>N</code></em>&gt;</code>
  110. <code class="type">tsquery</code> operator. For example:
  111. </p><pre class="screen">
  112. SELECT tsquery_phrase(to_tsquery('fat'), to_tsquery('cat'), 10);
  113. tsquery_phrase
  114. ------------------
  115. 'fat' &lt;10&gt; 'cat'
  116. </pre><p>
  117. </p></dd><dt><span class="term">
  118. <a id="id-1.5.11.7.4.3.6.1.1" class="indexterm"></a>
  119. <code class="literal">numnode(<em class="replaceable"><code>query</code></em> <code class="type">tsquery</code>) returns <code class="type">integer</code></code>
  120. </span></dt><dd><p>
  121. Returns the number of nodes (lexemes plus operators) in a
  122. <code class="type">tsquery</code>. This function is useful
  123. to determine if the <em class="replaceable"><code>query</code></em> is meaningful
  124. (returns &gt; 0), or contains only stop words (returns 0).
  125. Examples:
  126. </p><pre class="screen">
  127. SELECT numnode(plainto_tsquery('the any'));
  128. NOTICE: query contains only stopword(s) or doesn't contain lexeme(s), ignored
  129. numnode
  130. ---------
  131. 0
  132. SELECT numnode('foo &amp; bar'::tsquery);
  133. numnode
  134. ---------
  135. 3
  136. </pre><p>
  137. </p></dd><dt><span class="term">
  138. <a id="id-1.5.11.7.4.3.7.1.1" class="indexterm"></a>
  139. <code class="literal">querytree(<em class="replaceable"><code>query</code></em> <code class="type">tsquery</code>) returns <code class="type">text</code></code>
  140. </span></dt><dd><p>
  141. Returns the portion of a <code class="type">tsquery</code> that can be used for
  142. searching an index. This function is useful for detecting
  143. unindexable queries, for example those containing only stop words
  144. or only negated terms. For example:
  145. </p><pre class="screen">
  146. SELECT querytree(to_tsquery('!defined'));
  147. querytree
  148. -----------
  149. </pre><p>
  150. </p></dd></dl></div><div class="sect3" id="TEXTSEARCH-QUERY-REWRITING"><div class="titlepage"><div><div><h4 class="title">12.4.2.1. Query Rewriting</h4></div></div></div><a id="id-1.5.11.7.4.4.2" class="indexterm"></a><p>
  151. The <code class="function">ts_rewrite</code> family of functions search a
  152. given <code class="type">tsquery</code> for occurrences of a target
  153. subquery, and replace each occurrence with a
  154. substitute subquery. In essence this operation is a
  155. <code class="type">tsquery</code>-specific version of substring replacement.
  156. A target and substitute combination can be
  157. thought of as a <em class="firstterm">query rewrite rule</em>. A collection
  158. of such rewrite rules can be a powerful search aid.
  159. For example, you can expand the search using synonyms
  160. (e.g., <code class="literal">new york</code>, <code class="literal">big apple</code>, <code class="literal">nyc</code>,
  161. <code class="literal">gotham</code>) or narrow the search to direct the user to some hot
  162. topic. There is some overlap in functionality between this feature
  163. and thesaurus dictionaries (<a class="xref" href="textsearch-dictionaries.html#TEXTSEARCH-THESAURUS" title="12.6.4. Thesaurus Dictionary">Section 12.6.4</a>).
  164. However, you can modify a set of rewrite rules on-the-fly without
  165. reindexing, whereas updating a thesaurus requires reindexing to be
  166. effective.
  167. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  168. <code class="literal">ts_rewrite (<em class="replaceable"><code>query</code></em> <code class="type">tsquery</code>, <em class="replaceable"><code>target</code></em> <code class="type">tsquery</code>, <em class="replaceable"><code>substitute</code></em> <code class="type">tsquery</code>) returns <code class="type">tsquery</code></code>
  169. </span></dt><dd><p>
  170. This form of <code class="function">ts_rewrite</code> simply applies a single
  171. rewrite rule: <em class="replaceable"><code>target</code></em>
  172. is replaced by <em class="replaceable"><code>substitute</code></em>
  173. wherever it appears in <em class="replaceable"><code>query</code></em>. For example:
  174. </p><pre class="screen">
  175. SELECT ts_rewrite('a &amp; b'::tsquery, 'a'::tsquery, 'c'::tsquery);
  176. ts_rewrite
  177. ------------
  178. 'b' &amp; 'c'
  179. </pre><p>
  180. </p></dd><dt><span class="term">
  181. <code class="literal">ts_rewrite (<em class="replaceable"><code>query</code></em> <code class="type">tsquery</code>, <em class="replaceable"><code>select</code></em> <code class="type">text</code>) returns <code class="type">tsquery</code></code>
  182. </span></dt><dd><p>
  183. This form of <code class="function">ts_rewrite</code> accepts a starting
  184. <em class="replaceable"><code>query</code></em> and a SQL <em class="replaceable"><code>select</code></em> command, which
  185. is given as a text string. The <em class="replaceable"><code>select</code></em> must yield two
  186. columns of <code class="type">tsquery</code> type. For each row of the
  187. <em class="replaceable"><code>select</code></em> result, occurrences of the first column value
  188. (the target) are replaced by the second column value (the substitute)
  189. within the current <em class="replaceable"><code>query</code></em> value. For example:
  190. </p><pre class="screen">
  191. CREATE TABLE aliases (t tsquery PRIMARY KEY, s tsquery);
  192. INSERT INTO aliases VALUES('a', 'c');
  193. SELECT ts_rewrite('a &amp; b'::tsquery, 'SELECT t,s FROM aliases');
  194. ts_rewrite
  195. ------------
  196. 'b' &amp; 'c'
  197. </pre><p>
  198. </p><p>
  199. Note that when multiple rewrite rules are applied in this way,
  200. the order of application can be important; so in practice you will
  201. want the source query to <code class="literal">ORDER BY</code> some ordering key.
  202. </p></dd></dl></div><p>
  203. Let's consider a real-life astronomical example. We'll expand query
  204. <code class="literal">supernovae</code> using table-driven rewriting rules:
  205. </p><pre class="screen">
  206. CREATE TABLE aliases (t tsquery primary key, s tsquery);
  207. INSERT INTO aliases VALUES(to_tsquery('supernovae'), to_tsquery('supernovae|sn'));
  208. SELECT ts_rewrite(to_tsquery('supernovae &amp; crab'), 'SELECT * FROM aliases');
  209. ts_rewrite
  210. ---------------------------------
  211. 'crab' &amp; ( 'supernova' | 'sn' )
  212. </pre><p>
  213. We can change the rewriting rules just by updating the table:
  214. </p><pre class="screen">
  215. UPDATE aliases
  216. SET s = to_tsquery('supernovae|sn &amp; !nebulae')
  217. WHERE t = to_tsquery('supernovae');
  218. SELECT ts_rewrite(to_tsquery('supernovae &amp; crab'), 'SELECT * FROM aliases');
  219. ts_rewrite
  220. ---------------------------------------------
  221. 'crab' &amp; ( 'supernova' | 'sn' &amp; !'nebula' )
  222. </pre><p>
  223. </p><p>
  224. Rewriting can be slow when there are many rewriting rules, since it
  225. checks every rule for a possible match. To filter out obvious non-candidate
  226. rules we can use the containment operators for the <code class="type">tsquery</code>
  227. type. In the example below, we select only those rules which might match
  228. the original query:
  229. </p><pre class="screen">
  230. SELECT ts_rewrite('a &amp; b'::tsquery,
  231. 'SELECT t,s FROM aliases WHERE ''a &amp; b''::tsquery @&gt; t');
  232. ts_rewrite
  233. ------------
  234. 'b' &amp; 'c'
  235. </pre><p>
  236. </p></div></div><div class="sect2" id="TEXTSEARCH-UPDATE-TRIGGERS"><div class="titlepage"><div><div><h3 class="title">12.4.3. Triggers for Automatic Updates</h3></div></div></div><a id="id-1.5.11.7.5.2" class="indexterm"></a><div class="note"><h3 class="title">Note</h3><p>
  237. The method described in this section has been obsoleted by the use of
  238. stored generated columns, as described in <a class="xref" href="textsearch-tables.html#TEXTSEARCH-TABLES-INDEX" title="12.2.2. Creating Indexes">Section 12.2.2</a>.
  239. </p></div><p>
  240. When using a separate column to store the <code class="type">tsvector</code> representation
  241. of your documents, it is necessary to create a trigger to update the
  242. <code class="type">tsvector</code> column when the document content columns change.
  243. Two built-in trigger functions are available for this, or you can write
  244. your own.
  245. </p><pre class="synopsis">
  246. tsvector_update_trigger(<em class="replaceable"><code>tsvector_column_name</code></em>, <em class="replaceable"><code>config_name</code></em>, <em class="replaceable"><code>text_column_name</code></em> [<span class="optional">, ... </span>])
  247. tsvector_update_trigger_column(<em class="replaceable"><code>tsvector_column_name</code></em>, <em class="replaceable"><code>config_column_name</code></em>, <em class="replaceable"><code>text_column_name</code></em> [<span class="optional">, ... </span>])
  248. </pre><p>
  249. These trigger functions automatically compute a <code class="type">tsvector</code>
  250. column from one or more textual columns, under the control of
  251. parameters specified in the <code class="command">CREATE TRIGGER</code> command.
  252. An example of their use is:
  253. </p><pre class="screen">
  254. CREATE TABLE messages (
  255. title text,
  256. body text,
  257. tsv tsvector
  258. );
  259. CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
  260. ON messages FOR EACH ROW EXECUTE FUNCTION
  261. tsvector_update_trigger(tsv, 'pg_catalog.english', title, body);
  262. INSERT INTO messages VALUES('title here', 'the body text is here');
  263. SELECT * FROM messages;
  264. title | body | tsv
  265. ------------+-----------------------+----------------------------
  266. title here | the body text is here | 'bodi':4 'text':5 'titl':1
  267. SELECT title, body FROM messages WHERE tsv @@ to_tsquery('title &amp; body');
  268. title | body
  269. ------------+-----------------------
  270. title here | the body text is here
  271. </pre><p>
  272. Having created this trigger, any change in <code class="structfield">title</code> or
  273. <code class="structfield">body</code> will automatically be reflected into
  274. <code class="structfield">tsv</code>, without the application having to worry about it.
  275. </p><p>
  276. The first trigger argument must be the name of the <code class="type">tsvector</code>
  277. column to be updated. The second argument specifies the text search
  278. configuration to be used to perform the conversion. For
  279. <code class="function">tsvector_update_trigger</code>, the configuration name is simply
  280. given as the second trigger argument. It must be schema-qualified as
  281. shown above, so that the trigger behavior will not change with changes
  282. in <code class="varname">search_path</code>. For
  283. <code class="function">tsvector_update_trigger_column</code>, the second trigger argument
  284. is the name of another table column, which must be of type
  285. <code class="type">regconfig</code>. This allows a per-row selection of configuration
  286. to be made. The remaining argument(s) are the names of textual columns
  287. (of type <code class="type">text</code>, <code class="type">varchar</code>, or <code class="type">char</code>). These
  288. will be included in the document in the order given. NULL values will
  289. be skipped (but the other columns will still be indexed).
  290. </p><p>
  291. A limitation of these built-in triggers is that they treat all the
  292. input columns alike. To process columns differently — for
  293. example, to weight title differently from body — it is necessary
  294. to write a custom trigger. Here is an example using
  295. <span class="application">PL/pgSQL</span> as the trigger language:
  296. </p><pre class="programlisting">
  297. CREATE FUNCTION messages_trigger() RETURNS trigger AS $$
  298. begin
  299. new.tsv :=
  300. setweight(to_tsvector('pg_catalog.english', coalesce(new.title,'')), 'A') ||
  301. setweight(to_tsvector('pg_catalog.english', coalesce(new.body,'')), 'D');
  302. return new;
  303. end
  304. $$ LANGUAGE plpgsql;
  305. CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
  306. ON messages FOR EACH ROW EXECUTE FUNCTION messages_trigger();
  307. </pre><p>
  308. </p><p>
  309. Keep in mind that it is important to specify the configuration name
  310. explicitly when creating <code class="type">tsvector</code> values inside triggers,
  311. so that the column's contents will not be affected by changes to
  312. <code class="varname">default_text_search_config</code>. Failure to do this is likely to
  313. lead to problems such as search results changing after a dump and reload.
  314. </p></div><div class="sect2" id="TEXTSEARCH-STATISTICS"><div class="titlepage"><div><div><h3 class="title">12.4.4. Gathering Document Statistics</h3></div></div></div><a id="id-1.5.11.7.6.2" class="indexterm"></a><p>
  315. The function <code class="function">ts_stat</code> is useful for checking your
  316. configuration and for finding stop-word candidates.
  317. </p><pre class="synopsis">
  318. ts_stat(<em class="replaceable"><code>sqlquery</code></em> <code class="type">text</code>, [<span class="optional"> <em class="replaceable"><code>weights</code></em> <code class="type">text</code>, </span>]
  319. OUT <em class="replaceable"><code>word</code></em> <code class="type">text</code>, OUT <em class="replaceable"><code>ndoc</code></em> <code class="type">integer</code>,
  320. OUT <em class="replaceable"><code>nentry</code></em> <code class="type">integer</code>) returns <code class="type">setof record</code>
  321. </pre><p>
  322. <em class="replaceable"><code>sqlquery</code></em> is a text value containing an SQL
  323. query which must return a single <code class="type">tsvector</code> column.
  324. <code class="function">ts_stat</code> executes the query and returns statistics about
  325. each distinct lexeme (word) contained in the <code class="type">tsvector</code>
  326. data. The columns returned are
  327. </p><div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: bullet; "><li class="listitem" style="list-style-type: disc"><p>
  328. <em class="replaceable"><code>word</code></em> <code class="type">text</code> — the value of a lexeme
  329. </p></li><li class="listitem" style="list-style-type: disc"><p>
  330. <em class="replaceable"><code>ndoc</code></em> <code class="type">integer</code> — number of documents
  331. (<code class="type">tsvector</code>s) the word occurred in
  332. </p></li><li class="listitem" style="list-style-type: disc"><p>
  333. <em class="replaceable"><code>nentry</code></em> <code class="type">integer</code> — total number of
  334. occurrences of the word
  335. </p></li></ul></div><p>
  336. If <em class="replaceable"><code>weights</code></em> is supplied, only occurrences
  337. having one of those weights are counted.
  338. </p><p>
  339. For example, to find the ten most frequent words in a document collection:
  340. </p><pre class="programlisting">
  341. SELECT * FROM ts_stat('SELECT vector FROM apod')
  342. ORDER BY nentry DESC, ndoc DESC, word
  343. LIMIT 10;
  344. </pre><p>
  345. The same, but counting only word occurrences with weight <code class="literal">A</code>
  346. or <code class="literal">B</code>:
  347. </p><pre class="programlisting">
  348. SELECT * FROM ts_stat('SELECT vector FROM apod', 'ab')
  349. ORDER BY nentry DESC, ndoc DESC, word
  350. LIMIT 10;
  351. </pre><p>
  352. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="textsearch-controls.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-parsers.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">12.3. Controlling Text Search </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 12.5. Parsers</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1