groonga 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/NEWS.ja.rdoc +18 -3
  2. data/NEWS.rdoc +18 -3
  3. data/README.ja.rdoc +2 -0
  4. data/README.rdoc +2 -0
  5. data/Rakefile +14 -5
  6. data/TUTORIAL.ja.rdoc +82 -16
  7. data/benchmark/{read-write-small-many-items.rb → read-write-many-small-items.rb} +26 -23
  8. data/benchmark/{write-small-many-items.rb → write-many-small-items.rb} +26 -23
  9. data/example/bookmark.rb +49 -5
  10. data/ext/rb-grn-array.c +11 -1
  11. data/ext/rb-grn-column.c +132 -5
  12. data/ext/rb-grn-context.c +85 -80
  13. data/ext/rb-grn-database.c +182 -9
  14. data/ext/rb-grn-expression-builder.c +69 -0
  15. data/ext/rb-grn-expression.c +314 -0
  16. data/ext/rb-grn-fix-size-column.c +68 -89
  17. data/ext/rb-grn-hash.c +14 -5
  18. data/ext/rb-grn-index-column.c +14 -55
  19. data/ext/rb-grn-object.c +206 -75
  20. data/ext/rb-grn-operation.c +92 -0
  21. data/ext/rb-grn-patricia-trie.c +10 -32
  22. data/ext/rb-grn-query.c +9 -9
  23. data/ext/rb-grn-table-cursor.c +19 -80
  24. data/ext/rb-grn-table-key-support.c +33 -39
  25. data/ext/rb-grn-table.c +436 -79
  26. data/ext/rb-grn-type.c +10 -3
  27. data/ext/rb-grn-utils.c +131 -4
  28. data/ext/rb-grn-variable-size-column.c +36 -0
  29. data/ext/rb-grn-variable.c +90 -0
  30. data/ext/rb-grn.h +109 -56
  31. data/ext/rb-groonga.c +4 -0
  32. data/extconf.rb +39 -13
  33. data/html/index.html +2 -2
  34. data/lib/groonga.rb +22 -0
  35. data/lib/groonga/expression-builder.rb +141 -0
  36. data/lib/groonga/record.rb +25 -1
  37. data/lib/groonga/schema.rb +418 -0
  38. data/test/test-column.rb +11 -23
  39. data/test/test-context.rb +1 -1
  40. data/test/test-database.rb +60 -19
  41. data/test/test-expression-builder.rb +114 -0
  42. data/test/test-expression.rb +55 -0
  43. data/test/test-fix-size-column.rb +53 -0
  44. data/test/test-hash.rb +10 -3
  45. data/test/test-index-column.rb +24 -0
  46. data/test/test-patricia-trie.rb +9 -0
  47. data/test/test-procedure.rb +5 -5
  48. data/test/test-record.rb +71 -4
  49. data/test/test-schema.rb +207 -0
  50. data/test/test-table.rb +94 -12
  51. data/test/test-type.rb +18 -11
  52. data/test/test-variable-size-column.rb +53 -0
  53. data/test/test-variable.rb +28 -0
  54. metadata +18 -5
data/test/test-column.rb CHANGED
@@ -61,12 +61,12 @@ class ColumnTest < Test::Unit::TestCase
61
61
  @bookmarks_index =
62
62
  Groonga::PatriciaTrie.create(:name => "bookmarks-index",
63
63
  :path => @bookmarks_index_path.to_s,
64
- :key_type => "<shorttext>")
65
- @bookmarks_index.default_tokenizer = "<token:bigram>"
64
+ :key_type => "ShortText")
65
+ @bookmarks_index.default_tokenizer = "TokenBigram"
66
66
 
67
67
  @content_index_column_path = @columns_dir + "content-index"
68
68
  @bookmarks_index_content =
