groonga 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/NEWS.ja.rdoc +11 -0
  2. data/NEWS.rdoc +11 -0
  3. data/README.ja.rdoc +4 -3
  4. data/README.rdoc +4 -3
  5. data/Rakefile +1 -1
  6. data/TUTORIAL.ja.rdoc +168 -44
  7. data/benchmark/common.rb +49 -0
  8. data/benchmark/read-write-small-many-items.rb +156 -0
  9. data/benchmark/write-small-many-items.rb +145 -0
  10. data/example/bookmark.rb +68 -20
  11. data/ext/rb-grn-array-cursor.c +8 -0
  12. data/ext/rb-grn-array.c +40 -11
  13. data/ext/rb-grn-column.c +38 -209
  14. data/ext/rb-grn-context.c +203 -56
  15. data/ext/rb-grn-database.c +119 -5
  16. data/ext/rb-grn-encoding-support.c +64 -0
  17. data/ext/rb-grn-encoding.c +58 -1
  18. data/ext/rb-grn-fix-size-column.c +220 -0
  19. data/ext/rb-grn-hash-cursor.c +8 -0
  20. data/ext/rb-grn-hash.c +244 -2
  21. data/ext/rb-grn-index-column.c +474 -0
  22. data/ext/rb-grn-object.c +143 -265
  23. data/ext/rb-grn-patricia-trie.c +148 -2
  24. data/ext/rb-grn-query.c +5 -3
  25. data/ext/rb-grn-record.c +3 -2
  26. data/ext/rb-grn-snippet.c +5 -3
  27. data/ext/rb-grn-table-cursor-key-support.c +3 -3
  28. data/ext/rb-grn-table-cursor.c +106 -112
  29. data/ext/rb-grn-table-key-support.c +220 -118
  30. data/ext/rb-grn-table.c +336 -80
  31. data/ext/rb-grn-type.c +5 -4
  32. data/ext/rb-grn-utils.c +62 -63
  33. data/ext/rb-grn.h +215 -14
  34. data/ext/rb-groonga.c +7 -16
  35. data/extconf.rb +3 -1
  36. data/html/favicon.ico +0 -0
  37. data/html/favicon.xcf +0 -0
  38. data/html/index.html +1 -7
  39. data/lib/groonga/record.rb +6 -1
  40. data/test/groonga-test-utils.rb +1 -0
  41. data/test/test-array.rb +81 -0
  42. data/test/test-column.rb +22 -12
  43. data/test/test-context.rb +1 -29
  44. data/test/test-database.rb +30 -0
  45. data/test/test-hash.rb +194 -0
  46. data/test/test-index-column.rb +57 -0
  47. data/test/test-patricia-trie.rb +82 -0
  48. data/test/test-record.rb +10 -10
  49. data/test/test-table.rb +37 -130
  50. data/test/test-type.rb +4 -3
  51. metadata +15 -4
  52. data/benchmark/small-many-items.rb +0 -175
@@ -18,9 +18,14 @@
18
18
  module Groonga
19
19
  class Record
20
20
  attr_reader :table, :id
21
- def initialize(table, id)
21
+ def initialize(table, id, values=nil)
22
22
  @table = table
23
23
  @id = id
24
+ if values
25
+ values.each do |name, value|
26
+ self[name] = value
27
+ end
28
+ end
24
29
  end
25
30
 
26
31
  def ==(other)
@@ -80,6 +80,7 @@ module GroongaTestUtils
80
80
  end
81
81
 
82
82
  def teardown_sandbox
83
+ @database = nil
83
84
  teardown_tmp_directory
84
85
  GC.start
85
86
  end
