[pgsql-jp: 41106] Re: pg_trgmは正しく日本語を扱えるでしょうか?

MauMau maumau307 @ gmail.com
2012年 5月 11日 (金) 21:46:19 JST


佐藤さん、板垣さん、松山さん


MauMauです。

日本語を検索できること、および2文字以下ではインデックスが使われないことを教えていただき、ありがとうございます。
また、テキスト検索手法の違いについての板垣さんの資料は、とても勉強になります。 


本家hackers MLで、KEEPONLYNUMの定義を削除することの影響をたずねてみました。
次のように、英数字のみを使う場合に悪影響があるとのことです。
どうも、KEEPONLYNUMを削除することは、単に「英数字以外も検索できるようにする」 

というだけでなく、英数字のみを含むテキストの検索結果を変えてしまうようです。
私の理解が正しいか自信はありませんが、KEEPONLYALNUMは、
トリグラムに英数字以外を含めるかどうかを制御するマクロなのだろうと思います。
KEEPONLYALNUMを削除すると、英数字以外もトリグラムに含まれてしまう。
だから、検索結果が変わってしまう、と推測しました。

「日本語を扱えるようにすると、英数字の扱いが悪くなる」というしかないのでしょうか。
やっかいそうですね・・・


> For information, what kind of breakage would occur?

> I imagined removing KEEPONLYALNUM would just accept
> non-alphanumeric characters and cause no harm to those who use
> only alphanumeric characters.

This would break our current usages because of the handling of
trigrams at the "edges" of groups of qualifying characters.  It
would make similarity (and distance) values less useful for our
current name searches using it.  To simulate the effect, I used an
'8' in place of a comma instead of recompiling with the suggested
change.

test=# select show_trgm('smith,john');
                         show_trgm
-----------------------------------------------------------
 {"  j","  s"," jo"," sm","hn ",ith,joh,mit,ohn,smi,"th "}
(1 row)

test=# select show_trgm('smith8john');
                      show_trgm
-----------------------------------------------------
 {"  s"," sm",8jo,h8j,"hn ",ith,joh,mit,ohn,smi,th8}
(1 row)

test=# select similarity('smith,john', 'jon smith');
 similarity
------------
   0.615385
(1 row)

test=# select similarity('smith8john', 'jon smith');
 similarity
------------
     0.3125
(1 row)

So making the proposed change unconditionally could indeed hurt
current users of the technique.  On the other hand, if there was
fine-grained control of this, it might make trigrams useful for
searching statute cites (using all characters) as well as names
(using the current character set); so I wouldn't want it to just be
controlled by a global GUC.

-Kevin



pgsql-jp メーリングリストの案内