SHIDARA Yoji
daras****@gmail*****
2009年 6月 29日 (月) 16:37:43 JST
こんにちは、daraです。 bigramでtokenizeしてインデクスを作成すると、 1文字のクエリに対して得られる結果が少ないようです。 そのクエリ文字列と等しい文書にしかマッチしていないものと思われます。 trigramのときは2文字または1文字のクエリのとき同様の状況になります。 #もしかするとこれは仕様でしょうか? groonga本体の話のような気がするのでruby-groongaのコードで恐縮ですが、 以下のようなテストを追加すると、 dara @ buzztter:~/local/src/ruby-groonga$ svn diff Index: test/test-index-column.rb =================================================================== --- test/test-index-column.rb (リビジョン 410) +++ test/test-index-column.rb (作業コピー) @@ -54,4 +54,20 @@ assert_equal([groonga], content_index.search("エンジン").collect {|record| record.key}) end + def test_shorter_query_than_ngram + articles = Groonga::Array.create(:name => "<articles>") + articles.define_column("content", "<text>") + + terms = Groonga::Hash.create(:name => "<terms>", + :default_tokenizer => "<token:bigram>") + content_index = terms.define_index_column("content", articles, + :source => "<articles>.content") + articles.add(:content => 'l') + articles.add(:content => 'll') + articles.add(:content => 'hello') + + assert_equal(1, content_index.search("he").size) + assert_equal(2, content_index.search("ll").size) + assert_equal(3, content_index.search("l").size) + end end 結果が 2) Failure: test_shorter_query_than_ngram(IndexColumnTest) [./test/test-index-column.rb:71]: <3> expected but was <1>. となります。 ここで、test-index-column.rb:71 は assert_equal(3, content_index.search("l").size) です。 (ちなみに ruby test/run-test.rb では以下のようなエラーも出ています) 1) Failure: test_each(DatabaseTest) [./test/test-database.rb:84]: <["<float>", "<int64>", "<int>", "<longtext>", "<proc:disp>", "<proc:init>", "<proc:scan>", "<proc:search>", "<ranguba:objects>", "<shorttext>", "<text>", "<time>", "<token:bigram>", "<token:delimit>", "<token:mecab>", "<token:trigram>", "<token:unigram>", "<uint64>", "<uint>"]> expected but was <["<float>", "<int64>", "<int>", "<longtext>", "<ranguba:objects>", "<shorttext>", "<text>", "<time>", "<token:bigram>", "<token:delimit>", "<token:mecab>", "<token:trigram>", "<token:unigram>", "<uint64>", "<uint>"]>. diff: ["<float>", "<int64>", "<int>", "<longtext>", - "<proc:disp>", - "<proc:init>", - "<proc:scan>", - "<proc:search>", "<ranguba:objects>", "<shorttext>", "<text>", "<time>", "<token:bigram>", "<token:delimit>", "<token:mecab>", "<token:trigram>", "<token:unigram>", "<uint64>", "<uint>"] -- SHIDARA Yoji