OSDN Git Service

Add the descriptions of similarity search into the document.
authorMasaoFujii <masao.fujii@gmail.com>
Wed, 23 Oct 2013 13:26:55 +0000 (22:26 +0900)
committerMasaoFujii <masao.fujii@gmail.com>
Wed, 23 Oct 2013 13:26:55 +0000 (22:26 +0900)
html/pg_bigm-1-1.html
html/pg_bigm_en-1-1.html

index e23afad..23763c5 100644 (file)
@@ -78,7 +78,7 @@
   <td>高速<br>(検索時に全文検索インデックスを使える)</td></tr>
 <tr><td>類似文字列の検索</td>
   <td nowrap>対応済</td>
-  <td>未対応</td></tr>
+  <td>対応済(バージョン1.1以降)</td></tr>
 <tr><td>データベースのエンコーディングとロケール</td>
   <td nowrap>制限なし</td>
   <td>使用できるデータベースエンコーディングはUTF-8のみ。ロケールはCのみ</td></tr>
@@ -251,6 +251,20 @@ $ su
 <li>検索文字列は<a href="#likequery">likequery</a>に記載されているとおり、全文検索用に変換されなければなりません。</li>
 </ul>
 
+<h3 id="similarity_search">類似度検索の実行</h3>
+<p>pg_bigmでは、=% 演算子を使って類似度検索を行います。</p>
+<p>以下の実行例では、文字列「bigm」に似た文字列のtool列を検索しています。この類似度検索も、全文検索と同様にインデックスにより高速に実行されます。文字列どうしが似ているかどうかは、それら文字列の類似度が<a href="#similarity_limit">pg_bigm.similarity_limit</a>の設定値以上かどうかで判断されます。この実行例では、文字列「bigm」との類似度が0.2以上だった「pg_bigm」と「pg_trgm」のtool列だけが検索結果となります。</p>
+<pre>
+=# SET pg_bigm.similarity_limit TO 0.2;
+
+=# SELECT tool FROM pg_tools WHERE tool =% 'bigm';
+  tool   
+---------
+ pg_bigm
+ pg_trgm
+(2 rows)
+</pre>
+
 <h2 id="functions">提供関数</h2>
 <h3 id="likequery">likequery</h3>
 <p>likequeryは、全文検索できるように、検索文字列(引数1)をLIKE演算子のパターンに変換する関数です。</p>
@@ -427,6 +441,9 @@ $ su
 
 <p>ただし、インデックス検索に使う2-gram文字列の個数が減ると、インデックスから取得した検索結果候補にはより多くの誤った結果が含まれることになります。このため、Recheckの負荷が高まり、逆に、より性能劣化する可能性もあるため注意が必要です。</p>
 
+<h3 id="similarity_limit">pg_bigm.similarity_limit</h3>
+<p>pg_bigm.similarity_limitは、類似度検索の閾値を指定するパラメータです。類似度検索では、検索条件の文字列との類似度がこの閾値以上の行が検索結果となります。設定値は0以上1以下の小数点数で、デフォルト値は0.3です。このパラメータは、postgresql.confとSET文(スーパーユーザに限らずどのユーザからでも)で設定値を変更できます。</p>
+
 <h2 id="release_notes">リリースノート</h2>
 <ul>
 <li><a href="release-1-1-201310xx.html">バージョン1.1 (2013-10-xx リリース)</a></li>
index c233576..580325b 100644 (file)
@@ -78,7 +78,7 @@
   <td>Fast</td></tr>
 <tr><td>Similarity search</td>
   <td nowrap>Supported</td>
-  <td>Not supported</td></tr>
+  <td>Supported (version 1.1 or later)</td></tr>
 <tr><td>Available database encoding and locale</td>
   <td nowrap>Same as PostgreSQL</td>
   <td>Only encoding UTF-8 and locale C</td></tr>
@@ -250,6 +250,20 @@ $ su
 <li>The search keyword must be specified as the pattern string that LIKE operator can handle properly, as discussed in <a href="#likequery">likequery</a>.</li>
 </ul>
 
+<h3 id="similarity_search">Execute similarity search</h3>
+<p>You can execute similarity search by using =% operator.</p>
+<p>The following query returns all values in the tool column that are sufficiently similar to the word 'bigm'. This similarity search is basically fast because it can use the full text search index. It measures whether two strings are sufficiently similar to by seeing whether their similarity is higher than or equal to the value of <a href="#similarity_limit">pg_bigm.similarity_limit</a>. This means, in this query, that the values whose similarity with the word 'bigm' is higher than or equal to 0.2 are only 'pg_bigm' and 'pg_trgm' in the tool column.</p>
+<pre>
+=# SET pg_bigm.similarity_limit TO 0.2;
+
+=# SELECT tool FROM pg_tools WHERE tool =% 'bigm';
+  tool   
+---------
+ pg_bigm
+ pg_trgm
+(2 rows)
+</pre>
+
 <h2 id="functions">Functions</h2>
 <h3 id="likequery">likequery</h3>
 <p>likequery is a function that converts the search keyword (argument #1) into the pattern string that LIKE operator can handle properly.</p>
@@ -424,6 +438,9 @@ Example
 
 <p>On the other hand, the less 2-grams are used, the more wrong results are included in the result candidates retrieved from full text search index. Please note that this can increase the workload of Recheck and decrease the performance.</p>
 
+<h3 id="similarity_limit">pg_bigm.similarity_limit</h3>
+<p>pg_bigm.similarity_limit is a parameter that specifies the threshold used by the similarity search. The similarity search returns all the rows whose similarity with the search keyword is higher than or equal to this threshold. Value must be between 0 and 1 (default is 0.3). Not only superuser but also any user can change this parameter value in postgresql.conf or by using SET command.</p>
+
 <h2 id="release_notes">Release Notes</h2>
 <ul>
 <li><a href="release-1-1-201310xx_en.html">Version 1.1, released on 2013-10-xx</a></li>