69
- @bookmarks_index.define_index_column("<index:content>", @bookmarks,
69
+ @bookmarks_index.define_index_column("content", @bookmarks,
70
70
  :with_section => true,
71
71
  :with_weight => true,
72
72
  :with_position => true,
@@ -74,7 +74,7 @@ class ColumnTest < Test::Unit::TestCase
74
74
 
75
75
  @uri_index_column_path = @columns_dir + "uri-index"
76
76
  @bookmarks_index_uri =
77
- @bookmarks_index.define_index_column("<index:uri>", @bookmarks,
77
+ @bookmarks_index.define_index_column("uri", @bookmarks,
78
78
  :path => @uri_index_column_path.to_s)
79
79
  end
80
80
 
@@ -157,25 +157,6 @@ class ColumnTest < Test::Unit::TestCase
157
157
  assert_equal(daijiro, @bookmarks_user[bookmark.id])
158
158
  end
159
159
 
160
- def test_inspect
161
- assert_equal("#<Groonga::VarSizeColumn " +
162
- "id: <#{@users_name_column.id}>, " +
163
- "name: <users.name>, " +
164
- "path: <#{@users_name_column_path}>, " +
165
- "domain: <#{@users.inspect}>, " +
166
- "range: <#{context['<shorttext>'].inspect}>" +
167
- ">",
168
- @users_name_column.inspect)
169
- end
170
-
171
- def test_domain
172
- assert_equal(@users, @users_name_column.domain)
173
- end
174
-
175
- def test_table
176
- assert_equal(@users, @users_name_column.table)
177
- end
178
-
179
160
  def test_array_set_with_key_of_table
180
161
  users = Groonga::Hash.create(:name => "<users>")
181
162
  bookmarks = Groonga::Hash.create(:name => "<bookmarks>")
@@ -186,6 +167,13 @@ class ColumnTest < Test::Unit::TestCase
186
167
  assert_equal("morita", groonga[:user].key)
187
168
  end
188
169
 
170
+ def test_local_name
171
+ items = Groonga::Array.create(:name => "<items>")
172
+ title = items.define_column("title", "<shorttext>")
173
+ assert_equal("<items>.title", title.name)
174
+ assert_equal("title", title.local_name)
175
+ end
176
+
189
177
  private
190
178
  def assert_content_search(expected_records, term)
191
179
  records = @bookmarks_index_content.search(term).records
data/test/test-context.rb CHANGED
@@ -57,6 +57,6 @@ class ContextTest < Test::Unit::TestCase
57
57
  def test_array_reference
58
58
  Groonga::Database.create
59
59
  context = Groonga::Context.default
60
- assert_equal("<int>", context["<int>"].name)
60
+ assert_equal("Int32", context["<int>"].name)
61
61
  end
62
62
  end
@@ -63,25 +63,27 @@ class DatabaseTest < Test::Unit::TestCase
63
63
  def test_each
64
64
  db_path = @tmp_dir + "db"
65
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>"],
66
+ assert_equal(["/q/define_selector",
67
+ "Bool",
68
+ "Float",
69
+ "Int16",
70
+ "Int32",
71
+ "Int64",
72
+ "Int8",
73
+ "LongText",
74
+ "Object",
75
+ "ShortText",
76
+ "Text",
77
+ "Time",
78
+ "TokenBigram",
79
+ "TokenDelimit",
80
+ "TokenMecab",
81
+ "TokenTrigram",
82
+ "TokenUnigram",
83
+ "UInt16",
84
+ "UInt32",
85
+ "UInt64",
86
+ "UInt8"],
85
87
  database.collect {|object| object.name}.sort)
86
88
  end
87
89
 
@@ -89,4 +91,43 @@ class DatabaseTest < Test::Unit::TestCase
89
91
  assert_equal(Groonga::Encoding.default,
90
92
  Groonga::Database.create.encoding)
91
93
  end
94
+
95
+ def test_lock
96
+ database = Groonga::Database.create
97
+
98
+ assert_not_predicate(database, :locked?)
99
+ database.lock
100
+ assert_predicate(database, :locked?)
101
+ database.unlock
102
+ assert_not_predicate(database, :locked?)
103
+ end
104
+
105
+ def test_lock_failed
106
+ database = Groonga::Database.create
107
+
108
+ database.lock
109
+ assert_raise(Groonga::ResourceDeadlockAvoided) do
110
+ database.lock
111
+ end
112
+ end
113
+
114
+ def test_lock_block
115
+ database = Groonga::Database.create
116
+
117
+ assert_not_predicate(database, :locked?)
118
+ database.lock do
119
+ assert_predicate(database, :locked?)
120
+ end
121
+ assert_not_predicate(database, :locked?)
122
+ end
123
+
124
+ def test_clear_lock
125
+ database = Groonga::Database.create
126
+
127
+ assert_not_predicate(database, :locked?)
128
+ database.lock
129
+ assert_predicate(database, :locked?)
130
+ database.clear_lock
131
+ assert_not_predicate(database, :locked?)
132
+ end
92
133
  end
@@ -0,0 +1,114 @@
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 ExpressionBuilderTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+ setup :setup_tables
21
+ setup :setup_data
22
+
23
+ def setup_tables
24
+ @users = Groonga::Hash.create(:name => "<users>")
25
+ @name = @users.define_column("name", "<shorttext>")
26
+ @hp = @users.define_column("hp", "<uint>")
27
+
28
+ @terms = Groonga::PatriciaTrie.create(:name => "<terms>",
29
+ :default_tokenizer => "TokenBigram")
30
+ @terms.define_index_column("user-name", @users, :source => @name)
31
+ end
32
+
33
+ def setup_data
34
+ @morita = @users.add("morita",
35
+ :name => "mori daijiro",
36
+ :hp => 100)
37
+ @gunyara_kun = @users.add("gunyara-kun",
38
+ :name => "Tasuku SUENAGA",
39
+ :hp => 150)
40
+ @yu = @users.add("yu",
41
+ :name => "Yutaro Shimamura",
42
+ :hp => 200)
43
+ end
44
+
45
+ def test_equal
46
+ result = @users.select do |record|
47
+ record["name"] == "mori daijiro"
48
+ end
49
+ assert_equal(["morita"],
50
+ result.collect {|record| record.key.key})
51
+ end
52
+
53
+ def test_not_equal
54
+ omit("not supported yet!!!")
55
+ result = @users.select do |record|
56
+ record["name"] != "mori daijiro"
57
+ end
58
+ assert_equal(["gunyara-kun", "yu"],
59
+ result.collect {|record| record.key.key})
60
+ end
61
+
62
+ def test_less
63
+ result = @users.select do |record|
64
+ record["hp"] < 150
65
+ end
66
+ assert_equal(["morita"], result.collect {|record| record.key.key})
67
+ end
68
+
69
+ def test_less_equal
70
+ result = @users.select do |record|
71
+ record["hp"] <= 150
72
+ end
73
+ assert_equal(["morita", "gunyara-kun"],
74
+ result.collect {|record| record.key.key})
75
+ end
76
+
77
+ def test_greater
78
+ result = @users.select do |record|
79
+ record["hp"] > 150
80
+ end
81
+ assert_equal(["yu"], result.collect {|record| record.key.key})
82
+ end
83
+
84
+ def test_greater_equal
85
+ result = @users.select do |record|
86
+ record["hp"] >= 150
87
+ end
88
+ assert_equal(["gunyara-kun", "yu"],
89
+ result.collect {|record| record.key.key})
90
+ end
91
+
92
+ def test_and
93
+ result = @users.select do |record|
94
+ (record["hp"] > 100) & (record["hp"] <= 200)
95
+ end
96
+ assert_equal(["gunyara-kun", "yu"],
97
+ result.collect {|record| record.key.key})
98
+ end
99
+
100
+ def test_match
101
+ result = @users.select do |record|
102
+ record["name"] =~ "ro"
103
+ end
104
+ assert_equal(["morita", "yu"],
105
+ result.collect {|record| record.key.key})
106
+ end
107
+
108
+ def test_query_string
109
+ omit("not supported yet!!!")
110
+ result = @name.select("ro")
111
+ assert_equal(["morita", "yu"],
112
+ result.collect {|record| record.key.key})
113
+ end
114
+ end
@@ -0,0 +1,55 @@
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 ExpressionTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_get_value
22
+ users = Groonga::Hash.create(:name => "<users>")
23
+ name = users.define_column("name", "<shorttext>")
24
+
25
+ morita = users.add("morita", :name => "mori daijiro")
26
+
27
+ expression = Groonga::Expression.new
28
+ expression.append_constant(morita)
29
+ expression.append_constant("name")
30
+ expression.append_operation(Groonga::Operation::OBJECT_GET_VALUE, 2)
31
+ expression.compile
32
+ assert_equal("mori daijiro", expression.execute)
33
+ end
34
+
35
+ def test_get_value_with_variable
36
+ users = Groonga::Hash.create(:name => "<users>")
37
+ name = users.define_column("name", "<shorttext>")
38
+
39
+ morita = users.add("morita", :name => "mori daijiro")
40
+ gunyara_kun = users.add("gunyara-kun", :name => "Tasuku SUENAGA")
41
+
42
+ expression = Groonga::Expression.new
43
+ variable = expression.define_variable
44
+ variable.value = morita
45
+ expression.append_object(variable)
46
+ expression.append_constant("name")
47
+ expression.append_operation(Groonga::Operation::OBJECT_GET_VALUE, 2)
48
+ expression.compile
49
+
50
+ assert_equal("mori daijiro", expression.execute)
51
+
52
+ variable.value = gunyara_kun.id
53
+ assert_equal("Tasuku SUENAGA", expression.execute)
54
+ end
55
+ end
@@ -0,0 +1,53 @@
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 FixSizeColumnTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ setup_database
21
+
22
+ setup_bookmarks_table
23
+ end
24
+
25
+ def setup_bookmarks_table
26
+ @bookmarks_path = @tables_dir + "bookmarks"
27
+ @bookmarks = Groonga::Array.create(:name => "bookmarks",
28
+ :path => @bookmarks_path.to_s)
29
+
30
+ @viewed_column_path = @columns_dir + "viewed"
31
+ @viewed = @bookmarks.define_column("viewed", "<int>",
32
+ :path => @viewed_column_path.to_s)
33
+ end
34
+
35
+ def test_inspect
36
+ assert_equal("#<Groonga::FixSizeColumn " +
37
+ "id: <#{@viewed.id}>, " +
38
+ "name: <bookmarks.viewed>, " +
39
+ "path: <#{@viewed_column_path}>, " +
40
+ "domain: <#{@bookmarks.inspect}>, " +
41
+ "range: <#{context['<int>'].inspect}>" +
42
+ ">",
43
+ @viewed.inspect)
44
+ end
45
+
46
+ def test_domain
47
+ assert_equal(@bookmarks, @viewed.domain)
48
+ end
49
+
50
+ def test_table
51
+ assert_equal(@bookmarks, @viewed.table)
52
+ end
53
+ end
data/test/test-hash.rb CHANGED
@@ -102,11 +102,11 @@ class HashTest < Test::Unit::TestCase
102
102
  named_table.inspect)
103
103
  end
104
104
 
105
- def test_inspect_named_temporary
106
- named_table = Groonga::Hash.create(:name => "name")
105
+ def test_inspect_temporary
106
+ named_table = Groonga::Hash.create
107
107
  assert_equal("#<Groonga::Hash " +
108
108
  "id: <#{named_table.id}>, " +
109
- "name: <name>, " +
109
+ "name: (anonymous), " +
110
110
  "path: (temporary), " +
111
111
  "domain: <nil>, " +
112
112
  "range: <nil>, " +
@@ -191,4 +191,11 @@ class HashTest < Test::Unit::TestCase
191
191
  users_opened.add("morita")
192
192
  assert_equal(1, users_created.size)
193
193
  end
194
+
195
+ def test_has_key?
196
+ users = Groonga::Hash.create(:name => "<users>")
197
+ assert_false(users.has_key?("morita"))
198
+ users.add("morita")
199
+ assert_true(users.has_key?("morita"))
200
+ end
194
201
  end
@@ -54,4 +54,28 @@ class IndexColumnTest < Test::Unit::TestCase
54
54
  assert_equal([groonga],
55
55
  content_index.search("エンジン").collect {|record| record.key})
56
56
  end
57
+
58
+ def test_shorter_query_than_ngram
59
+ articles = Groonga::Array.create(:name => "<articles>")
60
+ articles.define_column("content", "<text>")
61
+
62
+ terms = Groonga::PatriciaTrie.create(:name => "<terms>",
63
+ :default_tokenizer => "<token:bigram>")
64
+ content_index = terms.define_index_column("content", articles,
65
+ :source => "<articles>.content")
66
+ articles.add(:content => 'l')
67
+ articles.add(:content => 'll')
68
+ articles.add(:content => 'hello')
69
+
70
+ assert_search(["hello"], content_index, "he")
71
+ assert_search(["ll", "hello"], content_index, "ll")
72
+ assert_search(["l", "ll", "hello"], content_index, "l")
73
+ end
74
+
75
+ def assert_search(expected, content_index, keyword)
76
+ result = content_index.search(keyword).collect do |entry|
77
+ entry.key["content"]
78
+ end
79
+ assert_equal(expected, result)
80
+ end
57
81
  end
@@ -32,6 +32,8 @@ class PatriciaTrieTest < Test::Unit::TestCase
32
32
  end
33
33
 
34
34
  def test_search
35
+ omit("creating entry is broken.")
36
+
35
37
  users = Groonga::Array.create(:name => "<users>")
36
38
  user_name = users.define_column("name", "<shorttext>")
37
39
 
@@ -79,4 +81,11 @@ class PatriciaTrieTest < Test::Unit::TestCase
79
81
  users_opened.add("morita")
80
82
  assert_equal(1, users_created.size)
81
83
  end
84
+
85
+ def test_has_key?
86
+ users = Groonga::PatriciaTrie.create(:name => "<users>")
87
+ assert_false(users.has_key?("morita"))
88
+ users.add("morita")
89
+ assert_true(users.has_key?("morita"))
90
+ end
82
91
  end