@@ -0,0 +1,81 @@
1
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ class ArrayTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_inspect_size
22
+ path = @tables_dir + "named.groonga"
23
+ contain_table = Groonga::Array.create(:name => "name", :path => path.to_s)
24
+ 3.times do
25
+ contain_table.add
26
+ end
27
+ assert_equal("#<Groonga::Array " +
28
+ "id: <#{contain_table.id}>, " +
29
+ "name: <name>, " +
30
+ "path: <#{path}>, " +
31
+ "domain: <nil>, " +
32
+ "range: <nil>, " +
33
+ "size: <3>>",
34
+ contain_table.inspect)
35
+ end
36
+
37
+ def test_encoding
38
+ array = Groonga::Array.create
39
+ assert_false(array.respond_to?(:encoding))
40
+ end
41
+
42
+ def test_add
43
+ users = Groonga::Array.create(:name => "<users>")
44
+ users.define_column("name", "<text>")
45
+ me = users.add(:name => "me")
46
+ assert_equal("me", me[:name])
47
+ end
48
+
49
+ def test_define_index_column
50
+ users = Groonga::Array.create(:name => "<users>")
51
+ users.define_column("name", "<text>")
52
+ bookmarks = Groonga::Array.create(:name => "<bookmarks>")
53
+ bookmarks.define_column("title", "<text>")
54
+ bookmarks.define_column("user", users)
55
+
56
+ index = users.define_index_column("bookmarks", bookmarks,
57
+ :source => "<bookmarks>.user")
58
+ morita = users.add(:name => "morita")
59
+ gunyara_kun = users.add(:name => "gunyara-kun")
60
+ groonga = bookmarks.add(:title => "groonga", :user => morita)
61
+ google = bookmarks.add(:title => "google", :user => morita)
62
+ python = bookmarks.add(:title => "Python", :user => gunyara_kun)
63
+
64
+ assert_equal(["groonga", "google"],
65
+ index.search(morita.id).collect {|record| record.key["title"]})
66
+ end
67
+
68
+ def test_create_duplicated_name
69
+ Groonga::Array.create(:name => "<users>")
70
+ assert_raise(Groonga::InvalidArgument) do
71
+ Groonga::Array.create(:name => "<users>")
72
+ end
73
+ end
74
+
75
+ def test_open_same_name
76
+ users_created = Groonga::Array.create(:name => "<users>")
77
+ users_opened = Groonga::Array.open(:name => "<users>")
78
+ users_opened.add
79
+ assert_equal(1, users_created.size)
80
+ end
81
+ end
data/test/test-column.rb CHANGED
@@ -62,20 +62,20 @@ class ColumnTest < Test::Unit::TestCase
62
62
  Groonga::PatriciaTrie.create(:name => "bookmarks-index",
63
63
  :path => @bookmarks_index_path.to_s,
64
64
  :key_type => "<shorttext>")
65
+ @bookmarks_index.default_tokenizer = "<token:bigram>"
66
+
65
67
  @content_index_column_path = @columns_dir + "content-index"
66
68
  @bookmarks_index_content =
67
- @bookmarks_index.define_column("<index:content>", @bookmarks,
68
- :type => "index",
69
- :with_section => true,
70
- :with_weight => true,
71
- :with_position => true,
72
- :path => @content_index_column_path.to_s)
69
+ @bookmarks_index.define_index_column("<index:content>", @bookmarks,
70
+ :with_section => true,
71
+ :with_weight => true,
72
+ :with_position => true,
73
+ :path => @content_index_column_path.to_s)
73
74
 
74
75
  @uri_index_column_path = @columns_dir + "uri-index"
75
76
  @bookmarks_index_uri =
76
- @bookmarks_index.define_column("<index:uri>", @bookmarks,
77
- :type => "index",
78
- :path => @uri_index_column_path.to_s)
77
+ @bookmarks_index.define_index_column("<index:uri>", @bookmarks,
78
+ :path => @uri_index_column_path.to_s)
79
79
  end
80
80
 
81
81
  def test_source_info
@@ -126,9 +126,9 @@ class ColumnTest < Test::Unit::TestCase
126
126
 
127
127
  index = Groonga::PatriciaTrie.create(:name => "<terms>",
128
128
  :key_type => "<shorttext>")
129
- content_index = index.define_column("content_index", comments,
130
- :type => "index",
131
- :with_position => true)
129
+ index.default_tokenizer = "<token:bigram>"
130
+ content_index = index.define_index_column("content_index", comments,
131
+ :with_position => true)
132
132
  content_index.source = content
133
133
 
134
134
  first_post = posts.add("Hello!")
@@ -176,6 +176,16 @@ class ColumnTest < Test::Unit::TestCase
176
176
  assert_equal(@users, @users_name_column.table)
177
177
  end
178
178
 
179
+ def test_array_set_with_key_of_table
180
+ users = Groonga::Hash.create(:name => "<users>")
181
+ bookmarks = Groonga::Hash.create(:name => "<bookmarks>")
182
+ bookmarks.define_column("user", users)
183
+
184
+ users.add("morita")
185
+ groonga = bookmarks.add("http://groonga.org/", :user => "morita")
186
+ assert_equal("morita", groonga[:user].key)
187
+ end
188
+
179
189
  private
