gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 satır
8.9KB

  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.15. fuzzystrmatch</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="file-fdw.html" title="F.14. file_fdw" /><link rel="next" href="hstore.html" title="F.16. hstore" /></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">F.15. fuzzystrmatch</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="file-fdw.html" title="F.14. file_fdw">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules</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="hstore.html" title="F.16. hstore">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FUZZYSTRMATCH"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.15. fuzzystrmatch</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="fuzzystrmatch.html#id-1.11.7.24.5">F.15.1. Soundex</a></span></dt><dt><span class="sect2"><a href="fuzzystrmatch.html#id-1.11.7.24.6">F.15.2. Levenshtein</a></span></dt><dt><span class="sect2"><a href="fuzzystrmatch.html#id-1.11.7.24.7">F.15.3. Metaphone</a></span></dt><dt><span class="sect2"><a href="fuzzystrmatch.html#id-1.11.7.24.8">F.15.4. Double Metaphone</a></span></dt></dl></div><a id="id-1.11.7.24.2" class="indexterm"></a><p>
  3. The <code class="filename">fuzzystrmatch</code> module provides several
  4. functions to determine similarities and distance between strings.
  5. </p><div class="caution"><h3 class="title">Caution</h3><p>
  6. At present, the <code class="function">soundex</code>, <code class="function">metaphone</code>,
  7. <code class="function">dmetaphone</code>, and <code class="function">dmetaphone_alt</code> functions do
  8. not work well with multibyte encodings (such as UTF-8).
  9. </p></div><div class="sect2" id="id-1.11.7.24.5"><div class="titlepage"><div><div><h3 class="title">F.15.1. Soundex</h3></div></div></div><p>
  10. The Soundex system is a method of matching similar-sounding names
  11. by converting them to the same code. It was initially used by the
  12. United States Census in 1880, 1900, and 1910. Note that Soundex
  13. is not very useful for non-English names.
  14. </p><p>
  15. The <code class="filename">fuzzystrmatch</code> module provides two functions
  16. for working with Soundex codes:
  17. </p><a id="id-1.11.7.24.5.4" class="indexterm"></a><a id="id-1.11.7.24.5.5" class="indexterm"></a><pre class="synopsis">
  18. soundex(text) returns text
  19. difference(text, text) returns int
  20. </pre><p>
  21. The <code class="function">soundex</code> function converts a string to its Soundex code.
  22. The <code class="function">difference</code> function converts two strings to their Soundex
  23. codes and then reports the number of matching code positions. Since
  24. Soundex codes have four characters, the result ranges from zero to four,
  25. with zero being no match and four being an exact match. (Thus, the
  26. function is misnamed — <code class="function">similarity</code> would have been
  27. a better name.)
  28. </p><p>
  29. Here are some usage examples:
  30. </p><pre class="programlisting">
  31. SELECT soundex('hello world!');
  32. SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann');
  33. SELECT soundex('Anne'), soundex('Andrew'), difference('Anne', 'Andrew');
  34. SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret');
  35. CREATE TABLE s (nm text);
  36. INSERT INTO s VALUES ('john');
  37. INSERT INTO s VALUES ('joan');
  38. INSERT INTO s VALUES ('wobbly');
  39. INSERT INTO s VALUES ('jack');
  40. SELECT * FROM s WHERE soundex(nm) = soundex('john');
  41. SELECT * FROM s WHERE difference(s.nm, 'john') &gt; 2;
  42. </pre></div><div class="sect2" id="id-1.11.7.24.6"><div class="titlepage"><div><div><h3 class="title">F.15.2. Levenshtein</h3></div></div></div><p>
  43. This function calculates the Levenshtein distance between two strings:
  44. </p><a id="id-1.11.7.24.6.3" class="indexterm"></a><a id="id-1.11.7.24.6.4" class="indexterm"></a><pre class="synopsis">
  45. levenshtein(text source, text target, int ins_cost, int del_cost, int sub_cost) returns int
  46. levenshtein(text source, text target) returns int
  47. levenshtein_less_equal(text source, text target, int ins_cost, int del_cost, int sub_cost, int max_d) returns int
  48. levenshtein_less_equal(text source, text target, int max_d) returns int
  49. </pre><p>
  50. Both <code class="literal">source</code> and <code class="literal">target</code> can be any
  51. non-null string, with a maximum of 255 characters. The cost parameters
  52. specify how much to charge for a character insertion, deletion, or
  53. substitution, respectively. You can omit the cost parameters, as in
  54. the second version of the function; in that case they all default to 1.
  55. </p><p>
  56. <code class="function">levenshtein_less_equal</code> is an accelerated version of the
  57. Levenshtein function for use when only small distances are of interest.
  58. If the actual distance is less than or equal to <code class="literal">max_d</code>,
  59. then <code class="function">levenshtein_less_equal</code> returns the correct
  60. distance; otherwise it returns some value greater than <code class="literal">max_d</code>.
  61. If <code class="literal">max_d</code> is negative then the behavior is the same as
  62. <code class="function">levenshtein</code>.
  63. </p><p>
  64. Examples:
  65. </p><pre class="screen">
  66. test=# SELECT levenshtein('GUMBO', 'GAMBOL');
  67. levenshtein
  68. -------------
  69. 2
  70. (1 row)
  71. test=# SELECT levenshtein('GUMBO', 'GAMBOL', 2, 1, 1);
  72. levenshtein
  73. -------------
  74. 3
  75. (1 row)
  76. test=# SELECT levenshtein_less_equal('extensive', 'exhaustive', 2);
  77. levenshtein_less_equal
  78. ------------------------
  79. 3
  80. (1 row)
  81. test=# SELECT levenshtein_less_equal('extensive', 'exhaustive', 4);
  82. levenshtein_less_equal
  83. ------------------------
  84. 4
  85. (1 row)
  86. </pre></div><div class="sect2" id="id-1.11.7.24.7"><div class="titlepage"><div><div><h3 class="title">F.15.3. Metaphone</h3></div></div></div><p>
  87. Metaphone, like Soundex, is based on the idea of constructing a
  88. representative code for an input string. Two strings are then
  89. deemed similar if they have the same codes.
  90. </p><p>
  91. This function calculates the metaphone code of an input string:
  92. </p><a id="id-1.11.7.24.7.4" class="indexterm"></a><pre class="synopsis">
  93. metaphone(text source, int max_output_length) returns text
  94. </pre><p>
  95. <code class="literal">source</code> has to be a non-null string with a maximum of
  96. 255 characters. <code class="literal">max_output_length</code> sets the maximum
  97. length of the output metaphone code; if longer, the output is truncated
  98. to this length.
  99. </p><p>
  100. Example:
  101. </p><pre class="screen">
  102. test=# SELECT metaphone('GUMBO', 4);
  103. metaphone
  104. -----------
  105. KM
  106. (1 row)
  107. </pre></div><div class="sect2" id="id-1.11.7.24.8"><div class="titlepage"><div><div><h3 class="title">F.15.4. Double Metaphone</h3></div></div></div><p>
  108. The Double Metaphone system computes two <span class="quote">“<span class="quote">sounds like</span>”</span> strings
  109. for a given input string — a <span class="quote">“<span class="quote">primary</span>”</span> and an
  110. <span class="quote">“<span class="quote">alternate</span>”</span>. In most cases they are the same, but for non-English
  111. names especially they can be a bit different, depending on pronunciation.
  112. These functions compute the primary and alternate codes:
  113. </p><a id="id-1.11.7.24.8.3" class="indexterm"></a><a id="id-1.11.7.24.8.4" class="indexterm"></a><pre class="synopsis">
  114. dmetaphone(text source) returns text
  115. dmetaphone_alt(text source) returns text
  116. </pre><p>
  117. There is no length limit on the input strings.
  118. </p><p>
  119. Example:
  120. </p><pre class="screen">
  121. test=# SELECT dmetaphone('gumbo');
  122. dmetaphone
  123. ------------
  124. KMP
  125. (1 row)
  126. </pre></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="file-fdw.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="hstore.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.14. file_fdw </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> F.16. hstore</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1