rroonga 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +21 -2
- data/bin/grndump +3 -2
- data/ext/groonga/extconf.rb +1 -6
- data/ext/groonga/rb-grn-array.c +58 -31
- data/ext/groonga/rb-grn-column.c +220 -148
- data/ext/groonga/rb-grn-context.c +46 -32
- data/ext/groonga/rb-grn-database.c +102 -90
- data/ext/groonga/rb-grn-double-array-trie.c +205 -163
- data/ext/groonga/rb-grn-encoding-support.c +2 -3
- data/ext/groonga/rb-grn-encoding.c +13 -8
- data/ext/groonga/rb-grn-exception.c +1 -1
- data/ext/groonga/rb-grn-expression.c +110 -133
- data/ext/groonga/rb-grn-fix-size-column.c +5 -4
- data/ext/groonga/rb-grn-geo-point.c +55 -0
- data/ext/groonga/rb-grn-hash.c +120 -82
- data/ext/groonga/rb-grn-index-column.c +66 -70
- data/ext/groonga/rb-grn-index-cursor.c +3 -0
- data/ext/groonga/rb-grn-logger.c +33 -51
- data/ext/groonga/rb-grn-object.c +2 -0
- data/ext/groonga/rb-grn-operator.c +1 -1
- data/ext/groonga/rb-grn-patricia-trie.c +287 -232
- data/ext/groonga/rb-grn-plugin.c +11 -14
- data/ext/groonga/rb-grn-snippet.c +37 -54
- data/ext/groonga/rb-grn-table-cursor-key-support.c +3 -3
- data/ext/groonga/rb-grn-table-cursor.c +8 -6
- data/ext/groonga/rb-grn-table-key-support.c +22 -29
- data/ext/groonga/rb-grn-table.c +355 -279
- data/ext/groonga/rb-grn-type.c +18 -25
- data/ext/groonga/rb-grn-utils.c +77 -7
- data/ext/groonga/rb-grn-variable-size-column.c +12 -20
- data/ext/groonga/rb-grn-view.c +56 -51
- data/ext/groonga/rb-grn.h +28 -1
- data/ext/groonga/rb-groonga.c +1 -0
- data/lib/groonga.rb +2 -0
- data/lib/groonga/command.rb +3 -1
- data/lib/groonga/database.rb +27 -0
- data/lib/groonga/dumper.rb +96 -17
- data/lib/groonga/geo-point.rb +216 -0
- data/lib/groonga/schema.rb +29 -46
- data/rroonga-build.rb +1 -1
- data/rroonga.gemspec +90 -0
- data/test/groonga-test-utils.rb +168 -0
- data/test/run-test.rb +60 -0
- data/test/test-accessor.rb +36 -0
- data/test/test-array.rb +146 -0
- data/test/test-column.rb +350 -0
- data/test/test-command-select.rb +181 -0
- data/test/test-context.rb +130 -0
- data/test/test-database-dumper.rb +259 -0
- data/test/test-database.rb +173 -0
- data/test/test-double-array-trie.rb +189 -0
- data/test/test-encoding.rb +33 -0
- data/test/test-exception.rb +230 -0
- data/test/test-expression-builder.rb +602 -0
- data/test/test-expression.rb +134 -0
- data/test/test-fix-size-column.rb +77 -0
- data/test/test-geo-point.rb +190 -0
- data/test/test-gqtp.rb +70 -0
- data/test/test-hash.rb +367 -0
- data/test/test-index-column.rb +180 -0
- data/test/test-index-cursor.rb +123 -0
- data/test/test-logger.rb +37 -0
- data/test/test-pagination.rb +249 -0
- data/test/test-patricia-trie.rb +440 -0
- data/test/test-plugin.rb +35 -0
- data/test/test-procedure.rb +37 -0
- data/test/test-query-log.rb +258 -0
- data/test/test-record.rb +577 -0
- data/test/test-remote.rb +63 -0
- data/test/test-schema-create-table.rb +267 -0
- data/test/test-schema-dumper.rb +235 -0
- data/test/test-schema-type.rb +208 -0
- data/test/test-schema-view.rb +90 -0
- data/test/test-schema.rb +886 -0
- data/test/test-snippet.rb +130 -0
- data/test/test-table-dumper.rb +353 -0
- data/test/test-table-offset-and-limit.rb +100 -0
- data/test/test-table-select-mecab.rb +80 -0
- data/test/test-table-select-normalize.rb +57 -0
- data/test/test-table-select-weight.rb +123 -0
- data/test/test-table-select.rb +191 -0
- data/test/test-table-traverse.rb +304 -0
- data/test/test-table.rb +711 -0
- data/test/test-type.rb +79 -0
- data/test/test-variable-size-column.rb +147 -0
- data/test/test-variable.rb +28 -0
- data/test/test-vector-column.rb +76 -0
- data/test/test-version.rb +61 -0
- data/test/test-view.rb +72 -0
- metadata +330 -202
data/test/test-array.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Copyright (C) 2009-2012 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_support_key?
|
22
|
+
assert_not_predicate(Groonga::Array.create(:name => "Users"), :support_key?)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_inspect_size
|
26
|
+
path = @tables_dir + "named.groonga"
|
27
|
+
contain_table = Groonga::Array.create(:name => "name", :path => path.to_s)
|
28
|
+
3.times do
|
29
|
+
contain_table.add
|
30
|
+
end
|
31
|
+
assert_equal("#<Groonga::Array " +
|
32
|
+
"id: <#{contain_table.id}>, " +
|
33
|
+
"name: <name>, " +
|
34
|
+
"path: <#{path}>, " +
|
35
|
+
"domain: (nil), " +
|
36
|
+
"range: (nil), " +
|
37
|
+
"flags: <>, " +
|
38
|
+
"size: <3>>",
|
39
|
+
contain_table.inspect)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_encoding
|
43
|
+
array = Groonga::Array.create
|
44
|
+
assert_false(array.respond_to?(:encoding))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_add
|
48
|
+
users = Groonga::Array.create(:name => "Users")
|
49
|
+
users.define_column("name", "Text")
|
50
|
+
me = users.add(:name => "me")
|
51
|
+
assert_equal("me", me[:name])
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_define_index_column
|
55
|
+
users = Groonga::Array.create(:name => "Users")
|
56
|
+
users.define_column("name", "Text")
|
57
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
58
|
+
bookmarks.define_column("title", "Text")
|
59
|
+
bookmarks.define_column("user", users)
|
60
|
+
|
61
|
+
index = users.define_index_column("bookmarks", bookmarks,
|
62
|
+
:source => "Bookmarks.user")
|
63
|
+
morita = users.add(:name => "morita")
|
64
|
+
gunyara_kun = users.add(:name => "gunyara-kun")
|
65
|
+
bookmarks.add(:title => "groonga", :user => morita)
|
66
|
+
bookmarks.add(:title => "google", :user => morita)
|
67
|
+
bookmarks.add(:title => "Python", :user => gunyara_kun)
|
68
|
+
|
69
|
+
assert_equal(["groonga", "google"],
|
70
|
+
index.search(morita.id).collect {|record| record.key["title"]})
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_create_duplicated_name
|
74
|
+
Groonga::Array.create(:name => "Users")
|
75
|
+
assert_raise(Groonga::InvalidArgument) do
|
76
|
+
Groonga::Array.create(:name => "Users")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_value
|
81
|
+
users = Groonga::Array.create(:value_type => "Int32")
|
82
|
+
user_id = users.add.id
|
83
|
+
users.set_value(user_id, 29)
|
84
|
+
assert_equal(29, users.value(user_id))
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_column_value
|
88
|
+
users = Groonga::Array.create(:name => "Users")
|
89
|
+
users.define_column("name", "ShortText")
|
90
|
+
morita_id = users.add.id
|
91
|
+
users.set_column_value(morita_id, "name", "morita")
|
92
|
+
assert_equal("morita", users.column_value(morita_id, "name"))
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_added?
|
96
|
+
users = Groonga::Array.create(:name => "Users")
|
97
|
+
first_user = users.add
|
98
|
+
assert_predicate(first_user, :added?)
|
99
|
+
second_user = users.add
|
100
|
+
assert_predicate(second_user, :added?)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_defrag
|
104
|
+
users = Groonga::Array.create(:name => "Users")
|
105
|
+
users.define_column("name", "ShortText")
|
106
|
+
users.define_column("address", "ShortText")
|
107
|
+
1000.times do |i|
|
108
|
+
users.add(:name => "user #{i}" * 1000,
|
109
|
+
:address => "address #{i}" * 1000)
|
110
|
+
end
|
111
|
+
assert_equal(7, users.defrag)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_rename
|
115
|
+
users = Groonga::Array.create(:name => "Users")
|
116
|
+
name = users.define_column("name", "ShortText")
|
117
|
+
address = users.define_column("address", "ShortText")
|
118
|
+
|
119
|
+
users.rename("People")
|
120
|
+
assert_equal(["People", "People.name", "People.address"],
|
121
|
+
[users.name, name.name, address.name])
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_each
|
125
|
+
users = Groonga::Array.create(:name => "Users")
|
126
|
+
users.add
|
127
|
+
users.add
|
128
|
+
users.add
|
129
|
+
|
130
|
+
user_ids = []
|
131
|
+
users.each do |user|
|
132
|
+
user_ids << user.id
|
133
|
+
end
|
134
|
+
assert_equal([1, 2, 3], user_ids)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_each_without_block
|
138
|
+
users = Groonga::Array.create(:name => "Users")
|
139
|
+
users.add
|
140
|
+
users.add
|
141
|
+
users.add
|
142
|
+
|
143
|
+
user_ids = users.each.collect(&:id)
|
144
|
+
assert_equal([1, 2, 3], user_ids)
|
145
|
+
end
|
146
|
+
end
|
data/test/test-column.rb
ADDED
@@ -0,0 +1,350 @@
|
|
1
|
+
# Copyright (C) 2009-2011 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 ColumnTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def setup
|
20
|
+
setup_database
|
21
|
+
|
22
|
+
setup_users_table
|
23
|
+
setup_bookmarks_table
|
24
|
+
setup_indexes
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup_users_table
|
28
|
+
@users_path = @tables_dir + "users"
|
29
|
+
@users = Groonga::Array.create(:name => "Users",
|
30
|
+
:path => @users_path.to_s)
|
31
|
+
|
32
|
+
@users_name_column_path = @columns_dir + "name"
|
33
|
+
@users_name_column =
|
34
|
+
@users.define_column("name", "ShortText",
|
35
|
+
:path => @users_name_column_path.to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup_bookmarks_table
|
39
|
+
@bookmarks_path = @tables_dir + "bookmarks"
|
40
|
+
@bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
41
|
+
:path => @bookmarks_path.to_s)
|
42
|
+
|
43
|
+
@uri_column_path = @columns_dir + "uri"
|
44
|
+
@bookmarks_uri = @bookmarks.define_column("uri", "ShortText",
|
45
|
+
:path => @uri_column_path.to_s)
|
46
|
+
|
47
|
+
@comment_column_path = @columns_dir + "comment"
|
48
|
+
@bookmarks_comment =
|
49
|
+
@bookmarks.define_column("comment", "Text",
|
50
|
+
:path => @comment_column_path.to_s)
|
51
|
+
|
52
|
+
@content_column_path = @columns_dir + "content"
|
53
|
+
@bookmarks_content = @bookmarks.define_column("content", "LongText")
|
54
|
+
|
55
|
+
@user_column_path = @columns_dir + "user"
|
56
|
+
@bookmarks_user = @bookmarks.define_column("user", @users)
|
57
|
+
end
|
58
|
+
|
59
|
+
def setup_indexes
|
60
|
+
@bookmarks_index_path = @tables_dir + "bookmarks-index"
|
61
|
+
@bookmarks_index =
|
62
|
+
Groonga::PatriciaTrie.create(:name => "BookmarksIndex",
|
63
|
+
:path => @bookmarks_index_path.to_s,
|
64
|
+
:key_type => "ShortText")
|
65
|
+
@bookmarks_index.default_tokenizer = "TokenBigram"
|
66
|
+
|
67
|
+
@content_index_column_path = @columns_dir + "content-index"
|
68
|
+
@bookmarks_index_content =
|
69
|
+
@bookmarks_index.define_index_column("content", @bookmarks,
|
70
|
+
:with_section => true,
|
71
|
+
:with_weight => true,
|
72
|
+
:with_position => true,
|
73
|
+
:path => @content_index_column_path.to_s)
|
74
|
+
|
75
|
+
@uri_index_column_path = @columns_dir + "uri-index"
|
76
|
+
@bookmarks_index_uri =
|
77
|
+
@bookmarks_index.define_index_column("uri", @bookmarks,
|
78
|
+
:path => @uri_index_column_path.to_s)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_source_info
|
82
|
+
@bookmarks_index_content.sources = [@bookmarks_content]
|
83
|
+
|
84
|
+
groonga = @bookmarks.add
|
85
|
+
groonga["content"] = "<html><body>groonga</body></html>"
|
86
|
+
|
87
|
+
ruby = @bookmarks.add
|
88
|
+
ruby["content"] = "<html><body>ruby</body></html>"
|
89
|
+
|
90
|
+
assert_content_search([groonga], "groonga")
|
91
|
+
assert_content_search([groonga, ruby], "html")
|
92
|
+
|
93
|
+
assert_equal([@bookmarks_content], @bookmarks_index_content.sources)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_update_index_column
|
97
|
+
groonga = @bookmarks.add
|
98
|
+
groonga["content"] = "<html><body>groonga</body></html>"
|
99
|
+
|
100
|
+
ruby = @bookmarks.add
|
101
|
+
ruby["content"] = "<html><body>ruby</body></html>"
|
102
|
+
|
103
|
+
@bookmarks_index_content[groonga.id] = groonga["content"]
|
104
|
+
@bookmarks_index_content[ruby.id] = ruby["content"]
|
105
|
+
|
106
|
+
assert_content_search([groonga], "groonga")
|
107
|
+
assert_content_search([groonga, ruby], "html")
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_range
|
111
|
+
assert_equal(context[Groonga::Type::SHORT_TEXT], @bookmarks_uri.range)
|
112
|
+
assert_equal(context[Groonga::Type::TEXT], @bookmarks_comment.range)
|
113
|
+
assert_equal(context[Groonga::Type::LONG_TEXT], @bookmarks_content.range)
|
114
|
+
assert_equal(@users, @bookmarks_user.range)
|
115
|
+
assert_equal(@bookmarks, @bookmarks_index_content.range)
|
116
|
+
assert_equal(@bookmarks, @bookmarks_index_uri.range)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_accessor
|
120
|
+
posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
121
|
+
posts.define_column("body", "Text")
|
122
|
+
comments = Groonga::Hash.create(:name => "Comments",
|
123
|
+
:key_type => "ShortText")
|
124
|
+
content = comments.define_column("content", "ShortText")
|
125
|
+
comments.define_column("post", posts)
|
126
|
+
|
127
|
+
index = Groonga::PatriciaTrie.create(:name => "Terms",
|
128
|
+
:key_type => "ShortText")
|
129
|
+
index.default_tokenizer = "TokenBigram"
|
130
|
+
content_index = index.define_index_column("content_index", comments,
|
131
|
+
:with_position => true)
|
132
|
+
content_index.source = content
|
133
|
+
|
134
|
+
first_post = posts.add("Hello!")
|
135
|
+
first_post["body"] = "World"
|
136
|
+
hobby = posts.add("My Hobby")
|
137
|
+
hobby["body"] = "Drive and Eat"
|
138
|
+
|
139
|
+
friend = comments.add("Me too")
|
140
|
+
friend["content"] = "I'm also like drive"
|
141
|
+
friend["post"] = hobby
|
142
|
+
|
143
|
+
result = content_index.search("drive")
|
144
|
+
assert_equal([["I'm also like drive", "My Hobby"]],
|
145
|
+
result.records.collect do |record|
|
146
|
+
[record[".content"], record[".post._key"]]
|
147
|
+
end)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_accessor_reference
|
151
|
+
bookmark = @bookmarks.add
|
152
|
+
assert_nil(@bookmarks_user[bookmark.id])
|
153
|
+
|
154
|
+
daijiro = @users.add
|
155
|
+
daijiro["name"] = "daijiro"
|
156
|
+
@bookmarks_user[bookmark.id] = daijiro
|
157
|
+
assert_equal(daijiro, @bookmarks_user[bookmark.id])
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_array_set_with_key_of_table
|
161
|
+
languages = Groonga::Hash.create(:name => "Languages",
|
162
|
+
:key_type => "ShortText")
|
163
|
+
sites = Groonga::Hash.create(:name => "Sites")
|
164
|
+
sites.define_column("language", languages)
|
165
|
+
|
166
|
+
languages.add("Ruby")
|
167
|
+
taiyaki_ru = sites.add("http://taiyaki.ru/", :language => "Ruby")
|
168
|
+
assert_equal("Ruby", taiyaki_ru[:language].key)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_local_name
|
172
|
+
items = Groonga::Array.create(:name => "Items")
|
173
|
+
title = items.define_column("title", "ShortText")
|
174
|
+
assert_equal("Items.title", title.name)
|
175
|
+
assert_equal("title", title.local_name)
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_select_query
|
179
|
+
populate_table_for_select
|
180
|
+
|
181
|
+
result = @body.select("drive")
|
182
|
+
assert_equal(["Drive and Eat"],
|
183
|
+
result.records.collect do |record|
|
184
|
+
record["body"]
|
185
|
+
end)
|
186
|
+
assert_equal("#<Groonga::Expression noname($1:\"\")" +
|
187
|
+
"{2body GET_VALUE,0\"drive\",0MATCH}>",
|
188
|
+
result.expression.inspect)
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_select_query_from_ctx
|
192
|
+
populate_table_for_select
|
193
|
+
|
194
|
+
body = Groonga::Context.default['Posts.body']
|
195
|
+
# select twice.
|
196
|
+
result = body.select("drive")
|
197
|
+
assert_equal(["Drive and Eat"],
|
198
|
+
result.records.collect do |record|
|
199
|
+
record["body"]
|
200
|
+
end)
|
201
|
+
|
202
|
+
result = body.select("drive")
|
203
|
+
assert_equal(["Drive and Eat"],
|
204
|
+
result.records.collect do |record|
|
205
|
+
record["body"]
|
206
|
+
end)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_select_query_with_parser
|
210
|
+
populate_table_for_select
|
211
|
+
|
212
|
+
result = @body.select("body @ \"drive\"", :syntax => :script)
|
213
|
+
assert_equal(["Drive and Eat"],
|
214
|
+
result.records.collect do |record|
|
215
|
+
record["body"]
|
216
|
+
end)
|
217
|
+
assert_equal("#<Groonga::Expression noname($1:\"\")" +
|
218
|
+
"{2body GET_VALUE,0\"drive\",0MATCH}>",
|
219
|
+
result.expression.inspect)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_select_expression
|
223
|
+
populate_table_for_select
|
224
|
+
|
225
|
+
expression = Groonga::Expression.new
|
226
|
+
variable = expression.define_variable(:domain => @posts)
|
227
|
+
expression.append_object(variable)
|
228
|
+
expression.parse("body:@drive", :syntax => :query)
|
229
|
+
expression.compile
|
230
|
+
result = @body.select(expression)
|
231
|
+
assert_equal(["Drive and Eat"],
|
232
|
+
result.records.collect do |record|
|
233
|
+
record["body"]
|
234
|
+
end)
|
235
|
+
assert_equal("#<Groonga::Expression noname($1:\"\")" +
|
236
|
+
"{0\"\",2body GET_VALUE,0\"drive\",0MATCH}>",
|
237
|
+
result.expression.inspect)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_select_with_block
|
241
|
+
populate_table_for_select
|
242
|
+
|
243
|
+
result = @body.select do |column|
|
244
|
+
column =~ "drive"
|
245
|
+
end
|
246
|
+
assert_equal(["Drive and Eat"],
|
247
|
+
result.records.collect do |record|
|
248
|
+
record["body"]
|
249
|
+
end)
|
250
|
+
assert_equal("#<Groonga::Expression noname($1:\"\")" +
|
251
|
+
"{1\"\",2body GET_VALUE,0\"drive\",0MATCH}>",
|
252
|
+
result.expression.inspect)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_set_time
|
256
|
+
posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
257
|
+
posts.define_column("issued", "Time")
|
258
|
+
|
259
|
+
post = posts.add("hello", :issued => 123456)
|
260
|
+
assert_equal(Time.at(123456), post[".issued"])
|
261
|
+
post = posts.add("groonga", :issued => 1251380635)
|
262
|
+
assert_equal(Time.parse("2009-08-27 22:43:55 +0900"), post[".issued"])
|
263
|
+
post = posts.add("mroonga", :issued => 1251380635.1234567)
|
264
|
+
assert_in_delta(Time.at(1251380635.1234567).usec, post[".issued"].usec, 10)
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_set_nil_to_time
|
268
|
+
posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
269
|
+
posts.define_column("issued", "Time")
|
270
|
+
|
271
|
+
post = posts.add("hello", :issued => nil)
|
272
|
+
assert_equal(Time.at(0), post["issued"])
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_bool
|
276
|
+
posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
277
|
+
posts.define_column("hidden", "Bool")
|
278
|
+
|
279
|
+
post = posts.add("hello")
|
280
|
+
assert_false(post["hidden"])
|
281
|
+
|
282
|
+
post["hidden"] = true
|
283
|
+
assert_true(post["hidden"])
|
284
|
+
|
285
|
+
post["hidden"] = false
|
286
|
+
assert_false(post["hidden"])
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_indexes
|
290
|
+
Groonga::Schema.define do |schema|
|
291
|
+
schema.create_table("Comments") do |table|
|
292
|
+
table.short_text("title")
|
293
|
+
end
|
294
|
+
end
|
295
|
+
title = Groonga["Comments.title"]
|
296
|
+
assert_equal([], title.indexes)
|
297
|
+
|
298
|
+
Groonga::Schema.define do |schema|
|
299
|
+
schema.create_table("Terms",
|
300
|
+
:type => :patricia_trie,
|
301
|
+
:default_tokenizer => "TokenBigram") do |table|
|
302
|
+
table.index("Comments.title")
|
303
|
+
end
|
304
|
+
end
|
305
|
+
assert_equal([Groonga["Terms.Comments_title"]],
|
306
|
+
title.indexes)
|
307
|
+
|
308
|
+
Groonga::Schema.define do |schema|
|
309
|
+
schema.create_table("Titles",
|
310
|
+
:type => :hash) do |table|
|
311
|
+
table.index("Comments.title")
|
312
|
+
end
|
313
|
+
end
|
314
|
+
assert_equal([Groonga["Titles.Comments_title"],
|
315
|
+
Groonga["Terms.Comments_title"]],
|
316
|
+
title.indexes)
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_builtin?
|
320
|
+
assert_not_predicate(@users_name_column, :builtin?)
|
321
|
+
end
|
322
|
+
|
323
|
+
private
|
324
|
+
def assert_content_search(expected_records, term)
|
325
|
+
records = @bookmarks_index_content.search(term).records
|
326
|
+
expected_contents = expected_records.collect do |record|
|
327
|
+
record["content"]
|
328
|
+
end
|
329
|
+
actual_contents = records.collect do |record|
|
330
|
+
record.key["content"]
|
331
|
+
end
|
332
|
+
assert_equal(expected_contents, actual_contents)
|
333
|
+
end
|
334
|
+
|
335
|
+
def populate_table_for_select
|
336
|
+
@posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
337
|
+
@body = @posts.define_column("body", "Text")
|
338
|
+
|
339
|
+
index = Groonga::PatriciaTrie.create(:name => "Terms",
|
340
|
+
:key_type => "ShortText",
|
341
|
+
:key_normalize => true)
|
342
|
+
index.default_tokenizer = "TokenBigram"
|
343
|
+
index.define_index_column("body_index", @posts,
|
344
|
+
:with_position => true,
|
345
|
+
:source => @body)
|
346
|
+
|
347
|
+
@posts.add("Hello!", :body => "World")
|
348
|
+
@posts.add("My Hobby", :body => "Drive and Eat")
|
349
|
+
end
|
350
|
+
end
|