groonga 0.0.7 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/NEWS.ja.rdoc +56 -0
- data/NEWS.rdoc +58 -0
- data/Rakefile +2 -3
- data/benchmark/read-write-many-small-items.rb +16 -32
- data/benchmark/write-many-small-items.rb +14 -28
- data/example/bookmark.rb +19 -17
- data/example/index-html.rb +11 -1
- data/example/search/config.ru +14 -9
- data/ext/rb-grn-array.c +6 -6
- data/ext/rb-grn-column.c +348 -18
- data/ext/rb-grn-context.c +8 -4
- data/ext/rb-grn-database.c +6 -7
- data/ext/rb-grn-exception.c +101 -5
- data/ext/rb-grn-expression.c +206 -23
- data/ext/rb-grn-fix-size-column.c +6 -39
- data/ext/rb-grn-hash.c +24 -24
- data/ext/rb-grn-index-column.c +74 -19
- data/ext/rb-grn-logger.c +48 -0
- data/ext/rb-grn-object.c +281 -67
- data/ext/rb-grn-operation.c +1 -1
- data/ext/rb-grn-patricia-trie-cursor.c +10 -1
- data/ext/rb-grn-patricia-trie.c +268 -7
- data/ext/rb-grn-query.c +52 -1
- data/ext/rb-grn-record.c +8 -2
- data/ext/rb-grn-snippet.c +63 -1
- data/ext/rb-grn-table-cursor-key-support.c +15 -1
- data/ext/rb-grn-table-cursor.c +57 -0
- data/ext/rb-grn-table-key-support.c +382 -46
- data/ext/rb-grn-table.c +729 -192
- data/ext/rb-grn-type.c +63 -12
- data/ext/rb-grn-utils.c +156 -158
- data/ext/rb-grn-variable.c +18 -0
- data/ext/rb-grn.h +85 -21
- data/ext/rb-groonga.c +13 -3
- data/extconf.rb +19 -4
- data/html/developer.html +1 -1
- data/html/header.html.erb +1 -1
- data/html/index.html +4 -4
- data/lib/groonga.rb +10 -0
- data/lib/groonga/expression-builder.rb +81 -42
- data/lib/groonga/patricia-trie.rb +13 -0
- data/lib/groonga/record.rb +158 -13
- data/lib/groonga/schema.rb +339 -33
- data/pkg-config.rb +6 -1
- data/test-unit/lib/test/unit.rb +23 -42
- data/test-unit/lib/test/unit/assertionfailederror.rb +11 -0
- data/test-unit/lib/test/unit/assertions.rb +87 -9
- data/test-unit/lib/test/unit/autorunner.rb +20 -11
- data/test-unit/lib/test/unit/collector.rb +1 -8
- data/test-unit/lib/test/unit/collector/load.rb +2 -3
- data/test-unit/lib/test/unit/color-scheme.rb +13 -1
- data/test-unit/lib/test/unit/diff.rb +223 -37
- data/test-unit/lib/test/unit/error.rb +4 -0
- data/test-unit/lib/test/unit/failure.rb +31 -5
- data/test-unit/lib/test/unit/notification.rb +8 -4
- data/test-unit/lib/test/unit/omission.rb +51 -3
- data/test-unit/lib/test/unit/pending.rb +4 -0
- data/test-unit/lib/test/unit/testcase.rb +55 -4
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +190 -4
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +14 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +8 -0
- data/test-unit/lib/test/unit/version.rb +1 -1
- data/test-unit/sample/{tc_adder.rb → test_adder.rb} +3 -1
- data/test-unit/sample/{tc_subtracter.rb → test_subtracter.rb} +3 -1
- data/test-unit/sample/test_user.rb +1 -0
- data/test-unit/test/collector/test-descendant.rb +2 -4
- data/test-unit/test/collector/test_objectspace.rb +7 -5
- data/test-unit/test/run-test.rb +2 -0
- data/test-unit/test/test-color-scheme.rb +7 -0
- data/test-unit/test/test-diff.rb +48 -7
- data/test-unit/test/test-omission.rb +1 -1
- data/test-unit/test/test-testcase.rb +47 -0
- data/test-unit/test/test_assertions.rb +79 -10
- data/test/groonga-test-utils.rb +6 -1
- data/test/test-array.rb +29 -14
- data/test/test-column.rb +107 -55
- data/test/test-context.rb +5 -0
- data/test/test-database.rb +2 -37
- data/test/test-exception.rb +9 -1
- data/test/test-expression-builder.rb +23 -5
- data/test/test-expression.rb +44 -8
- data/test/test-fix-size-column.rb +16 -5
- data/test/test-gqtp.rb +70 -0
- data/test/test-hash.rb +142 -43
- data/test/test-index-column.rb +9 -9
- data/test/test-patricia-trie.rb +79 -20
- data/test/test-procedure.rb +4 -2
- data/test/test-record.rb +32 -20
- data/test/test-remote.rb +3 -2
- data/test/test-schema.rb +226 -92
- data/test/test-table-cursor.rb +103 -1
- data/test/test-table-offset-and-limit.rb +102 -0
- data/test/test-table-select-normalize.rb +4 -4
- data/test/test-table-select.rb +52 -8
- data/test/test-table.rb +235 -116
- data/test/test-type.rb +2 -2
- data/test/test-variable-size-column.rb +21 -5
- data/test/test-vector-column.rb +76 -0
- data/{TUTORIAL.ja.rdoc → text/TUTORIAL.ja.rdoc} +52 -52
- data/text/expression.rdoc +284 -0
- metadata +11 -7
- data/test-unit/sample/ts_examples.rb +0 -7
data/test/test-expression.rb
CHANGED
|
@@ -19,9 +19,24 @@ class ExpressionTest < Test::Unit::TestCase
|
|
|
19
19
|
|
|
20
20
|
setup :setup_database
|
|
21
21
|
|
|
22
|
+
def test_array_reference
|
|
23
|
+
expression = Groonga::Expression.new
|
|
24
|
+
ryoqun = expression.define_variable({:name => "user"})
|
|
25
|
+
ryoqun.value = "ryoqun"
|
|
26
|
+
mori = expression.define_variable
|
|
27
|
+
mori.value = "mori"
|
|
28
|
+
|
|
29
|
+
expression.append_object(ryoqun)
|
|
30
|
+
expression.append_object(mori)
|
|
31
|
+
|
|
32
|
+
assert_equal("ryoqun", expression["user"])
|
|
33
|
+
assert_equal("ryoqun", expression[0])
|
|
34
|
+
assert_equal("mori", expression[1])
|
|
35
|
+
end
|
|
36
|
+
|
|
22
37
|
def test_get_value
|
|
23
|
-
users = Groonga::Hash.create(:name => "
|
|
24
|
-
name = users.define_column("name", "
|
|
38
|
+
users = Groonga::Hash.create(:name => "Users")
|
|
39
|
+
name = users.define_column("name", "ShortText")
|
|
25
40
|
|
|
26
41
|
morita = users.add("morita", :name => "mori daijiro")
|
|
27
42
|
|
|
@@ -35,8 +50,8 @@ class ExpressionTest < Test::Unit::TestCase
|
|
|
35
50
|
end
|
|
36
51
|
|
|
37
52
|
def test_get_value_with_variable
|
|
38
|
-
users = Groonga::Hash.create(:name => "
|
|
39
|
-
name = users.define_column("name", "
|
|
53
|
+
users = Groonga::Hash.create(:name => "Users")
|
|
54
|
+
name = users.define_column("name", "ShortText")
|
|
40
55
|
|
|
41
56
|
morita = users.add("morita", :name => "mori daijiro")
|
|
42
57
|
gunyara_kun = users.add("gunyara-kun", :name => "Tasuku SUENAGA")
|
|
@@ -63,17 +78,17 @@ class ExpressionTest < Test::Unit::TestCase
|
|
|
63
78
|
expression.append_operation(Groonga::Operation::PLUS, 2)
|
|
64
79
|
expression.compile
|
|
65
80
|
|
|
66
|
-
assert_equal("#<Groonga::Expression noname(){1 1}>", expression.inspect)
|
|
81
|
+
assert_equal("#<Groonga::Expression noname(){1 1 PLUS}>", expression.inspect)
|
|
67
82
|
end
|
|
68
83
|
|
|
69
84
|
def test_snippet
|
|
70
|
-
users = Groonga::Array.create(:name => "
|
|
85
|
+
users = Groonga::Array.create(:name => "Users")
|
|
71
86
|
name = users.define_column("name", "ShortText")
|
|
72
|
-
terms = Groonga::Hash.create(:name => "
|
|
87
|
+
terms = Groonga::Hash.create(:name => "Terms",
|
|
73
88
|
:key_type => "ShortText",
|
|
74
89
|
:default_tokenizer => "TokenBigram")
|
|
75
90
|
users.define_index_column("user_name", users,
|
|
76
|
-
:source => "
|
|
91
|
+
:source => "Users.name",
|
|
77
92
|
:with_position => true)
|
|
78
93
|
|
|
79
94
|
expression = Groonga::Expression.new
|
|
@@ -94,4 +109,25 @@ class ExpressionTest < Test::Unit::TestCase
|
|
|
94
109
|
"Rubyらしい読み書きしやすい構文で利用できる" +
|
|
95
110
|
"ことが利点です。"))
|
|
96
111
|
end
|
|
112
|
+
|
|
113
|
+
def test_snippet_without_tags
|
|
114
|
+
users = Groonga::Array.create(:name => "Users")
|
|
115
|
+
name = users.define_column("name", "ShortText")
|
|
116
|
+
terms = Groonga::Hash.create(:name => "Terms",
|
|
117
|
+
:key_type => "ShortText",
|
|
118
|
+
:default_tokenizer => "TokenBigram")
|
|
119
|
+
users.define_index_column("user_name", users,
|
|
120
|
+
:source => "Users.name",
|
|
121
|
+
:with_position => true)
|
|
122
|
+
|
|
123
|
+
expression = Groonga::Expression.new
|
|
124
|
+
variable = expression.define_variable(:domain => users)
|
|
125
|
+
expression.append_object(variable)
|
|
126
|
+
expression.parse("ラングバ", :default_column => name)
|
|
127
|
+
expression.compile
|
|
128
|
+
|
|
129
|
+
snippet = expression.snippet([], :width => 30)
|
|
130
|
+
assert_equal(["ラングバプロジェクト"],
|
|
131
|
+
snippet.execute("ラングバプロジェクトはカラムストア機能も"))
|
|
132
|
+
end
|
|
97
133
|
end
|
|
@@ -24,21 +24,21 @@ class FixSizeColumnTest < Test::Unit::TestCase
|
|
|
24
24
|
|
|
25
25
|
def setup_bookmarks_table
|
|
26
26
|
@bookmarks_path = @tables_dir + "bookmarks"
|
|
27
|
-
@bookmarks = Groonga::Array.create(:name => "
|
|
27
|
+
@bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
|
28
28
|
:path => @bookmarks_path.to_s)
|
|
29
29
|
|
|
30
30
|
@viewed_column_path = @columns_dir + "viewed"
|
|
31
|
-
@viewed = @bookmarks.define_column("viewed", "
|
|
31
|
+
@viewed = @bookmarks.define_column("viewed", "Int32",
|
|
32
32
|
:path => @viewed_column_path.to_s)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def test_inspect
|
|
36
36
|
assert_equal("#<Groonga::FixSizeColumn " +
|
|
37
37
|
"id: <#{@viewed.id}>, " +
|
|
38
|
-
"name: <
|
|
38
|
+
"name: <Bookmarks.viewed>, " +
|
|
39
39
|
"path: <#{@viewed_column_path}>, " +
|
|
40
|
-
"domain:
|
|
41
|
-
"range:
|
|
40
|
+
"domain: <Bookmarks>, " +
|
|
41
|
+
"range: <Int32>, " +
|
|
42
42
|
"flags: <KEY_INT>" +
|
|
43
43
|
">",
|
|
44
44
|
@viewed.inspect)
|
|
@@ -51,4 +51,15 @@ class FixSizeColumnTest < Test::Unit::TestCase
|
|
|
51
51
|
def test_table
|
|
52
52
|
assert_equal(@bookmarks, @viewed.table)
|
|
53
53
|
end
|
|
54
|
+
|
|
55
|
+
def test_assign_time
|
|
56
|
+
comments = Groonga::Array.create(:name => "Comments")
|
|
57
|
+
comments.define_column("title", "ShortText")
|
|
58
|
+
comments.define_column("issued", "Time")
|
|
59
|
+
title = "Good"
|
|
60
|
+
issued = 1187430026
|
|
61
|
+
record = comments.add(:title => title, :issued => issued)
|
|
62
|
+
assert_equal([title, Time.at(issued)],
|
|
63
|
+
[record["title"], record["issued"]])
|
|
64
|
+
end
|
|
54
65
|
end
|
data/test/test-gqtp.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C) 2010 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 GQTPTest < Test::Unit::TestCase
|
|
19
|
+
include GroongaTestUtils
|
|
20
|
+
|
|
21
|
+
setup :setup_database
|
|
22
|
+
|
|
23
|
+
setup
|
|
24
|
+
def setup_comments
|
|
25
|
+
@users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
|
|
26
|
+
|
|
27
|
+
@comments = Groonga::Array.create(:name => "Comments")
|
|
28
|
+
@comments.define_column("content", "Text")
|
|
29
|
+
@comments.define_column("created_at", "Time")
|
|
30
|
+
@comments.define_column("user", "Users")
|
|
31
|
+
|
|
32
|
+
terms = Groonga::PatriciaTrie.create(:name => "Terms",
|
|
33
|
+
:default_tokenizer => "TokenBigram")
|
|
34
|
+
terms.define_index_column("comment_content", @comments,
|
|
35
|
+
:with_section => true,
|
|
36
|
+
:source => "content")
|
|
37
|
+
@comment1 = @comments.add(:content => "Hello Good-bye!",
|
|
38
|
+
:created_at => Time.parse("2009-08-09"),
|
|
39
|
+
:user => "morita")
|
|
40
|
+
@comment2 = @comments.add(:content => "Hello World",
|
|
41
|
+
:created_at => Time.parse("2009-07-09"),
|
|
42
|
+
:user => "")
|
|
43
|
+
@comment3 = @comments.add(:content => "test",
|
|
44
|
+
:created_at => Time.parse("2009-06-09"),
|
|
45
|
+
:user => "gunyara-kun")
|
|
46
|
+
@japanese_comment =
|
|
47
|
+
@comments.add(:content => "うちのボロTVはまだ現役です",
|
|
48
|
+
:created_at => Time.parse("2009-06-09"),
|
|
49
|
+
:user => "darashi")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_select_filter_by_existent_user
|
|
53
|
+
assert_equal([[0], [[1], ["user"], ["darashi"]]],
|
|
54
|
+
process("select Comments --output_columns user " +
|
|
55
|
+
"--filter 'user == \"darashi\"'"))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_select_filter_by_nonexistent_user
|
|
59
|
+
assert_equal([[0], [[0], ["user"]]],
|
|
60
|
+
process("select Comments --output_columns user " +
|
|
61
|
+
"--filter 'user == \"yu\"'"))
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
def process(gqtp)
|
|
66
|
+
context.send(gqtp)
|
|
67
|
+
id, result = context.receive
|
|
68
|
+
JSON.parse(result)
|
|
69
|
+
end
|
|
70
|
+
end
|
data/test/test-hash.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
# Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
|
|
2
|
+
# Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
|
|
3
3
|
#
|
|
4
4
|
# This library is free software; you can redistribute it and/or
|
|
5
5
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -21,7 +21,7 @@ class HashTest < Test::Unit::TestCase
|
|
|
21
21
|
|
|
22
22
|
def test_delete
|
|
23
23
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
24
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
24
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
|
25
25
|
:path => bookmarks_path.to_s)
|
|
26
26
|
|
|
27
27
|
groonga = bookmarks.add("groonga")
|
|
@@ -40,25 +40,33 @@ class HashTest < Test::Unit::TestCase
|
|
|
40
40
|
bookmarks.collect {|bookmark| bookmark.key})
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def
|
|
44
|
-
value = "groonga"
|
|
45
|
-
value_type = Groonga::Type.new("Text#{value.size}", :size => value.size)
|
|
43
|
+
def test_value
|
|
46
44
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
47
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
45
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
|
48
46
|
:path => bookmarks_path.to_s,
|
|
49
|
-
:key_type => "
|
|
50
|
-
:value_type =>
|
|
51
|
-
bookmarks
|
|
52
|
-
assert_equal(
|
|
47
|
+
:key_type => "ShortText",
|
|
48
|
+
:value_type => "UInt32")
|
|
49
|
+
bookmarks.set_value("http://google.com/", 29)
|
|
50
|
+
assert_equal(29, bookmarks.value("http://google.com/"))
|
|
53
51
|
end
|
|
54
52
|
|
|
55
|
-
def
|
|
53
|
+
def test_column_value
|
|
54
|
+
bookmarks_path = @tables_dir + "bookmarks"
|
|
55
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
|
56
|
+
:path => bookmarks_path.to_s,
|
|
57
|
+
:key_type => "ShortText")
|
|
58
|
+
uri = bookmarks.define_column("uri", "ShortText")
|
|
59
|
+
bookmarks.set_column_value("google", "uri", "http://google.com/")
|
|
60
|
+
assert_equal("http://google.com/", bookmarks.column_value("google", "uri"))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_array_reference
|
|
56
64
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
57
65
|
bookmarks = Groonga::Hash.create(:name => "bookmarks",
|
|
58
66
|
:path => bookmarks_path.to_s,
|
|
59
|
-
:key_type => "
|
|
67
|
+
:key_type => "ShortText")
|
|
60
68
|
bookmark = bookmarks.add("http://google.com/")
|
|
61
|
-
assert_equal(bookmark, bookmarks
|
|
69
|
+
assert_equal(bookmark, bookmarks["http://google.com/"])
|
|
62
70
|
end
|
|
63
71
|
|
|
64
72
|
|
|
@@ -69,8 +77,8 @@ class HashTest < Test::Unit::TestCase
|
|
|
69
77
|
"id: <#{anonymous_table.id}>, " +
|
|
70
78
|
"name: (anonymous), " +
|
|
71
79
|
"path: <#{path}>, " +
|
|
72
|
-
"domain:
|
|
73
|
-
"range:
|
|
80
|
+
"domain: (nil), " +
|
|
81
|
+
"range: (nil), " +
|
|
74
82
|
"flags: <>, " +
|
|
75
83
|
"encoding: <#{encoding.inspect}>, " +
|
|
76
84
|
"size: <0>>",
|
|
@@ -83,8 +91,8 @@ class HashTest < Test::Unit::TestCase
|
|
|
83
91
|
"id: <#{anonymous_table.id}>, " +
|
|
84
92
|
"name: (anonymous), " +
|
|
85
93
|
"path: (temporary), " +
|
|
86
|
-
"domain:
|
|
87
|
-
"range:
|
|
94
|
+
"domain: (nil), " +
|
|
95
|
+
"range: (nil), " +
|
|
88
96
|
"flags: <>, " +
|
|
89
97
|
"encoding: <#{encoding.inspect}>, " +
|
|
90
98
|
"size: <0>>",
|
|
@@ -93,13 +101,13 @@ class HashTest < Test::Unit::TestCase
|
|
|
93
101
|
|
|
94
102
|
def test_inspect_named
|
|
95
103
|
path = @tables_dir + "named.groonga"
|
|
96
|
-
named_table = Groonga::Hash.create(:name => "
|
|
104
|
+
named_table = Groonga::Hash.create(:name => "Users", :path => path.to_s)
|
|
97
105
|
assert_equal("#<Groonga::Hash " +
|
|
98
106
|
"id: <#{named_table.id}>, " +
|
|
99
|
-
"name: <
|
|
107
|
+
"name: <Users>, " +
|
|
100
108
|
"path: <#{path}>, " +
|
|
101
|
-
"domain:
|
|
102
|
-
"range:
|
|
109
|
+
"domain: (nil), " +
|
|
110
|
+
"range: (nil), " +
|
|
103
111
|
"flags: <>, " +
|
|
104
112
|
"encoding: <#{encoding.inspect}>, " +
|
|
105
113
|
"size: <0>>",
|
|
@@ -112,8 +120,8 @@ class HashTest < Test::Unit::TestCase
|
|
|
112
120
|
"id: <#{named_table.id}>, " +
|
|
113
121
|
"name: (anonymous), " +
|
|
114
122
|
"path: (temporary), " +
|
|
115
|
-
"domain:
|
|
116
|
-
"range:
|
|
123
|
+
"domain: (nil), " +
|
|
124
|
+
"range: (nil), " +
|
|
117
125
|
"flags: <>, " +
|
|
118
126
|
"encoding: <#{encoding.inspect}>, " +
|
|
119
127
|
"size: <0>>",
|
|
@@ -128,17 +136,17 @@ class HashTest < Test::Unit::TestCase
|
|
|
128
136
|
def test_tokenizer
|
|
129
137
|
hash = Groonga::Hash.create
|
|
130
138
|
assert_nil(hash.default_tokenizer)
|
|
131
|
-
hash.default_tokenizer = "
|
|
132
|
-
assert_equal(Groonga::Context.default["
|
|
139
|
+
hash.default_tokenizer = "TokenBigram"
|
|
140
|
+
assert_equal(Groonga::Context.default["TokenBigram"],
|
|
133
141
|
hash.default_tokenizer)
|
|
134
142
|
end
|
|
135
143
|
|
|
136
144
|
def test_search
|
|
137
|
-
users = Groonga::Array.create(:name => "
|
|
138
|
-
user_name = users.define_column("name", "
|
|
145
|
+
users = Groonga::Array.create(:name => "Users")
|
|
146
|
+
user_name = users.define_column("name", "ShortText")
|
|
139
147
|
|
|
140
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
141
|
-
:key_type => "
|
|
148
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
|
149
|
+
:key_type => "ShortText")
|
|
142
150
|
bookmark_user_id = bookmarks.define_column("user_id", users)
|
|
143
151
|
|
|
144
152
|
daijiro = users.add
|
|
@@ -155,33 +163,33 @@ class HashTest < Test::Unit::TestCase
|
|
|
155
163
|
end
|
|
156
164
|
|
|
157
165
|
def test_add
|
|
158
|
-
users = Groonga::Hash.create(:name => "
|
|
159
|
-
users.define_column("address", "
|
|
166
|
+
users = Groonga::Hash.create(:name => "Users")
|
|
167
|
+
users.define_column("address", "Text")
|
|
160
168
|
me = users.add("me", :address => "me@example.com")
|
|
161
169
|
assert_equal("me@example.com", me[:address])
|
|
162
170
|
end
|
|
163
171
|
|
|
164
172
|
def test_default_tokenizer_on_create
|
|
165
|
-
terms = Groonga::Hash.create(:name => "
|
|
166
|
-
:default_tokenizer => "
|
|
173
|
+
terms = Groonga::Hash.create(:name => "Terms",
|
|
174
|
+
:default_tokenizer => "TokenTrigram")
|
|
167
175
|
assert_equal(context[Groonga::Type::TRIGRAM],
|
|
168
176
|
terms.default_tokenizer)
|
|
169
177
|
end
|
|
170
178
|
|
|
171
179
|
def test_duplicated_name
|
|
172
|
-
Groonga::Hash.create(:name => "
|
|
180
|
+
Groonga::Hash.create(:name => "Users")
|
|
173
181
|
assert_raise(Groonga::InvalidArgument) do
|
|
174
|
-
Groonga::Hash.create(:name => "
|
|
182
|
+
Groonga::Hash.create(:name => "Users")
|
|
175
183
|
end
|
|
176
184
|
end
|
|
177
185
|
|
|
178
186
|
def test_define_index_column_implicit_with_position
|
|
179
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
180
|
-
bookmarks.define_column("comment", "
|
|
181
|
-
terms = Groonga::Hash.create(:name => "
|
|
182
|
-
:default_tokenizer => "
|
|
187
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
188
|
+
bookmarks.define_column("comment", "Text")
|
|
189
|
+
terms = Groonga::Hash.create(:name => "Terms",
|
|
190
|
+
:default_tokenizer => "TokenBigram")
|
|
183
191
|
index = terms.define_index_column("comment", bookmarks,
|
|
184
|
-
:source => "
|
|
192
|
+
:source => "Bookmarks.comment")
|
|
185
193
|
groonga = bookmarks.add("groonga", :comment => "search engine by Brazil")
|
|
186
194
|
google = bookmarks.add("google", :comment => "search engine by Google")
|
|
187
195
|
ruby = bookmarks.add("ruby", :comment => "programing language")
|
|
@@ -191,14 +199,14 @@ class HashTest < Test::Unit::TestCase
|
|
|
191
199
|
end
|
|
192
200
|
|
|
193
201
|
def test_open_same_name
|
|
194
|
-
users_created = Groonga::Hash.create(:name => "
|
|
195
|
-
users_opened = Groonga::Hash.open(:name => "
|
|
202
|
+
users_created = Groonga::Hash.create(:name => "Users")
|
|
203
|
+
users_opened = Groonga::Hash.open(:name => "Users")
|
|
196
204
|
users_opened.add("morita")
|
|
197
205
|
assert_equal(1, users_created.size)
|
|
198
206
|
end
|
|
199
207
|
|
|
200
208
|
def test_has_key?
|
|
201
|
-
users = Groonga::Hash.create(:name => "
|
|
209
|
+
users = Groonga::Hash.create(:name => "Users")
|
|
202
210
|
assert_false(users.has_key?("morita"))
|
|
203
211
|
users.add("morita")
|
|
204
212
|
assert_true(users.has_key?("morita"))
|
|
@@ -210,4 +218,95 @@ class HashTest < Test::Unit::TestCase
|
|
|
210
218
|
hash.add(1 << 63)
|
|
211
219
|
end
|
|
212
220
|
end
|
|
221
|
+
|
|
222
|
+
def test_value_by_key
|
|
223
|
+
users = Groonga::Hash.create(:key_type => "ShortText",
|
|
224
|
+
:value_type => "Int32")
|
|
225
|
+
key = "niku"
|
|
226
|
+
users.add(key)
|
|
227
|
+
users.set_value(key, 29)
|
|
228
|
+
assert_equal(29, users.value(key))
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def test_value_by_id
|
|
232
|
+
users = Groonga::Hash.create(:key_type => "ShortText",
|
|
233
|
+
:value_type => "Int32")
|
|
234
|
+
user_id = users.add("niku").id
|
|
235
|
+
users.set_value(user_id, 29, :id => true)
|
|
236
|
+
assert_equal(29, users.value(user_id, :id => true))
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def test_id
|
|
240
|
+
users = Groonga::Hash.create(:key_type => "ShortText")
|
|
241
|
+
|
|
242
|
+
key = "niku"
|
|
243
|
+
assert_nil(users.id(key))
|
|
244
|
+
user_id = users.add(key).id
|
|
245
|
+
assert_equal(user_id, users.id(key))
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def test_set_multi_values
|
|
249
|
+
users = Groonga::Hash.create(:name => "Users",
|
|
250
|
+
:key_type => "ShortText")
|
|
251
|
+
users.define_column("self_introduction", "ShortText")
|
|
252
|
+
users.define_column("age", "UInt32")
|
|
253
|
+
|
|
254
|
+
key = "niku"
|
|
255
|
+
niku = users.add(key)
|
|
256
|
+
assert_equal({
|
|
257
|
+
"id" => niku.id,
|
|
258
|
+
"key" => key,
|
|
259
|
+
"self_introduction" => nil,
|
|
260
|
+
"age" => 0,
|
|
261
|
+
},
|
|
262
|
+
niku.attributes)
|
|
263
|
+
users[key] = {
|
|
264
|
+
"self_introduction" => "I'm a meet lover.",
|
|
265
|
+
"age" => 29
|
|
266
|
+
}
|
|
267
|
+
assert_equal({
|
|
268
|
+
"id" => niku.id,
|
|
269
|
+
"key" => key,
|
|
270
|
+
"self_introduction" => "I'm a meet lover.",
|
|
271
|
+
"age" => 29,
|
|
272
|
+
},
|
|
273
|
+
niku.attributes)
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def test_set_multi_values_for_nonexistent_record
|
|
277
|
+
users = Groonga::Hash.create(:name => "Users",
|
|
278
|
+
:key_type => "ShortText")
|
|
279
|
+
users.define_column("self_introduction", "ShortText")
|
|
280
|
+
users.define_column("age", "UInt32")
|
|
281
|
+
|
|
282
|
+
key = "niku"
|
|
283
|
+
users[key] = {
|
|
284
|
+
"self_introduction" => "I'm a meet lover.",
|
|
285
|
+
"age" => 29
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
assert_equal({
|
|
289
|
+
"id" => users[key].id,
|
|
290
|
+
"key" => key,
|
|
291
|
+
"self_introduction" => "I'm a meet lover.",
|
|
292
|
+
"age" => 29,
|
|
293
|
+
},
|
|
294
|
+
users[key].attributes)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def test_set_multi_values_with_nonexistent_column
|
|
298
|
+
users = Groonga::Hash.create(:name => "Users",
|
|
299
|
+
:key_type => "ShortText")
|
|
300
|
+
users.define_column("self_introduction", "ShortText")
|
|
301
|
+
users.define_column("age", "UInt32")
|
|
302
|
+
|
|
303
|
+
key = "niku"
|
|
304
|
+
inspected_users = users.inspect.sub(/size: <0>/, "size: <1>")
|
|
305
|
+
message = "no such column: <\"nonexistent\">: <#{inspected_users}>"
|
|
306
|
+
assert_raise(Groonga::NoSuchColumn.new(message)) do
|
|
307
|
+
users[key] = {
|
|
308
|
+
"nonexistent" => "No!",
|
|
309
|
+
}
|
|
310
|
+
end
|
|
311
|
+
end
|
|
213
312
|
end
|