180
190
  def assert_content_search(expected_records, term)
181
191
  records = @bookmarks_index_content.search(term).records
data/test/test-context.rb CHANGED
@@ -18,39 +18,17 @@ class ContextTest < Test::Unit::TestCase
18
18
 
19
19
  def test_default
20
20
  context = Groonga::Context.default
21
- assert_not_predicate(context, :use_ql?)
22
- assert_not_predicate(context, :batch_mode?)
23
21
  assert_equal(Groonga::Encoding.default, context.encoding)
24
22
  end
25
23
 
26
24
  def test_default_options
27
25
  Groonga::Context.default_options = {
28
- :use_ql => true,
29
- :batch_mode => true,
30
26
  :encoding => :utf8,
31
27
  }
32
28
  context = Groonga::Context.default
33
- assert_predicate(context, :use_ql?)
34
- assert_predicate(context, :batch_mode?)
35
29
  assert_equal(Groonga::Encoding::UTF8, context.encoding)
36
30
  end
37
31
 
38
- def test_use_ql?
39
- context = Groonga::Context.new
40
- assert_not_predicate(context, :use_ql?)
41
-
42
- context = Groonga::Context.new(:use_ql => true)
43
- assert_predicate(context, :use_ql?)
44
- end
45
-
46
- def test_batch_mode?
47
- context = Groonga::Context.new
48
- assert_not_predicate(context, :batch_mode?)
49
-
50
- context = Groonga::Context.new(:batch_mode => true)
51
- assert_predicate(context, :batch_mode?)
52
- end
53
-
54
32
  def test_encoding
55
33
  context = Groonga::Context.new
56
34
  assert_equal(Groonga::Encoding.default, context.encoding)
@@ -60,12 +38,8 @@ class ContextTest < Test::Unit::TestCase
60
38
  end
61
39
 
62
40
  def test_inspect
63
- context = Groonga::Context.new(:use_ql => true,
64
- :batch_mode => true,
65
- :encoding => Groonga::Encoding::UTF8)
41
+ context = Groonga::Context.new(:encoding => Groonga::Encoding::UTF8)
66
42
  assert_equal("#<Groonga::Context " +
67
- "use_ql: <true>, " +
68
- "batch_mode: <true>, " +
69
43
  "encoding: <:utf8>, " +
70
44
  "database: <nil>>",
71
45
  context.inspect)
@@ -75,8 +49,6 @@ class ContextTest < Test::Unit::TestCase
75
49
  db = Groonga::Database.create
76
50
  context = Groonga::Context.default
77
51
  assert_equal("#<Groonga::Context " +
78
- "use_ql: <false>, " +
79
- "batch_mode: <false>, " +
80
52
  "encoding: <#{Groonga::Encoding.default.inspect}>, " +
81
53
  "database: <#{db.inspect}>>",
82
54
  context.inspect)
@@ -59,4 +59,34 @@ class DatabaseTest < Test::Unit::TestCase
59
59
 
60
60
  assert_not_predicate(Groonga::Database.new(db_path.to_s), :closed?)
61
61
  end
62
+
63
+ def test_each
64
+ db_path = @tmp_dir + "db"
65
+ database = Groonga::Database.create(:path => db_path.to_s)
66
+ assert_equal(["<float>",
67
+ "<int64>",
68
+ "<int>",
69
+ "<longtext>",
70
+ "<proc:disp>",
71
+ "<proc:init>",
72
+ "<proc:scan>",
73
+ "<proc:search>",
74
+ "<ranguba:objects>",
75
+ "<shorttext>",
76
+ "<text>",
77
+ "<time>",
78
+ "<token:bigram>",
79
+ "<token:delimit>",
80
+ "<token:mecab>",
81
+ "<token:trigram>",
82
+ "<token:unigram>",
83
+ "<uint64>",
84
+ "<uint>"],
85
+ database.collect {|object| object.name}.sort)
86
+ end
87
+
88
+ def test_encoding
89
+ assert_equal(Groonga::Encoding.default,
90
+ Groonga::Database.create.encoding)
91
+ end
62
92
  end
