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-table-cursor.rb
CHANGED
|
@@ -20,7 +20,7 @@ class TableCursorTest < Test::Unit::TestCase
|
|
|
20
20
|
setup_database
|
|
21
21
|
|
|
22
22
|
@bookmarks_path = @tables_dir + "table"
|
|
23
|
-
@bookmarks = Groonga::PatriciaTrie.create(:name => "
|
|
23
|
+
@bookmarks = Groonga::PatriciaTrie.create(:name => "Bookmarks",
|
|
24
24
|
:path => @bookmarks_path.to_s)
|
|
25
25
|
@groonga_bookmark = @bookmarks.add("groonga")
|
|
26
26
|
@cutter_bookmark = @bookmarks.add("Cutter")
|
|
@@ -48,4 +48,106 @@ class TableCursorTest < Test::Unit::TestCase
|
|
|
48
48
|
[@groonga_bookmark, "groonga"]],
|
|
49
49
|
record_and_key_list)
|
|
50
50
|
end
|
|
51
|
+
|
|
52
|
+
def test_without_limit_and_offset
|
|
53
|
+
users = create_users
|
|
54
|
+
add_users(users)
|
|
55
|
+
results = []
|
|
56
|
+
users.open_cursor do |cursor|
|
|
57
|
+
cursor.each do |record|
|
|
58
|
+
results << record["name"]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
assert_equal((100..199).collect {|i| "user#{i}"},
|
|
63
|
+
results)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_with_limit
|
|
67
|
+
users = create_users
|
|
68
|
+
add_users(users)
|
|
69
|
+
results = []
|
|
70
|
+
users.open_cursor(:limit => 20) do |cursor|
|
|
71
|
+
cursor.each do |record|
|
|
72
|
+
results << record["name"]
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
assert_equal((100...120).collect {|i| "user#{i}"},
|
|
77
|
+
results)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_with_offset
|
|
81
|
+
users = create_users
|
|
82
|
+
add_users(users)
|
|
83
|
+
results = []
|
|
84
|
+
users.open_cursor(:offset => 20) do |cursor|
|
|
85
|
+
cursor.each do |record|
|
|
86
|
+
results << record["name"]
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
assert_equal((120...200).collect {|i| "user#{i}"},
|
|
91
|
+
results)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_with_limit_and_offset
|
|
95
|
+
users = create_users
|
|
96
|
+
add_users(users)
|
|
97
|
+
results = []
|
|
98
|
+
users.open_cursor(:limit => 20, :offset => 20) do |cursor|
|
|
99
|
+
cursor.each do |record|
|
|
100
|
+
results << record["name"]
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
assert_equal((120...140).collect {|i| "user#{i}"},
|
|
105
|
+
results)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_delete
|
|
109
|
+
users = create_users
|
|
110
|
+
add_users(users)
|
|
111
|
+
|
|
112
|
+
users.open_cursor(:limit => 20) do |cursor|
|
|
113
|
+
20.times do
|
|
114
|
+
cursor.next
|
|
115
|
+
cursor.delete
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
results = []
|
|
120
|
+
users.open_cursor do |cursor|
|
|
121
|
+
cursor.each do |record|
|
|
122
|
+
results << record["name"]
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
assert_equal((120...200).collect {|i| "user#{i}"},
|
|
127
|
+
results)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def test_patricia_trie_cursor_key
|
|
131
|
+
sites = Groonga::PatriciaTrie.create(:name => "Sites")
|
|
132
|
+
sites.add("http://groonga.org/")
|
|
133
|
+
sites.open_cursor do |cursor|
|
|
134
|
+
cursor.next
|
|
135
|
+
assert_equal("http://groonga.org/", cursor.key)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
private
|
|
140
|
+
def create_users
|
|
141
|
+
users = Groonga::Array.create(:name => "Users")
|
|
142
|
+
users.define_column("name", "ShortText")
|
|
143
|
+
users
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def add_users(users)
|
|
147
|
+
(0...100).to_a.each do |i|
|
|
148
|
+
user = users.add
|
|
149
|
+
user["name"] = "user#{i + 100}"
|
|
150
|
+
end
|
|
151
|
+
users
|
|
152
|
+
end
|
|
51
153
|
end
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
module TestOffsetAndLimitSupport
|
|
17
|
+
def test_zero_and_positive_offset
|
|
18
|
+
assert_equal(((100 + 0)...200).to_a, ids(:offset => 0))
|
|
19
|
+
assert_equal(((100 + 32)...200).to_a, ids(:offset => 32))
|
|
20
|
+
assert_equal(((100 + 99)...200).to_a, ids(:offset => 99))
|
|
21
|
+
assert_raise(Groonga::InvalidArgument) do
|
|
22
|
+
ids(:offset => 100)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_negative_offset
|
|
27
|
+
assert_equal(((200 - 1)...200).to_a, ids(:offset => -1))
|
|
28
|
+
assert_equal(((200 - 32)...200).to_a, ids(:offset => -32))
|
|
29
|
+
assert_equal(((200 - 100)...200).to_a, ids(:offset => -100))
|
|
30
|
+
assert_raise(Groonga::InvalidArgument) do
|
|
31
|
+
ids(:offset => -101)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_zero_and_positive_limit
|
|
36
|
+
all_ids = (100...200).to_a
|
|
37
|
+
assert_equal(all_ids[0, 0], ids(:limit => 0))
|
|
38
|
+
assert_equal(all_ids[0, 32], ids(:limit => 32))
|
|
39
|
+
assert_equal(all_ids[0, 100], ids(:limit => 100))
|
|
40
|
+
assert_nothing_raised do
|
|
41
|
+
ids(:limit => 101)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_negative_limit
|
|
46
|
+
all_ids = (100...200).to_a
|
|
47
|
+
assert_equal(all_ids[0..-1], ids(:limit => -1))
|
|
48
|
+
assert_equal(all_ids[0..-32], ids(:limit => -32))
|
|
49
|
+
assert_equal(all_ids[0..-100], ids(:limit => -100))
|
|
50
|
+
assert_raise(Groonga::InvalidArgument) do
|
|
51
|
+
ids(:offset => -101)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
def create_bookmarks
|
|
57
|
+
@bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
|
58
|
+
@bookmarks.define_column("id", "Int32")
|
|
59
|
+
@bookmarks
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def add_ids
|
|
63
|
+
100.times do |i|
|
|
64
|
+
bookmark = @bookmarks.add
|
|
65
|
+
bookmark["id"] = i + 100
|
|
66
|
+
end
|
|
67
|
+
@bookmarks
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class TestOffsetAndLimit < Test::Unit::TestCase
|
|
72
|
+
include GroongaTestUtils
|
|
73
|
+
def setup
|
|
74
|
+
setup_database
|
|
75
|
+
@bookmarks = create_bookmarks
|
|
76
|
+
add_ids
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
class TestTableCursorOffsetAndLimit < TestOffsetAndLimit
|
|
81
|
+
include TestOffsetAndLimitSupport
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
def ids(options={})
|
|
85
|
+
@bookmarks.open_cursor(options) do |cursor|
|
|
86
|
+
cursor.collect do |record|
|
|
87
|
+
record["id"]
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
class TestTableSortOffsetAndLimit < TestOffsetAndLimit
|
|
94
|
+
include TestOffsetAndLimitSupport
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
def ids(options={})
|
|
98
|
+
@bookmarks.sort([:key => "id", :order => :asc], options).collect do |record|
|
|
99
|
+
record["id"]
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -15,22 +15,22 @@
|
|
|
15
15
|
# License along with this library; if not, write to the Free Software
|
|
16
16
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17
17
|
|
|
18
|
-
class
|
|
18
|
+
class TableSelectNormalizeTest < Test::Unit::TestCase
|
|
19
19
|
include GroongaTestUtils
|
|
20
20
|
|
|
21
21
|
setup :setup_database
|
|
22
22
|
|
|
23
23
|
setup
|
|
24
24
|
def setup_comments
|
|
25
|
-
@comments = Groonga::Array.create(:name => "
|
|
25
|
+
@comments = Groonga::Array.create(:name => "Comments")
|
|
26
26
|
@comments.define_column("content", "Text")
|
|
27
27
|
@comments.define_column("created_at", "Time")
|
|
28
|
-
terms = Groonga::PatriciaTrie.create(:name => "
|
|
28
|
+
terms = Groonga::PatriciaTrie.create(:name => "Terms",
|
|
29
29
|
:default_tokenizer => "TokenBigram",
|
|
30
30
|
:key_normalize => true)
|
|
31
31
|
terms.define_index_column("comment_content", @comments,
|
|
32
32
|
:with_section => true,
|
|
33
|
-
:source => "
|
|
33
|
+
:source => "Comments.content")
|
|
34
34
|
@japanese_comment =
|
|
35
35
|
@comments.add(:content => "うちのボロTVはまだ現役です",
|
|
36
36
|
:created_at => Time.parse("2009-06-09"))
|
data/test/test-table-select.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
#
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
|
|
3
4
|
#
|
|
4
5
|
# This library is free software; you can redistribute it and/or
|
|
5
6
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -14,30 +15,37 @@
|
|
|
14
15
|
# License along with this library; if not, write to the Free Software
|
|
15
16
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16
17
|
|
|
17
|
-
class
|
|
18
|
+
class TableSelectTest < Test::Unit::TestCase
|
|
18
19
|
include GroongaTestUtils
|
|
19
20
|
|
|
20
21
|
setup :setup_database
|
|
21
22
|
|
|
22
23
|
setup
|
|
23
24
|
def setup_comments
|
|
24
|
-
@
|
|
25
|
+
@users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
|
|
26
|
+
|
|
27
|
+
@comments = Groonga::Array.create(:name => "Comments")
|
|
25
28
|
@comments.define_column("content", "Text")
|
|
26
29
|
@comments.define_column("created_at", "Time")
|
|
27
|
-
|
|
30
|
+
@comments.define_column("user", "Users")
|
|
31
|
+
|
|
32
|
+
terms = Groonga::PatriciaTrie.create(:name => "Terms",
|
|
28
33
|
:default_tokenizer => "TokenBigram")
|
|
29
34
|
terms.define_index_column("comment_content", @comments,
|
|
30
35
|
:with_section => true,
|
|
31
|
-
:source => "
|
|
36
|
+
:source => "content")
|
|
32
37
|
@comment1 = @comments.add(:content => "Hello Good-bye!",
|
|
33
|
-
:created_at => Time.parse("2009-08-09")
|
|
38
|
+
:created_at => Time.parse("2009-08-09"),
|
|
39
|
+
:user => "morita")
|
|
34
40
|
@comment2 = @comments.add(:content => "Hello World",
|
|
35
41
|
:created_at => Time.parse("2009-07-09"))
|
|
36
42
|
@comment3 = @comments.add(:content => "test",
|
|
37
|
-
:created_at => Time.parse("2009-06-09")
|
|
43
|
+
:created_at => Time.parse("2009-06-09"),
|
|
44
|
+
:user => "gunyara-kun")
|
|
38
45
|
@japanese_comment =
|
|
39
46
|
@comments.add(:content => "うちのボロTVはまだ現役です",
|
|
40
|
-
:created_at => Time.parse("2009-06-09")
|
|
47
|
+
:created_at => Time.parse("2009-06-09"),
|
|
48
|
+
:user => "darashi")
|
|
41
49
|
end
|
|
42
50
|
|
|
43
51
|
def test_select_sub_expression
|
|
@@ -53,6 +61,22 @@ class TableTestSelect < Test::Unit::TestCase
|
|
|
53
61
|
assert_equal_select_result([@comment1, @comment2], result)
|
|
54
62
|
end
|
|
55
63
|
|
|
64
|
+
def test_select_query_with_parser
|
|
65
|
+
result = @comments.select("content @ \"Hello\"", :syntax => :script)
|
|
66
|
+
assert_equal_select_result([@comment1, @comment2], result)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_select_expression
|
|
70
|
+
expression = Groonga::Expression.new
|
|
71
|
+
variable = expression.define_variable(:domain => @comments)
|
|
72
|
+
expression.append_object(variable)
|
|
73
|
+
expression.parse("content:%Hello", :syntax => :query)
|
|
74
|
+
expression.compile
|
|
75
|
+
result = @comments.select(expression)
|
|
76
|
+
assert_equal(expression, result.expression)
|
|
77
|
+
assert_equal_select_result([@comment1, @comment2], result)
|
|
78
|
+
end
|
|
79
|
+
|
|
56
80
|
def test_select_query_with_block
|
|
57
81
|
result = @comments.select("content:%Hello") do |record|
|
|
58
82
|
record["created_at"] < Time.parse("2009-08-01")
|
|
@@ -98,4 +122,24 @@ class TableTestSelect < Test::Unit::TestCase
|
|
|
98
122
|
end
|
|
99
123
|
assert_equal_select_result([], result)
|
|
100
124
|
end
|
|
125
|
+
|
|
126
|
+
def test_select_equal_reference_column_by_key
|
|
127
|
+
result = @comments.select do |record|
|
|
128
|
+
record["user"] == "darashi"
|
|
129
|
+
end
|
|
130
|
+
assert_equal_select_result([@japanese_comment], result)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_select_not_equal_reference_column_by_key
|
|
134
|
+
result = @comments.select('user != "darashi"', :syntax => :script)
|
|
135
|
+
assert_equal_select_result([@comment1, @comment2, @comment3],
|
|
136
|
+
result)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_select_equal_reference_column_by_nonexistent_key
|
|
140
|
+
result = @comments.select do |record|
|
|
141
|
+
record["user"] == "nonexistent"
|
|
142
|
+
end
|
|
143
|
+
assert_equal_select_result([], result)
|
|
144
|
+
end
|
|
101
145
|
end
|
data/test/test-table.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
|
|
1
|
+
# Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
|
|
2
2
|
#
|
|
3
3
|
# This library is free software; you can redistribute it and/or
|
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -19,31 +19,33 @@ class TableTest < Test::Unit::TestCase
|
|
|
19
19
|
setup :setup_database
|
|
20
20
|
|
|
21
21
|
def test_create
|
|
22
|
-
table_path = @tables_dir + "
|
|
22
|
+
table_path = @tables_dir + "bookmarks"
|
|
23
23
|
assert_not_predicate(table_path, :exist?)
|
|
24
|
-
table = Groonga::PatriciaTrie.create(:name => "
|
|
24
|
+
table = Groonga::PatriciaTrie.create(:name => "Bookmarks",
|
|
25
25
|
:path => table_path.to_s)
|
|
26
|
-
assert_equal("
|
|
26
|
+
assert_equal("Bookmarks", table.name)
|
|
27
27
|
assert_predicate(table_path, :exist?)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def test_temporary
|
|
31
31
|
table = Groonga::PatriciaTrie.create
|
|
32
32
|
assert_nil(table.name)
|
|
33
|
+
assert_predicate(table, :temporary?)
|
|
34
|
+
assert_not_predicate(table, :persistent?)
|
|
33
35
|
assert_equal([], @tables_dir.children)
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
def test_open
|
|
37
|
-
table_path = @tables_dir + "
|
|
38
|
-
table = Groonga::Hash.create(:name => "
|
|
39
|
+
table_path = @tables_dir + "bookmarks"
|
|
40
|
+
table = Groonga::Hash.create(:name => "Bookmarks",
|
|
39
41
|
:path => table_path.to_s)
|
|
40
|
-
assert_equal("
|
|
42
|
+
assert_equal("Bookmarks", table.name)
|
|
41
43
|
|
|
42
44
|
called = false
|
|
43
|
-
Groonga::Table.open(:name => "
|
|
45
|
+
Groonga::Table.open(:name => "Bookmarks") do |_table|
|
|
44
46
|
table = _table
|
|
45
47
|
assert_not_predicate(table, :closed?)
|
|
46
|
-
assert_equal("
|
|
48
|
+
assert_equal("Bookmarks", _table.name)
|
|
47
49
|
called = true
|
|
48
50
|
end
|
|
49
51
|
assert_true(called)
|
|
@@ -51,10 +53,10 @@ class TableTest < Test::Unit::TestCase
|
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
def test_open_by_path
|
|
54
|
-
table_path = @tables_dir + "
|
|
55
|
-
table = Groonga::PatriciaTrie.create(:name => "
|
|
56
|
+
table_path = @tables_dir + "bookmarks"
|
|
57
|
+
table = Groonga::PatriciaTrie.create(:name => "Bookmarks",
|
|
56
58
|
:path => table_path.to_s)
|
|
57
|
-
assert_equal("
|
|
59
|
+
assert_equal("Bookmarks", table.name)
|
|
58
60
|
table.close
|
|
59
61
|
|
|
60
62
|
called = false
|
|
@@ -69,17 +71,17 @@ class TableTest < Test::Unit::TestCase
|
|
|
69
71
|
end
|
|
70
72
|
|
|
71
73
|
def test_open_override_name
|
|
72
|
-
table_path = @tables_dir + "
|
|
73
|
-
table = Groonga::PatriciaTrie.create(:name => "
|
|
74
|
+
table_path = @tables_dir + "bookmarks"
|
|
75
|
+
table = Groonga::PatriciaTrie.create(:name => "Bookmarks",
|
|
74
76
|
:path => table_path.to_s)
|
|
75
|
-
assert_equal("
|
|
77
|
+
assert_equal("Bookmarks", table.name)
|
|
76
78
|
table.close
|
|
77
79
|
|
|
78
80
|
called = false
|
|
79
|
-
Groonga::Table.open(:name => "
|
|
81
|
+
Groonga::Table.open(:name => "Marks", :path => table_path.to_s) do |_table|
|
|
80
82
|
table = _table
|
|
81
83
|
assert_not_predicate(table, :closed?)
|
|
82
|
-
assert_equal("
|
|
84
|
+
assert_equal("Marks", _table.name)
|
|
83
85
|
called = true
|
|
84
86
|
end
|
|
85
87
|
assert_true(called)
|
|
@@ -87,19 +89,19 @@ class TableTest < Test::Unit::TestCase
|
|
|
87
89
|
end
|
|
88
90
|
|
|
89
91
|
def test_open_wrong_table
|
|
90
|
-
table_path = @tables_dir + "
|
|
91
|
-
Groonga::Hash.create(:name => "
|
|
92
|
+
table_path = @tables_dir + "bookmarks"
|
|
93
|
+
Groonga::Hash.create(:name => "Bookmarks",
|
|
92
94
|
:path => table_path.to_s) do
|
|
93
95
|
end
|
|
94
96
|
|
|
95
97
|
assert_raise(TypeError) do
|
|
96
|
-
Groonga::PatriciaTrie.open(:name => "
|
|
98
|
+
Groonga::PatriciaTrie.open(:name => "Bookmarks",
|
|
97
99
|
:path => table_path.to_s)
|
|
98
100
|
end
|
|
99
101
|
end
|
|
100
102
|
|
|
101
103
|
def test_new
|
|
102
|
-
table_path = @tables_dir + "
|
|
104
|
+
table_path = @tables_dir + "no-name"
|
|
103
105
|
assert_raise(Groonga::NoSuchFileOrDirectory) do
|
|
104
106
|
Groonga::Hash.new(:path => table_path.to_s)
|
|
105
107
|
end
|
|
@@ -109,42 +111,108 @@ class TableTest < Test::Unit::TestCase
|
|
|
109
111
|
end
|
|
110
112
|
|
|
111
113
|
def test_define_column
|
|
112
|
-
table_path = @tables_dir + "
|
|
113
|
-
table = Groonga::Hash.create(:name => "
|
|
114
|
+
table_path = @tables_dir + "bookmarks"
|
|
115
|
+
table = Groonga::Hash.create(:name => "Bookmarks",
|
|
114
116
|
:path => table_path.to_s)
|
|
115
|
-
column = table.define_column("name", "
|
|
116
|
-
assert_equal("
|
|
117
|
+
column = table.define_column("name", "Text")
|
|
118
|
+
assert_equal("Bookmarks.name", column.name)
|
|
117
119
|
assert_equal(column, table.column("name"))
|
|
118
120
|
end
|
|
119
121
|
|
|
122
|
+
def test_temporary_table_define_column_default_persistent
|
|
123
|
+
table = Groonga::Hash.create
|
|
124
|
+
name = table.define_column("name", "ShortText")
|
|
125
|
+
assert_predicate(name, :temporary?)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_temporary_table_define_index_column_default_persistent
|
|
129
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
130
|
+
terms = Groonga::Hash.create
|
|
131
|
+
url = terms.define_index_column("url", bookmarks)
|
|
132
|
+
assert_predicate(url, :temporary?)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def test_define_column_default_persistent
|
|
136
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
137
|
+
real_name = bookmarks.define_column("real_name", "ShortText")
|
|
138
|
+
assert_predicate(real_name, :persistent?)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_define_column_not_persistent
|
|
142
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
143
|
+
real_name = bookmarks.define_column("real_name", "ShortText",
|
|
144
|
+
:persistent => false)
|
|
145
|
+
assert_predicate(real_name, :temporary?)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_define_column_not_persistent_and_path
|
|
149
|
+
column_path = @tables_dir + "bookmakrs.real_name.column"
|
|
150
|
+
|
|
151
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
152
|
+
message = "should not pass :path if :persistent is false: <#{column_path}>"
|
|
153
|
+
assert_raise(ArgumentError.new(message)) do
|
|
154
|
+
real_name = bookmarks.define_column("real_name", "ShortText",
|
|
155
|
+
:path => column_path.to_s,
|
|
156
|
+
:persistent => false)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def test_define_index_column_default_persistent
|
|
161
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
162
|
+
terms = Groonga::Hash.create(:name => "Terms")
|
|
163
|
+
real_name = terms.define_index_column("real_name", bookmarks)
|
|
164
|
+
assert_predicate(real_name, :persistent?)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def test_define_index_column_not_persistent
|
|
168
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
169
|
+
terms = Groonga::Hash.create(:name => "Terms")
|
|
170
|
+
real_name = terms.define_index_column("real_name", bookmarks,
|
|
171
|
+
:persistent => false)
|
|
172
|
+
assert_predicate(real_name, :temporary?)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_define_index_column_not_persistent_and_path
|
|
176
|
+
column_path = @tables_dir + "bookmakrs.real_name.column"
|
|
177
|
+
|
|
178
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
179
|
+
terms = Groonga::Hash.create(:name => "Terms")
|
|
180
|
+
message = "should not pass :path if :persistent is false: <#{column_path}>"
|
|
181
|
+
assert_raise(ArgumentError.new(message)) do
|
|
182
|
+
real_name = terms.define_index_column("real_name", bookmarks,
|
|
183
|
+
:path => column_path.to_s,
|
|
184
|
+
:persistent => false)
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
120
188
|
def test_define_index_column
|
|
121
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
122
|
-
bookmarks.define_column("content", "
|
|
123
|
-
terms = Groonga::Hash.create(:name => "
|
|
124
|
-
terms.default_tokenizer = "
|
|
189
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
190
|
+
bookmarks.define_column("content", "Text")
|
|
191
|
+
terms = Groonga::Hash.create(:name => "Terms")
|
|
192
|
+
terms.default_tokenizer = "TokenBigram"
|
|
125
193
|
index = terms.define_index_column("content-index", bookmarks,
|
|
126
194
|
:with_section => true,
|
|
127
|
-
:source => "
|
|
195
|
+
:source => "Bookmarks.content")
|
|
128
196
|
bookmarks.add("google", :content => "Search engine")
|
|
129
197
|
assert_equal(["google"],
|
|
130
198
|
index.search("engine").collect {|record| record.key.key})
|
|
131
199
|
end
|
|
132
200
|
|
|
133
201
|
def test_add_column
|
|
134
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
202
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
|
135
203
|
:path => (@tables_dir + "bookmarks").to_s)
|
|
136
204
|
|
|
137
205
|
description_column_path = @columns_dir + "description"
|
|
138
206
|
bookmarks_description =
|
|
139
|
-
bookmarks.define_index_column("description", "
|
|
207
|
+
bookmarks.define_index_column("description", "Text",
|
|
140
208
|
:path => description_column_path.to_s)
|
|
141
209
|
|
|
142
|
-
books = Groonga::Hash.create(:name => "
|
|
210
|
+
books = Groonga::Hash.create(:name => "Books",
|
|
143
211
|
:path => (@tables_dir + "books").to_s)
|
|
144
212
|
books_description = books.add_column("description",
|
|
145
|
-
"
|
|
213
|
+
"LongText",
|
|
146
214
|
description_column_path.to_s)
|
|
147
|
-
assert_equal("
|
|
215
|
+
assert_equal("Books.description", books_description.name)
|
|
148
216
|
assert_equal(books_description, books.column("description"))
|
|
149
217
|
|
|
150
218
|
assert_equal(bookmarks_description, bookmarks.column("description"))
|
|
@@ -152,51 +220,46 @@ class TableTest < Test::Unit::TestCase
|
|
|
152
220
|
|
|
153
221
|
def test_column_nonexistent
|
|
154
222
|
table_path = @tables_dir + "bookmarks"
|
|
155
|
-
table = Groonga::Hash.create(:name => "
|
|
223
|
+
table = Groonga::Hash.create(:name => "Bookmarks",
|
|
156
224
|
:path => table_path.to_s)
|
|
157
225
|
assert_nil(table.column("nonexistent"))
|
|
158
226
|
end
|
|
159
227
|
|
|
160
228
|
def test_set_value
|
|
161
|
-
value_type = Groonga::Type.new("Text512", :size => 512)
|
|
162
229
|
table_path = @tables_dir + "bookmarks"
|
|
163
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
164
|
-
:value_type =>
|
|
230
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
|
231
|
+
:value_type => "Int32",
|
|
165
232
|
:path => table_path.to_s)
|
|
166
233
|
comment_column_path = @columns_dir + "comment"
|
|
167
234
|
bookmarks_comment =
|
|
168
|
-
bookmarks.define_column("comment", "
|
|
235
|
+
bookmarks.define_column("comment", "ShortText",
|
|
169
236
|
:type => "scalar",
|
|
170
237
|
:path => comment_column_path.to_s)
|
|
171
238
|
groonga = bookmarks.add("groonga")
|
|
172
|
-
|
|
173
|
-
groonga.value = url
|
|
239
|
+
groonga.value = 29
|
|
174
240
|
bookmarks_comment[groonga.id] = "fulltext search engine"
|
|
175
241
|
|
|
176
|
-
assert_equal([
|
|
177
|
-
[groonga.value
|
|
178
|
-
bookmarks_comment[groonga.id]])
|
|
242
|
+
assert_equal([29, "fulltext search engine"],
|
|
243
|
+
[groonga.value, bookmarks_comment[groonga.id]])
|
|
179
244
|
end
|
|
180
245
|
|
|
181
246
|
def test_array_set
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
url = "http://groonga.org/"
|
|
186
|
-
bookmarks["groonga"] = "#{url}\0"
|
|
247
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
|
248
|
+
:value_type => "Int32")
|
|
249
|
+
bookmarks.set_value("groonga", 29)
|
|
187
250
|
|
|
188
251
|
values = bookmarks.records.collect do |record|
|
|
189
|
-
record.value
|
|
252
|
+
record.value
|
|
190
253
|
end
|
|
191
|
-
assert_equal([
|
|
254
|
+
assert_equal([29], values)
|
|
192
255
|
end
|
|
193
256
|
|
|
194
257
|
def test_add_without_name
|
|
195
258
|
users_path = @tables_dir + "users"
|
|
196
|
-
users = Groonga::Array.create(:name => "
|
|
259
|
+
users = Groonga::Array.create(:name => "Users",
|
|
197
260
|
:path => users_path.to_s)
|
|
198
261
|
name_column_path = @columns_dir + "name"
|
|
199
|
-
users_name = users.define_column("name", "
|
|
262
|
+
users_name = users.define_column("name", "ShortText",
|
|
200
263
|
:path => name_column_path.to_s)
|
|
201
264
|
morita = users.add
|
|
202
265
|
users_name[morita.id] = "morita"
|
|
@@ -205,37 +268,34 @@ class TableTest < Test::Unit::TestCase
|
|
|
205
268
|
|
|
206
269
|
def test_add_by_id
|
|
207
270
|
users_path = @tables_dir + "users"
|
|
208
|
-
users = Groonga::Hash.create(:name => "
|
|
271
|
+
users = Groonga::Hash.create(:name => "Users",
|
|
209
272
|
:path => users_path.to_s)
|
|
210
273
|
|
|
211
|
-
value_type = Groonga::Type.new("Text512", :size => 512)
|
|
212
274
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
213
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
275
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
|
214
276
|
:key_type => users,
|
|
215
|
-
:value_type =>
|
|
277
|
+
:value_type => "Int32",
|
|
216
278
|
:path => bookmarks_path.to_s)
|
|
217
279
|
morita = users.add("morita")
|
|
218
280
|
groonga = bookmarks.add(morita.id)
|
|
219
|
-
|
|
220
|
-
groonga.value
|
|
221
|
-
|
|
222
|
-
assert_equal(url, groonga.value[0, url.length])
|
|
281
|
+
groonga.value = 29
|
|
282
|
+
assert_equal(29, groonga.value)
|
|
223
283
|
end
|
|
224
284
|
|
|
225
285
|
def test_columns
|
|
226
286
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
227
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
287
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
|
228
288
|
:path => bookmarks_path.to_s)
|
|
229
289
|
|
|
230
|
-
uri_column = bookmarks.define_column("uri", "
|
|
231
|
-
comment_column = bookmarks.define_column("comment", "
|
|
290
|
+
uri_column = bookmarks.define_column("uri", "ShortText")
|
|
291
|
+
comment_column = bookmarks.define_column("comment", "Text")
|
|
232
292
|
assert_equal([uri_column.name, comment_column.name].sort,
|
|
233
293
|
bookmarks.columns.collect {|column| column.name}.sort)
|
|
234
294
|
end
|
|
235
295
|
|
|
236
296
|
def test_column_by_symbol
|
|
237
297
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
238
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
298
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
|
239
299
|
:path => bookmarks_path.to_s)
|
|
240
300
|
|
|
241
301
|
uri_column = bookmarks.define_column("uri", "Text")
|
|
@@ -244,7 +304,7 @@ class TableTest < Test::Unit::TestCase
|
|
|
244
304
|
|
|
245
305
|
def test_size
|
|
246
306
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
247
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
307
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
|
248
308
|
:path => bookmarks_path.to_s)
|
|
249
309
|
|
|
250
310
|
assert_equal(0, bookmarks.size)
|
|
@@ -256,11 +316,18 @@ class TableTest < Test::Unit::TestCase
|
|
|
256
316
|
assert_equal(3, bookmarks.size)
|
|
257
317
|
end
|
|
258
318
|
|
|
319
|
+
def test_path
|
|
320
|
+
bookmarks_path = @tables_dir + "bookmarks"
|
|
321
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
|
322
|
+
:path => bookmarks_path.to_s)
|
|
323
|
+
assert_equal(bookmarks_path.to_s, bookmarks.path)
|
|
324
|
+
end
|
|
325
|
+
|
|
259
326
|
def test_time_column
|
|
260
327
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
261
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
328
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
|
262
329
|
:path => bookmarks_path.to_s)
|
|
263
|
-
column = bookmarks.define_column("created_at", "
|
|
330
|
+
column = bookmarks.define_column("created_at", "Time")
|
|
264
331
|
|
|
265
332
|
bookmark = bookmarks.add
|
|
266
333
|
now = Time.now
|
|
@@ -271,7 +338,7 @@ class TableTest < Test::Unit::TestCase
|
|
|
271
338
|
|
|
272
339
|
def test_delete
|
|
273
340
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
274
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
341
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
|
275
342
|
:path => bookmarks_path.to_s)
|
|
276
343
|
|
|
277
344
|
bookmark1 = bookmarks.add
|
|
@@ -285,7 +352,7 @@ class TableTest < Test::Unit::TestCase
|
|
|
285
352
|
|
|
286
353
|
def test_remove
|
|
287
354
|
bookmarks_path = @tables_dir + "bookmarks"
|
|
288
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
355
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
|
289
356
|
:path => bookmarks_path.to_s)
|
|
290
357
|
assert_predicate(bookmarks_path, :exist?)
|
|
291
358
|
bookmarks.remove
|
|
@@ -293,15 +360,15 @@ class TableTest < Test::Unit::TestCase
|
|
|
293
360
|
end
|
|
294
361
|
|
|
295
362
|
def test_temporary_add
|
|
296
|
-
table = Groonga::Hash.create(:key_type => "
|
|
363
|
+
table = Groonga::Hash.create(:key_type => "ShortText")
|
|
297
364
|
assert_equal(0, table.size)
|
|
298
365
|
table.add("key")
|
|
299
366
|
assert_equal(1, table.size)
|
|
300
367
|
end
|
|
301
368
|
|
|
302
369
|
def test_each
|
|
303
|
-
users = Groonga::Array.create(:name => "
|
|
304
|
-
user_name = users.define_column("name", "
|
|
370
|
+
users = Groonga::Array.create(:name => "Users")
|
|
371
|
+
user_name = users.define_column("name", "ShortText")
|
|
305
372
|
|
|
306
373
|
names = ["daijiro", "gunyarakun", "yu"]
|
|
307
374
|
names.each do |name|
|
|
@@ -313,7 +380,7 @@ class TableTest < Test::Unit::TestCase
|
|
|
313
380
|
end
|
|
314
381
|
|
|
315
382
|
def test_truncate
|
|
316
|
-
users = Groonga::Array.create(:name => "
|
|
383
|
+
users = Groonga::Array.create(:name => "Users")
|
|
317
384
|
users.add
|
|
318
385
|
users.add
|
|
319
386
|
users.add
|
|
@@ -325,12 +392,8 @@ class TableTest < Test::Unit::TestCase
|
|
|
325
392
|
end
|
|
326
393
|
|
|
327
394
|
def test_sort
|
|
328
|
-
bookmarks =
|
|
329
|
-
|
|
330
|
-
100.times do |i|
|
|
331
|
-
bookmark = bookmarks.add
|
|
332
|
-
bookmark["id"] = i + 100
|
|
333
|
-
end
|
|
395
|
+
bookmarks = create_bookmarks
|
|
396
|
+
add_shuffled_ids(bookmarks)
|
|
334
397
|
|
|
335
398
|
results = bookmarks.sort([
|
|
336
399
|
{
|
|
@@ -344,12 +407,8 @@ class TableTest < Test::Unit::TestCase
|
|
|
344
407
|
end
|
|
345
408
|
|
|
346
409
|
def test_sort_simple
|
|
347
|
-
bookmarks =
|
|
348
|
-
|
|
349
|
-
100.times do |i|
|
|
350
|
-
bookmark = bookmarks.add
|
|
351
|
-
bookmark["id"] = i + 100
|
|
352
|
-
end
|
|
410
|
+
bookmarks = create_bookmarks
|
|
411
|
+
add_shuffled_ids(bookmarks)
|
|
353
412
|
|
|
354
413
|
results = bookmarks.sort(["id"], :limit => 20)
|
|
355
414
|
assert_equal((100..119).to_a,
|
|
@@ -357,35 +416,66 @@ class TableTest < Test::Unit::TestCase
|
|
|
357
416
|
end
|
|
358
417
|
|
|
359
418
|
def test_sort_by_array
|
|
360
|
-
bookmarks =
|
|
361
|
-
|
|
362
|
-
100.times do |i|
|
|
363
|
-
bookmark = bookmarks.add
|
|
364
|
-
bookmark["id"] = i + 100
|
|
365
|
-
end
|
|
419
|
+
bookmarks = create_bookmarks
|
|
420
|
+
add_shuffled_ids(bookmarks)
|
|
366
421
|
|
|
367
422
|
results = bookmarks.sort([["id", "descending"]], :limit => 20)
|
|
368
423
|
assert_equal((180..199).to_a.reverse,
|
|
369
424
|
results.collect {|record| record["id"]})
|
|
370
425
|
end
|
|
371
426
|
|
|
372
|
-
def
|
|
373
|
-
bookmarks =
|
|
374
|
-
|
|
375
|
-
100.times do |i|
|
|
376
|
-
bookmark = bookmarks.add
|
|
377
|
-
bookmark["id"] = i + 100
|
|
378
|
-
end
|
|
427
|
+
def test_sort_without_limit_and_offset
|
|
428
|
+
bookmarks = create_bookmarks
|
|
429
|
+
add_shuffled_ids(bookmarks)
|
|
379
430
|
|
|
380
431
|
results = bookmarks.sort([{:key => "id", :order => :descending}])
|
|
381
432
|
assert_equal((100..199).to_a.reverse,
|
|
382
433
|
results.collect {|record| record["id"]})
|
|
383
434
|
end
|
|
384
435
|
|
|
436
|
+
def test_sort_with_limit
|
|
437
|
+
bookmarks = create_bookmarks
|
|
438
|
+
add_shuffled_ids(bookmarks)
|
|
439
|
+
|
|
440
|
+
results = bookmarks.sort([{:key => "id", :order => :descending}],
|
|
441
|
+
:limit => 20)
|
|
442
|
+
assert_equal((180..199).to_a.reverse,
|
|
443
|
+
results.collect {|record| record["id"]})
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
def test_sort_with_offset
|
|
447
|
+
bookmarks = create_bookmarks
|
|
448
|
+
add_shuffled_ids(bookmarks)
|
|
449
|
+
|
|
450
|
+
results = bookmarks.sort([{:key => "id", :order => :descending}],
|
|
451
|
+
:offset => 20)
|
|
452
|
+
assert_equal((100..179).to_a.reverse,
|
|
453
|
+
results.collect {|record| record["id"]})
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
def test_sort_with_limit_and_offset
|
|
457
|
+
bookmarks = create_bookmarks
|
|
458
|
+
add_shuffled_ids(bookmarks)
|
|
459
|
+
|
|
460
|
+
results = bookmarks.sort([{:key => "id", :order => :descending}],
|
|
461
|
+
:limit => 20, :offset => 20)
|
|
462
|
+
assert_equal((160..179).to_a.reverse,
|
|
463
|
+
results.collect {|record| record["id"]})
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
def test_sort_with_nonexistent_key
|
|
467
|
+
omit("maybe crash!!!")
|
|
468
|
+
bookmarks = create_bookmarks
|
|
469
|
+
add_shuffled_ids(bookmarks)
|
|
470
|
+
results = bookmarks.sort([{:key => "nonexistent", :order => :descending}])
|
|
471
|
+
assert_equal("unknown",
|
|
472
|
+
results.collect {|record| record["id"]})
|
|
473
|
+
end
|
|
474
|
+
|
|
385
475
|
def test_group
|
|
386
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
387
|
-
bookmarks.define_column("title", "
|
|
388
|
-
comments = Groonga::Array.create(:name => "
|
|
476
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
477
|
+
bookmarks.define_column("title", "Text")
|
|
478
|
+
comments = Groonga::Array.create(:name => "Comments")
|
|
389
479
|
comments.define_column("bookmark", bookmarks)
|
|
390
480
|
comments.define_column("content", "Text")
|
|
391
481
|
comments.define_column("issued", "Int32")
|
|
@@ -409,16 +499,16 @@ class TableTest < Test::Unit::TestCase
|
|
|
409
499
|
end
|
|
410
500
|
assert_equal([[2, "groonga", "http://groonga.org/"],
|
|
411
501
|
[1, "Ruby", "http://ruby-lang.org/"]],
|
|
412
|
-
records.group(
|
|
502
|
+
records.group(".bookmark").collect do |record|
|
|
413
503
|
bookmark = record.key
|
|
414
|
-
[record
|
|
504
|
+
[record.n_sub_records,
|
|
415
505
|
bookmark["title"],
|
|
416
506
|
bookmark.key]
|
|
417
507
|
end)
|
|
418
508
|
end
|
|
419
509
|
|
|
420
510
|
def test_union!
|
|
421
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
511
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
422
512
|
bookmarks.define_column("title", "ShortText")
|
|
423
513
|
|
|
424
514
|
groonga = bookmarks.add("http://groonga.org/", :title => "groonga")
|
|
@@ -448,7 +538,7 @@ class TableTest < Test::Unit::TestCase
|
|
|
448
538
|
end
|
|
449
539
|
|
|
450
540
|
def test_difference!
|
|
451
|
-
bookmarks = Groonga::Hash.create(:name => "
|
|
541
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
452
542
|
bookmarks.define_column("title", "ShortText")
|
|
453
543
|
|
|
454
544
|
bookmarks.add("http://groonga.org/", :title => "groonga")
|
|
@@ -463,23 +553,23 @@ class TableTest < Test::Unit::TestCase
|
|
|
463
553
|
end
|
|
464
554
|
|
|
465
555
|
def test_merge!
|
|
466
|
-
|
|
467
|
-
bookmarks = Groonga::Hash.create(:name => "bookmarks")
|
|
556
|
+
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
|
468
557
|
bookmarks.define_column("title", "ShortText")
|
|
469
558
|
|
|
470
559
|
bookmarks.add("http://groonga.org/", :title => "groonga")
|
|
471
560
|
bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
|
|
472
561
|
|
|
473
|
-
ruby_bookmarks = bookmarks.select {|record| record["title"] == "Ruby"
|
|
562
|
+
ruby_bookmarks = bookmarks.select {|record| (record["title"] == "Ruby") &
|
|
563
|
+
(record["title"] == "Ruby") }
|
|
474
564
|
all_bookmarks = bookmarks.select
|
|
475
|
-
assert_equal(["groonga"],
|
|
565
|
+
assert_equal([["groonga", 1], ["Ruby", 2]],
|
|
476
566
|
all_bookmarks.merge!(ruby_bookmarks).collect do |record|
|
|
477
|
-
[record[".title"], record
|
|
567
|
+
[record[".title"], record.score]
|
|
478
568
|
end)
|
|
479
569
|
end
|
|
480
570
|
|
|
481
571
|
def test_lock
|
|
482
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
572
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
|
483
573
|
bookmark = bookmarks.add
|
|
484
574
|
|
|
485
575
|
assert_not_predicate(bookmarks, :locked?)
|
|
@@ -490,7 +580,7 @@ class TableTest < Test::Unit::TestCase
|
|
|
490
580
|
end
|
|
491
581
|
|
|
492
582
|
def test_lock_failed
|
|
493
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
583
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
|
494
584
|
bookmark = bookmarks.add
|
|
495
585
|
|
|
496
586
|
bookmarks.lock
|
|
@@ -500,7 +590,7 @@ class TableTest < Test::Unit::TestCase
|
|
|
500
590
|
end
|
|
501
591
|
|
|
502
592
|
def test_lock_block
|
|
503
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
593
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
|
504
594
|
bookmark = bookmarks.add
|
|
505
595
|
|
|
506
596
|
assert_not_predicate(bookmarks, :locked?)
|
|
@@ -511,7 +601,7 @@ class TableTest < Test::Unit::TestCase
|
|
|
511
601
|
end
|
|
512
602
|
|
|
513
603
|
def test_clear_lock
|
|
514
|
-
bookmarks = Groonga::Array.create(:name => "
|
|
604
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
|
515
605
|
bookmark = bookmarks.add
|
|
516
606
|
|
|
517
607
|
assert_not_predicate(bookmarks, :locked?)
|
|
@@ -520,4 +610,33 @@ class TableTest < Test::Unit::TestCase
|
|
|
520
610
|
bookmarks.clear_lock
|
|
521
611
|
assert_not_predicate(bookmarks, :locked?)
|
|
522
612
|
end
|
|
613
|
+
|
|
614
|
+
def test_auto_record_register
|
|
615
|
+
users = Groonga::Hash.create(:name => "Users",
|
|
616
|
+
:key_type => "ShortText")
|
|
617
|
+
books = Groonga::Hash.create(:name => "Books",
|
|
618
|
+
:key_type => "ShortText")
|
|
619
|
+
users.define_column("book", "Books")
|
|
620
|
+
|
|
621
|
+
assert_equal([], books.select.collect {|book| book.key})
|
|
622
|
+
users.add("ryoqun", :book => "XP")
|
|
623
|
+
assert_equal([books["XP"]],
|
|
624
|
+
books.select.collect {|book| book.key})
|
|
625
|
+
end
|
|
626
|
+
|
|
627
|
+
private
|
|
628
|
+
def create_bookmarks
|
|
629
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
|
630
|
+
bookmarks.define_column("id", "Int32")
|
|
631
|
+
bookmarks
|
|
632
|
+
end
|
|
633
|
+
|
|
634
|
+
def add_shuffled_ids(bookmarks)
|
|
635
|
+
srand(Time.now.to_i)
|
|
636
|
+
(0...100).to_a.shuffle.each do |i|
|
|
637
|
+
bookmark = bookmarks.add
|
|
638
|
+
bookmark["id"] = i + 100
|
|
639
|
+
end
|
|
640
|
+
bookmarks
|
|
641
|
+
end
|
|
523
642
|
end
|