SHIDARA Yoji
dara****@shida*****
2009年 9月 13日 (日) 09:09:15 JST
こんにちは、daraです。
:key_normalize => true としたとき、
文字種が切り替わる部分をまたぐようなクエリに
レコードがヒットしないという現象があるように思われます。
#まだ条件が完全には把握できていませんが・・・
:key_normalize => trueとすると、たとえば
"うちのボロTVはまだ現役です" という文字列に対して
「ボロTV」というクエリがヒットしなくなります。
Ruby/Groonga: r655
groonga: commit b21711e861bbcd371db98f325cf6187a1598ac4d
にて、以下のスクリプトで確認しました。
#!/usr/bin/env ruby
$KCODE='u'
require 'groonga'
target = 'うちのボロTVはまだ現役です'
p target
for normalize in [true, false]
Groonga::Database.create(:path => 'db-'+ (normalize ? 't' : 'f'))
Groonga::Schema.define do |schema|
schema.create_table("data", :type => :hash) do |table|
table.text("text")
end
schema.create_table("terms",
:type => :patricia_trie,
:key_normalize => normalize,
:default_tokenizer => "TokenBigram") do |table|
table.index("data.text")
end
end
data = Groonga::Context.default['data']
data.add('1', :text => target)
queries = %w(TV のボロ ボロ ボロTV ロTV TVは ははは)
queries.each do |query|
size = data.select {|d| d['text'].match query}.size
p [normalize, query, size]
end
end
実行結果は以下の通りです。
最初の要素がkey_normalize、次の要素がクエリ、最後の要素がヒット数です。
$ ./testnormalize.rb
"うちのボロTVはまだ現役です"
[true, "TV", 1]
[true, "のボロ", 1]
[true, "ボロ", 1]
[true, "ボロTV", 0] # これは1であるべきでは
[true, "ロTV", 1]
[true, "TVは", 1]
[true, "ははは", 0]
[false, "TV", 1]
[false, "のボロ", 1]
[false, "ボロ", 1]
[false, "ボロTV", 1] # これは1で期待通り
[false, "ロTV", 1]
[false, "TVは", 1]
[false, "ははは", 0]
ruby-groongaのテストに書き足してみました。
dara @ buzztter:~/local/src/ruby-groonga$ svn diff
Index: test/test-table-select.rb
===================================================================
--- test/test-table-select.rb (リビジョン 658)
+++ test/test-table-select.rb (作業コピー)
@@ -23,7 +23,7 @@
@comments = Groonga::Array.create(:name => "comments")
@comments.define_column("content", "Text")
@comments.define_column("created_at", "Time")
- terms = Groonga::PatriciaTrie.create(:name => "terms")
+ terms = Groonga::PatriciaTrie.create(:name => "terms",
:default_tokenizer => "TokenBigram", :key_normalize => true)
terms.define_index_column("comment_content", @comments,
:with_section => true,
:source => "comments.content")
@@ -33,6 +33,8 @@
:created_at => Time.parse("2009-07-09"))
@comment3 =****@comme*****(:content => "test",
:created_at => Time.parse("2009-06-09"))
+ @comment4 =****@comme*****(:content => "うちのボロTVはまだ現役です",
+ :created_at => Time.parse("2009-06-09"))
end
def test_select_sub_expression
@@ -48,7 +50,7 @@
result =****@comme*****("content:%Hello")
assert_equal([@comment1, @comment2], result.collect {|record| record.key})
end
-
+
priority :must
def test_select_query_with_block
result =****@comme*****("content:%Hello") do |record|
@@ -68,4 +70,9 @@
assert_equal([@comment1, @comment2, @comment3],
@comments.select.collect {|record| record.key})
end
+
+ def test_select_query_with_japanese
+ result =****@comme*****("content:%ボロTV")
+ assert_equal([@comment4], result.collect {|record| record.key})
+ end
end
実行結果(当該部分抜粋)は以下のようになりました。
4) Failure:
test_select_query_with_japanese(TableTestSelect)
[./test/test-table-select.rb:76]:
<[#<Groonga::Record:0x7f593ff8b368
@id=4,
@table=
#<Groonga::Array id: <256>, name: <comments>, path:
</home/dara/local/src/ruby-groonga/test/tmp/database.0000100>, domain:
<nil>, range: <nil>, flags: <>, size: <4>>>]> expected but was
<[]>.
diff:
+ []
- [#<Groonga::Record:0x7f593ff8b368
- @id=4,
- @table=
- #<Groonga::Array id: <256>, name: <comments>, path:
</home/dara/local/src/ruby-groonga/test/tmp/database.0000100>, domain:
<nil>, range: <nil>, flags: <>, size: <4>>>]
folded diff:
+ []
- [#<Groonga::Record:0x7f593ff8b368
- @id=4,
- @table=
- #<Groonga::Array id: <256>, name: <comments>, path: </home/dara/local/src/r
- uby-groonga/test/tmp/database.0000100>, domain: <nil>, range: <nil>, flags: <>
- , size: <4>>>]
--
SHIDARA Yoji
本を書きました! http://www.amazon.co.jp/dp/4798119881