data/test/test-hash.rb ADDED
@@ -0,0 +1,194 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License version 2.1 as published by the Free Software Foundation.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+
17
+ class HashTest < Test::Unit::TestCase
18
+ include GroongaTestUtils
19
+
20
+ setup :setup_database
21
+
22
+ def test_delete
23
+ bookmarks_path = @tables_dir + "bookmarks"
24
+ bookmarks = Groonga::Hash.create(:name => "bookmarks",
25
+ :path => bookmarks_path.to_s)
26
+
27
+ groonga = bookmarks.add("groonga")
28
+ google = bookmarks.add("Google")
29
+ cutter = bookmarks.add("Cutter")
30
+
31
+ assert_equal(["groonga", "Google", "Cutter"],
32
+ bookmarks.collect {|bookmark| bookmark.key})
33
+
34
+ bookmarks.delete(google.id)
35
+ assert_equal(["groonga", "Cutter"],
36
+ bookmarks.collect {|bookmark| bookmark.key})
37
+
38
+ bookmarks.delete(cutter.key)
39
+ assert_equal(["groonga"],
40
+ bookmarks.collect {|bookmark| bookmark.key})
41
+ end
42
+
43
+ def test_array_reference
44
+ value = "groonga"
45
+ bookmarks_path = @tables_dir + "bookmarks"
46
+ bookmarks = Groonga::Hash.create(:name => "bookmarks",
47
+ :path => bookmarks_path.to_s,
48
+ :key_type => "<shorttext>",
49
+ :value_size => value.size)
50
+ bookmarks["http://google.com/"] = value
51
+ assert_equal(value, bookmarks["http://google.com/"])
52
+ end
53
+
54
+ def test_find
55
+ bookmarks_path = @tables_dir + "bookmarks"
56
+ bookmarks = Groonga::Hash.create(:name => "bookmarks",
57
+ :path => bookmarks_path.to_s,
58
+ :key_type => "<shorttext>")
59
+ bookmark = bookmarks.add("http://google.com/")
60
+ assert_equal(bookmark, bookmarks.find("http://google.com/"))
61
+ end
62
+
63
+
64
+ def test_inspect_anonymous
65
+ path = @tables_dir + "anoymous.groonga"
66
+ anonymous_table = Groonga::Hash.create(:path => path.to_s)
67
+ assert_equal("#<Groonga::Hash " +
68
+ "id: <#{anonymous_table.id}>, " +
69
+ "name: (anonymous), " +
70
+ "path: <#{path}>, " +
71
+ "domain: <nil>, " +
72
+ "range: <nil>, " +
73
+ "encoding: <#{encoding.inspect}>, " +
74
+ "size: <0>>",
75
+ anonymous_table.inspect)
76
+ end
77
+
78
+ def test_inspect_anonymous_temporary
79
+ anonymous_table = Groonga::Hash.create
80
+ assert_equal("#<Groonga::Hash " +
81
+ "id: <#{anonymous_table.id}>, " +
82
+ "name: (anonymous), " +
83
+ "path: (temporary), " +
84
+ "domain: <nil>, " +
85
+ "range: <nil>, " +
86
+ "encoding: <#{encoding.inspect}>, " +
87
+ "size: <0>>",
88
+ anonymous_table.inspect)
89
+ end
90
+
91
+ def test_inspect_named
92
+ path = @tables_dir + "named.groonga"
93
+ named_table = Groonga::Hash.create(:name => "name", :path => path.to_s)
94
+ assert_equal("#<Groonga::Hash " +
95
+ "id: <#{named_table.id}>, " +
96
+ "name: <name>, " +
97
+ "path: <#{path}>, " +
98
+ "domain: <nil>, " +
99
+ "range: <nil>, " +
100
+ "encoding: <#{encoding.inspect}>, " +
101
+ "size: <0>>",
102
+ named_table.inspect)
103
+ end
104
+
105
+ def test_inspect_named_temporary
106
+ named_table = Groonga::Hash.create(:name => "name")
107
+ assert_equal("#<Groonga::Hash " +
108
+ "id: <#{named_table.id}>, " +
109
+ "name: <name>, " +
110
+ "path: (temporary), " +
111
+ "domain: <nil>, " +
112
+ "range: <nil>, " +
113
+ "encoding: <#{encoding.inspect}>, " +
114
+ "size: <0>>",
115
+ named_table.inspect)
116
+ end
117
+
118
+ def test_encoding
119
+ assert_equal(Groonga::Encoding.default,
120
+ Groonga::Hash.create.encoding)
121
+ end
122
+
123
+ def test_tokenizer
124
+ hash = Groonga::Hash.create
125
+ assert_nil(hash.default_tokenizer)
126
+ hash.default_tokenizer = "<token:bigram>"
127
+ assert_equal(Groonga::Context.default["<token:bigram>"],
128
+ hash.default_tokenizer)
129
+ end
130
+
131
+ def test_search
132
+ users = Groonga::Array.create(:name => "<users>")
133
+ user_name = users.define_column("name", "<shorttext>")
134
+
135
+ bookmarks = Groonga::Hash.create(:name => "<bookmarks>",
136
+ :key_type => "<shorttext>")
137
+ bookmark_user_id = bookmarks.define_column("user_id", users)
138
+
139
+ daijiro = users.add
140
+ daijiro["name"] = "daijiro"
141
+ gunyarakun = users.add
142
+ gunyarakun["name"] = "gunyarakun"
143
+
144
+ groonga = bookmarks.add("http://groonga.org/")
145
+ groonga["user_id"] = daijiro
146
+
147
+ records = bookmarks.search("http://groonga.org/")
148
+ assert_equal(["daijiro"],
149
+ records.records.collect {|record| record[".user_id.name"]})
150
+ end
151
+
152
+ def test_add
153
+ users = Groonga::Hash.create(:name => "<users>")
154
+ users.define_column("address", "<text>")
155
+ me = users.add("me", :address => "me@example.com")
156
+ assert_equal("me@example.com", me[:address])
157
+ end
158
+
159
+ def test_default_tokenizer_on_create
160
+ terms = Groonga::Hash.create(:name => "<terms>",
161
+ :default_tokenizer => "<token:trigram>")
162
+ assert_equal(context[Groonga::Type::TRIGRAM],
163
+ terms.default_tokenizer)
164
+ end
165
+
166
+ def test_duplicated_name
167
+ Groonga::Hash.create(:name => "<users>")
168
+ assert_raise(Groonga::InvalidArgument) do
169
+ Groonga::Hash.create(:name => "<users>")
170
+ end
171
+ end
172
+
173
+ def test_define_index_column_implicit_with_position
174
+ bookmarks = Groonga::Hash.create(:name => "<bookmarks>")
175
+ bookmarks.define_column("comment", "<text>")
176
+ terms = Groonga::Hash.create(:name => "<terms>",
177
+ :default_tokenizer => "<token:bigram>")
178
+ index = terms.define_index_column("comment", bookmarks,
179
+ :source => "<bookmarks>.comment")
180
+ groonga = bookmarks.add("groonga", :comment => "search engine by Brazil")
181
+ google = bookmarks.add("google", :comment => "search engine by Google")
182
+ ruby = bookmarks.add("ruby", :comment => "programing language")
183
+
184
+ assert_equal(["groonga", "google"],
185
+ index.search("engine").collect {|record| record.key.key})
186
+ end
187
+
188
+ def test_open_same_name
189
+ users_created = Groonga::Hash.create(:name => "<users>")
190
+ users_opened = Groonga::Hash.open(:name => "<users>")
191
+ users_opened.add("morita")
192
+ assert_equal(1, users_created.size)
193
+ end
194
+ end
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ class IndexColumnTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+
21
+ def setup
22
+ setup_database
23
+ end
24
+
25
+ def test_array_set_with_record
26
+ articles = Groonga::Array.create(:name => "<articles>")
27
+ articles.define_column("content", "<text>")
28
+
29
+ terms = Groonga::Hash.create(:name => "<terms>",
30
+ :default_tokenizer => "<token:bigram>")
31
+ content_index = terms.define_index_column("content", articles,
32
+ :with_section => true)
33
+
34
+ content = <<-EOC
35
+ groonga は組み込み型の全文検索エンジンライブラリです。
36
+ DBMSやスクリプト言語処理系等に組み込むことによって、その
37
+ 全文検索機能を強化することができます。また、リレーショナ
38
+ ルモデルに基づくデータストア機能を内包しており、groonga
39
+ 単体でも高速なデータストアサーバとして使用することができ
40
+ ます。
41
+
42
+ ■全文検索方式
43
+ 転置索引型の全文検索エンジンです。転置索引は圧縮されてファ
44
+ イルに格納され、検索時のディスク読み出し量を小さく、かつ
45
+ 局所的に抑えるように設計されています。用途に応じて以下の
46
+ 索引タイプを選択できます。
47
+ EOC
48
+
49
+ groonga = articles.add(:content => content)
50
+
51
+ content.split(/\n{2,}/).each_with_index do |sentence, i|
52
+ content_index[groonga] = {:value => sentence, :section => i + 1}
53
+ end
54
+ assert_equal([groonga],
55
+ content_index.search("エンジン").collect {|record| record.key})
56
+ end
57
+ end
@@ -0,0 +1,82 @@
1
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ class PatriciaTrieTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_encoding
22
+ assert_equal(Groonga::Encoding.default,
23
+ Groonga::PatriciaTrie.create.encoding)
24
+ end
25
+
26
+ def test_tokenizer
27
+ trie = Groonga::PatriciaTrie.create
28
+ assert_nil(trie.default_tokenizer)
29
+ trie.default_tokenizer = "<token:trigram>"
30
+ assert_equal(Groonga::Context.default["<token:trigram>"],
31
+ trie.default_tokenizer)
32
+ end
33
+
34
+ def test_search
35
+ users = Groonga::Array.create(:name => "<users>")
36
+ user_name = users.define_column("name", "<shorttext>")
37
+
38
+ bookmarks = Groonga::PatriciaTrie.create(:name => "<bookmarks>",
39
+ :key_type => "<shorttext>")
40
+ bookmark_user_id = bookmarks.define_column("user_id", users)
41
+
42
+ daijiro = users.add
43
+ daijiro["name"] = "daijiro"
44
+ gunyarakun = users.add
45
+ gunyarakun["name"] = "gunyarakun"
46
+
47
+ groonga = bookmarks.add("http://groonga.org/")
48
+ groonga["user_id"] = daijiro
49
+
50
+ records = bookmarks.search("http://groonga.org/")
51
+ assert_equal(["daijiro"],
52
+ records.records.collect {|record| record[".user_id.name"]})
53
+ end
54
+
55
+ def test_add
56
+ users = Groonga::PatriciaTrie.create(:name => "<users>")
57
+ users.define_column("address", "<text>")
58
+ me = users.add("me", :address => "me@example.com")
59
+ assert_equal("me@example.com", me[:address])
60
+ end
61
+
62
+ def test_default_tokenizer_on_create
63
+ terms = Groonga::PatriciaTrie.create(:name => "<terms>",
64
+ :default_tokenizer => "<token:unigram>")
65
+ assert_equal(context[Groonga::Type::UNIGRAM],
66
+ terms.default_tokenizer)
67
+ end
68
+
69
+ def test_duplicated_name
70
+ Groonga::PatriciaTrie.create(:name => "<users>")
71
+ assert_raise(Groonga::InvalidArgument) do
72
+ Groonga::PatriciaTrie.create(:name => "<users>")
73
+ end
74
+ end
75
+
76
+ def test_open_same_name
77
+ users_created = Groonga::PatriciaTrie.create(:name => "<users>")
78
+ users_opened = Groonga::PatriciaTrie.open(:name => "<users>")
79
+ users_opened.add("morita")
80
+ assert_equal(1, users_created.size)
81
+ end
82
+ end
data/test/test-record.rb CHANGED
@@ -80,22 +80,22 @@ class RecordTest < Test::Unit::TestCase
80
80
  @bookmarks_index =
81
81
  Groonga::PatriciaTrie.create(:name => "bookmarks-index",
82
82
  :path => @bookmarks_index_path.to_s)
83
+ @bookmarks_index.default_tokenizer = "<token:bigram>"
84
+
83
85
  @content_index_column_path = @columns_dir + "content-index"
84
86
  @bookmarks_content_index =
85
- @bookmarks_index.define_column("<index:content>", @bookmarks,
86
- :type => "index",
87
- :with_section => true,
88
- :with_weight => true,
89
- :with_position => true,
90
- :path => @content_index_column_path.to_s)
87
+ @bookmarks_index.define_index_column("<index:content>", @bookmarks,
88
+ :with_section => true,
89
+ :with_weight => true,
90
+ :with_position => true,
91
+ :path => @content_index_column_path.to_s)
91
92
  @bookmarks_content_index.source = @bookmarks_content
92
93
 
93
94
  @uri_index_column_path = @columns_dir + "uri-index"
94
95
  @bookmarks_uri_index =
95
- @bookmarks_index.define_column("<index:uri>", @bookmarks,
96
- :type => "index",
97
- :with_position => true,
98
- :path => @uri_index_column_path.to_s)
96
+ @bookmarks_index.define_index_column("<index:uri>", @bookmarks,
97
+ :with_position => true,
98
+ :path => @uri_index_column_path.to_s)
99
99
  @bookmarks_uri_index.source = @bookmarks_uri
100
100
  end
101
101