groonga 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- metadata +38 -227
- data/AUTHORS +0 -5
- data/NEWS.ja.rdoc +0 -114
- data/NEWS.rdoc +0 -116
- data/README.ja.rdoc +0 -63
- data/README.rdoc +0 -64
- data/Rakefile +0 -216
- data/benchmark/common.rb +0 -49
- data/benchmark/read-write-many-small-items.rb +0 -144
- data/benchmark/write-many-small-items.rb +0 -135
- data/example/bookmark.rb +0 -161
- data/example/index-html.rb +0 -89
- data/example/search/config.ru +0 -211
- data/example/search/public/css/groonga.css +0 -122
- data/ext/.gitignore +0 -2
- data/ext/rb-grn-accessor.c +0 -52
- data/ext/rb-grn-array-cursor.c +0 -36
- data/ext/rb-grn-array.c +0 -210
- data/ext/rb-grn-column.c +0 -570
- data/ext/rb-grn-context.c +0 -655
- data/ext/rb-grn-database.c +0 -415
- data/ext/rb-grn-encoding-support.c +0 -64
- data/ext/rb-grn-encoding.c +0 -257
- data/ext/rb-grn-exception.c +0 -1110
- data/ext/rb-grn-expression-builder.c +0 -75
- data/ext/rb-grn-expression.c +0 -732
- data/ext/rb-grn-fix-size-column.c +0 -166
- data/ext/rb-grn-hash-cursor.c +0 -38
- data/ext/rb-grn-hash.c +0 -294
- data/ext/rb-grn-index-column.c +0 -488
- data/ext/rb-grn-logger.c +0 -325
- data/ext/rb-grn-object.c +0 -1335
- data/ext/rb-grn-operation.c +0 -198
- data/ext/rb-grn-patricia-trie-cursor.c +0 -39
- data/ext/rb-grn-patricia-trie.c +0 -488
- data/ext/rb-grn-procedure.c +0 -52
- data/ext/rb-grn-query.c +0 -260
- data/ext/rb-grn-record.c +0 -40
- data/ext/rb-grn-snippet.c +0 -328
- data/ext/rb-grn-table-cursor-key-support.c +0 -69
- data/ext/rb-grn-table-cursor.c +0 -246
- data/ext/rb-grn-table-key-support.c +0 -731
- data/ext/rb-grn-table.c +0 -2038
- data/ext/rb-grn-type.c +0 -181
- data/ext/rb-grn-utils.c +0 -769
- data/ext/rb-grn-variable-size-column.c +0 -36
- data/ext/rb-grn-variable.c +0 -108
- data/ext/rb-grn.h +0 -684
- data/ext/rb-groonga.c +0 -113
- data/extconf.rb +0 -216
- data/html/bar.svg +0 -153
- data/html/developer.html +0 -121
- data/html/developer.svg +0 -469
- data/html/download.svg +0 -253
- data/html/favicon.ico +0 -0
- data/html/favicon.xcf +0 -0
- data/html/footer.html.erb +0 -28
- data/html/head.html.erb +0 -4
- data/html/header.html.erb +0 -17
- data/html/index.html +0 -147
- data/html/install.svg +0 -636
- data/html/logo.xcf +0 -0
- data/html/ranguba.css +0 -248
- data/html/tutorial.svg +0 -559
- data/lib/groonga.rb +0 -83
- data/lib/groonga/expression-builder.rb +0 -285
- data/lib/groonga/patricia-trie.rb +0 -53
- data/lib/groonga/record.rb +0 -276
- data/lib/groonga/schema.rb +0 -916
- data/license/GPL +0 -340
- data/license/LGPL +0 -504
- data/license/RUBY +0 -59
- data/misc/grnop2ruby.rb +0 -49
- data/pkg-config.rb +0 -333
- data/src/rb-grn-table-cursor.c +0 -296
- data/test-unit/Rakefile +0 -40
- data/test-unit/TODO +0 -5
- data/test-unit/bin/testrb +0 -5
- data/test-unit/html/classic.html +0 -15
- data/test-unit/html/index.html +0 -25
- data/test-unit/html/index.html.ja +0 -27
- data/test-unit/lib/test/unit.rb +0 -323
- data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
- data/test-unit/lib/test/unit/assertions.rb +0 -1230
- data/test-unit/lib/test/unit/attribute.rb +0 -125
- data/test-unit/lib/test/unit/autorunner.rb +0 -353
- data/test-unit/lib/test/unit/collector.rb +0 -36
- data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
- data/test-unit/lib/test/unit/collector/dir.rb +0 -108
- data/test-unit/lib/test/unit/collector/load.rb +0 -136
- data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
- data/test-unit/lib/test/unit/color-scheme.rb +0 -102
- data/test-unit/lib/test/unit/color.rb +0 -96
- data/test-unit/lib/test/unit/diff.rb +0 -724
- data/test-unit/lib/test/unit/error.rb +0 -130
- data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
- data/test-unit/lib/test/unit/failure.rb +0 -136
- data/test-unit/lib/test/unit/fixture.rb +0 -176
- data/test-unit/lib/test/unit/notification.rb +0 -129
- data/test-unit/lib/test/unit/omission.rb +0 -191
- data/test-unit/lib/test/unit/pending.rb +0 -150
- data/test-unit/lib/test/unit/priority.rb +0 -181
- data/test-unit/lib/test/unit/runner/console.rb +0 -52
- data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
- data/test-unit/lib/test/unit/runner/tap.rb +0 -8
- data/test-unit/lib/test/unit/testcase.rb +0 -476
- data/test-unit/lib/test/unit/testresult.rb +0 -89
- data/test-unit/lib/test/unit/testsuite.rb +0 -110
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -464
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
- data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -92
- data/test-unit/lib/test/unit/ui/testrunner.rb +0 -28
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
- data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
- data/test-unit/lib/test/unit/util/observable.rb +0 -90
- data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
- data/test-unit/lib/test/unit/version.rb +0 -7
- data/test-unit/sample/adder.rb +0 -13
- data/test-unit/sample/subtracter.rb +0 -12
- data/test-unit/sample/test_adder.rb +0 -20
- data/test-unit/sample/test_subtracter.rb +0 -20
- data/test-unit/sample/test_user.rb +0 -23
- data/test-unit/test/collector/test-descendant.rb +0 -133
- data/test-unit/test/collector/test-load.rb +0 -329
- data/test-unit/test/collector/test_dir.rb +0 -406
- data/test-unit/test/collector/test_objectspace.rb +0 -100
- data/test-unit/test/run-test.rb +0 -15
- data/test-unit/test/test-attribute.rb +0 -86
- data/test-unit/test/test-color-scheme.rb +0 -67
- data/test-unit/test/test-color.rb +0 -47
- data/test-unit/test/test-diff.rb +0 -518
- data/test-unit/test/test-emacs-runner.rb +0 -60
- data/test-unit/test/test-fixture.rb +0 -287
- data/test-unit/test/test-notification.rb +0 -33
- data/test-unit/test/test-omission.rb +0 -81
- data/test-unit/test/test-pending.rb +0 -70
- data/test-unit/test/test-priority.rb +0 -119
- data/test-unit/test/test-testcase.rb +0 -554
- data/test-unit/test/test_assertions.rb +0 -1151
- data/test-unit/test/test_error.rb +0 -26
- data/test-unit/test/test_failure.rb +0 -33
- data/test-unit/test/test_testresult.rb +0 -113
- data/test-unit/test/test_testsuite.rb +0 -129
- data/test-unit/test/testunit-test-util.rb +0 -14
- data/test-unit/test/ui/test_testrunmediator.rb +0 -20
- data/test-unit/test/util/test-method-owner-finder.rb +0 -38
- data/test-unit/test/util/test_backtracefilter.rb +0 -41
- data/test-unit/test/util/test_observable.rb +0 -102
- data/test-unit/test/util/test_procwrapper.rb +0 -36
- data/test/.gitignore +0 -1
- data/test/groonga-test-utils.rb +0 -106
- data/test/run-test.rb +0 -58
- data/test/test-array.rb +0 -97
- data/test/test-column.rb +0 -298
- data/test/test-context.rb +0 -73
- data/test/test-database.rb +0 -113
- data/test/test-encoding.rb +0 -33
- data/test/test-exception.rb +0 -93
- data/test/test-expression-builder.rb +0 -156
- data/test/test-expression.rb +0 -133
- data/test/test-fix-size-column.rb +0 -65
- data/test/test-gqtp.rb +0 -70
- data/test/test-hash.rb +0 -312
- data/test/test-index-column.rb +0 -81
- data/test/test-patricia-trie.rb +0 -189
- data/test/test-procedure.rb +0 -37
- data/test/test-query.rb +0 -22
- data/test/test-record.rb +0 -268
- data/test/test-remote.rb +0 -53
- data/test/test-schema.rb +0 -416
- data/test/test-snippet.rb +0 -121
- data/test/test-table-cursor.rb +0 -153
- data/test/test-table-offset-and-limit.rb +0 -102
- data/test/test-table-select-normalize.rb +0 -48
- data/test/test-table-select.rb +0 -145
- data/test/test-table.rb +0 -642
- data/test/test-type.rb +0 -61
- data/test/test-variable-size-column.rb +0 -98
- data/test/test-variable.rb +0 -28
- data/test/test-vector-column.rb +0 -76
- data/test/test-version.rb +0 -31
- data/text/TUTORIAL.ja.rdoc +0 -392
- data/text/expression.rdoc +0 -284
data/test/test-expression.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
# Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or
|
5
|
-
# modify it under the terms of the GNU Lesser General Public
|
6
|
-
# License version 2.1 as published by the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This library is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
-
# Lesser General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public
|
14
|
-
# License along with this library; if not, write to the Free Software
|
15
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
16
|
-
|
17
|
-
class ExpressionTest < Test::Unit::TestCase
|
18
|
-
include GroongaTestUtils
|
19
|
-
|
20
|
-
setup :setup_database
|
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
|
-
|
37
|
-
def test_get_value
|
38
|
-
users = Groonga::Hash.create(:name => "Users")
|
39
|
-
name = users.define_column("name", "ShortText")
|
40
|
-
|
41
|
-
morita = users.add("morita", :name => "mori daijiro")
|
42
|
-
|
43
|
-
expression = Groonga::Expression.new
|
44
|
-
expression.append_constant(morita)
|
45
|
-
expression.append_constant("name")
|
46
|
-
expression.append_operation(Groonga::Operation::GET_VALUE, 2)
|
47
|
-
expression.compile
|
48
|
-
expression.execute
|
49
|
-
assert_equal("mori daijiro", context.pop)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_get_value_with_variable
|
53
|
-
users = Groonga::Hash.create(:name => "Users")
|
54
|
-
name = users.define_column("name", "ShortText")
|
55
|
-
|
56
|
-
morita = users.add("morita", :name => "mori daijiro")
|
57
|
-
gunyara_kun = users.add("gunyara-kun", :name => "Tasuku SUENAGA")
|
58
|
-
|
59
|
-
expression = Groonga::Expression.new
|
60
|
-
variable = expression.define_variable
|
61
|
-
variable.value = morita
|
62
|
-
expression.append_object(variable)
|
63
|
-
expression.append_constant("name")
|
64
|
-
expression.append_operation(Groonga::Operation::GET_VALUE, 2)
|
65
|
-
expression.compile
|
66
|
-
expression.execute
|
67
|
-
assert_equal("mori daijiro", context.pop)
|
68
|
-
|
69
|
-
variable.value = gunyara_kun.id
|
70
|
-
expression.execute
|
71
|
-
assert_equal("Tasuku SUENAGA", context.pop)
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_inspect
|
75
|
-
expression = Groonga::Expression.new
|
76
|
-
expression.append_constant(1)
|
77
|
-
expression.append_constant(1)
|
78
|
-
expression.append_operation(Groonga::Operation::PLUS, 2)
|
79
|
-
expression.compile
|
80
|
-
|
81
|
-
assert_equal("#<Groonga::Expression noname(){1 1 PLUS}>", expression.inspect)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_snippet
|
85
|
-
users = Groonga::Array.create(:name => "Users")
|
86
|
-
name = users.define_column("name", "ShortText")
|
87
|
-
terms = Groonga::Hash.create(:name => "Terms",
|
88
|
-
:key_type => "ShortText",
|
89
|
-
:default_tokenizer => "TokenBigram")
|
90
|
-
users.define_index_column("user_name", users,
|
91
|
-
:source => "Users.name",
|
92
|
-
:with_position => true)
|
93
|
-
|
94
|
-
expression = Groonga::Expression.new
|
95
|
-
variable = expression.define_variable(:domain => users)
|
96
|
-
expression.append_object(variable)
|
97
|
-
expression.parse("ラングバ OR Ruby OR groonga", :default_column => name)
|
98
|
-
expression.compile
|
99
|
-
|
100
|
-
snippet = expression.snippet([["[[", "]]"], ["<", ">"]],
|
101
|
-
:width => 30)
|
102
|
-
assert_equal(["[[ラングバ]]プロジェクト",
|
103
|
-
"ン[[groonga]]の機能を<Ruby>か",
|
104
|
-
"。[[groonga]]の機能を<Ruby>ら"],
|
105
|
-
snippet.execute("ラングバプロジェクトはカラムストア機能も" +
|
106
|
-
"備える高速・高機能な全文検索エンジンgroonga" +
|
107
|
-
"の機能をRubyから利用するためのライブラリを" +
|
108
|
-
"提供するプロジェクトです。groongaの機能を" +
|
109
|
-
"Rubyらしい読み書きしやすい構文で利用できる" +
|
110
|
-
"ことが利点です。"))
|
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
|
133
|
-
end
|
@@ -1,65 +0,0 @@
|
|
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", "Int32",
|
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>, " +
|
41
|
-
"range: <Int32>, " +
|
42
|
-
"flags: <KEY_INT>" +
|
43
|
-
">",
|
44
|
-
@viewed.inspect)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_domain
|
48
|
-
assert_equal(@bookmarks, @viewed.domain)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_table
|
52
|
-
assert_equal(@bookmarks, @viewed.table)
|
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
|
65
|
-
end
|
data/test/test-gqtp.rb
DELETED
@@ -1,70 +0,0 @@
|
|
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
DELETED
@@ -1,312 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
# Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
|
3
|
-
#
|
4
|
-
# This library is free software; you can redistribute it and/or
|
5
|
-
# modify it under the terms of the GNU Lesser General Public
|
6
|
-
# License version 2.1 as published by the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This library is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
-
# Lesser General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public
|
14
|
-
# License along with this library; if not, write to the Free Software
|
15
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
16
|
-
|
17
|
-
class HashTest < Test::Unit::TestCase
|
18
|
-
include GroongaTestUtils
|
19
|
-
|
20
|
-
setup :setup_database
|
21
|
-
|
22
|
-
def test_delete
|
23
|
-
bookmarks_path = @tables_dir + "bookmarks"
|
24
|
-
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
25
|
-
:path => bookmarks_path.to_s)
|
26
|
-
|
27
|
-
groonga = bookmarks.add("groonga")
|
28
|
-
google = bookmarks.add("Google")
|
29
|
-
cutter = bookmarks.add("Cutter")
|
30
|
-
|
31
|
-
assert_equal(["groonga", "Google", "Cutter"],
|
32
|
-
bookmarks.collect {|bookmark| bookmark.key})
|
33
|
-
|
34
|
-
bookmarks.delete(google.id)
|
35
|
-
assert_equal(["groonga", "Cutter"],
|
36
|
-
bookmarks.collect {|bookmark| bookmark.key})
|
37
|
-
|
38
|
-
bookmarks.delete(cutter.key)
|
39
|
-
assert_equal(["groonga"],
|
40
|
-
bookmarks.collect {|bookmark| bookmark.key})
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_value
|
44
|
-
bookmarks_path = @tables_dir + "bookmarks"
|
45
|
-
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
46
|
-
:path => bookmarks_path.to_s,
|
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/"))
|
51
|
-
end
|
52
|
-
|
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
|
64
|
-
bookmarks_path = @tables_dir + "bookmarks"
|
65
|
-
bookmarks = Groonga::Hash.create(:name => "bookmarks",
|
66
|
-
:path => bookmarks_path.to_s,
|
67
|
-
:key_type => "ShortText")
|
68
|
-
bookmark = bookmarks.add("http://google.com/")
|
69
|
-
assert_equal(bookmark, bookmarks["http://google.com/"])
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
def test_inspect_anonymous
|
74
|
-
path = @tables_dir + "anoymous.groonga"
|
75
|
-
anonymous_table = Groonga::Hash.create(:path => path.to_s)
|
76
|
-
assert_equal("#<Groonga::Hash " +
|
77
|
-
"id: <#{anonymous_table.id}>, " +
|
78
|
-
"name: (anonymous), " +
|
79
|
-
"path: <#{path}>, " +
|
80
|
-
"domain: (nil), " +
|
81
|
-
"range: (nil), " +
|
82
|
-
"flags: <>, " +
|
83
|
-
"encoding: <#{encoding.inspect}>, " +
|
84
|
-
"size: <0>>",
|
85
|
-
anonymous_table.inspect)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_inspect_anonymous_temporary
|
89
|
-
anonymous_table = Groonga::Hash.create
|
90
|
-
assert_equal("#<Groonga::Hash " +
|
91
|
-
"id: <#{anonymous_table.id}>, " +
|
92
|
-
"name: (anonymous), " +
|
93
|
-
"path: (temporary), " +
|
94
|
-
"domain: (nil), " +
|
95
|
-
"range: (nil), " +
|
96
|
-
"flags: <>, " +
|
97
|
-
"encoding: <#{encoding.inspect}>, " +
|
98
|
-
"size: <0>>",
|
99
|
-
anonymous_table.inspect)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_inspect_named
|
103
|
-
path = @tables_dir + "named.groonga"
|
104
|
-
named_table = Groonga::Hash.create(:name => "Users", :path => path.to_s)
|
105
|
-
assert_equal("#<Groonga::Hash " +
|
106
|
-
"id: <#{named_table.id}>, " +
|
107
|
-
"name: <Users>, " +
|
108
|
-
"path: <#{path}>, " +
|
109
|
-
"domain: (nil), " +
|
110
|
-
"range: (nil), " +
|
111
|
-
"flags: <>, " +
|
112
|
-
"encoding: <#{encoding.inspect}>, " +
|
113
|
-
"size: <0>>",
|
114
|
-
named_table.inspect)
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_inspect_temporary
|
118
|
-
named_table = Groonga::Hash.create
|
119
|
-
assert_equal("#<Groonga::Hash " +
|
120
|
-
"id: <#{named_table.id}>, " +
|
121
|
-
"name: (anonymous), " +
|
122
|
-
"path: (temporary), " +
|
123
|
-
"domain: (nil), " +
|
124
|
-
"range: (nil), " +
|
125
|
-
"flags: <>, " +
|
126
|
-
"encoding: <#{encoding.inspect}>, " +
|
127
|
-
"size: <0>>",
|
128
|
-
named_table.inspect)
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_encoding
|
132
|
-
assert_equal(Groonga::Encoding.default,
|
133
|
-
Groonga::Hash.create.encoding)
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_tokenizer
|
137
|
-
hash = Groonga::Hash.create
|
138
|
-
assert_nil(hash.default_tokenizer)
|
139
|
-
hash.default_tokenizer = "TokenBigram"
|
140
|
-
assert_equal(Groonga::Context.default["TokenBigram"],
|
141
|
-
hash.default_tokenizer)
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_search
|
145
|
-
users = Groonga::Array.create(:name => "Users")
|
146
|
-
user_name = users.define_column("name", "ShortText")
|
147
|
-
|
148
|
-
bookmarks = Groonga::Hash.create(:name => "Bookmarks",
|
149
|
-
:key_type => "ShortText")
|
150
|
-
bookmark_user_id = bookmarks.define_column("user_id", users)
|
151
|
-
|
152
|
-
daijiro = users.add
|
153
|
-
daijiro["name"] = "daijiro"
|
154
|
-
gunyarakun = users.add
|
155
|
-
gunyarakun["name"] = "gunyarakun"
|
156
|
-
|
157
|
-
groonga = bookmarks.add("http://groonga.org/")
|
158
|
-
groonga["user_id"] = daijiro
|
159
|
-
|
160
|
-
records = bookmarks.search("http://groonga.org/")
|
161
|
-
assert_equal(["daijiro"],
|
162
|
-
records.records.collect {|record| record[".user_id.name"]})
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_add
|
166
|
-
users = Groonga::Hash.create(:name => "Users")
|
167
|
-
users.define_column("address", "Text")
|
168
|
-
me = users.add("me", :address => "me@example.com")
|
169
|
-
assert_equal("me@example.com", me[:address])
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_default_tokenizer_on_create
|
173
|
-
terms = Groonga::Hash.create(:name => "Terms",
|
174
|
-
:default_tokenizer => "TokenTrigram")
|
175
|
-
assert_equal(context[Groonga::Type::TRIGRAM],
|
176
|
-
terms.default_tokenizer)
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_duplicated_name
|
180
|
-
Groonga::Hash.create(:name => "Users")
|
181
|
-
assert_raise(Groonga::InvalidArgument) do
|
182
|
-
Groonga::Hash.create(:name => "Users")
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_define_index_column_implicit_with_position
|
187
|
-
bookmarks = Groonga::Hash.create(:name => "Bookmarks")
|
188
|
-
bookmarks.define_column("comment", "Text")
|
189
|
-
terms = Groonga::Hash.create(:name => "Terms",
|
190
|
-
:default_tokenizer => "TokenBigram")
|
191
|
-
index = terms.define_index_column("comment", bookmarks,
|
192
|
-
:source => "Bookmarks.comment")
|
193
|
-
groonga = bookmarks.add("groonga", :comment => "search engine by Brazil")
|
194
|
-
google = bookmarks.add("google", :comment => "search engine by Google")
|
195
|
-
ruby = bookmarks.add("ruby", :comment => "programing language")
|
196
|
-
|
197
|
-
assert_equal(["groonga", "google"],
|
198
|
-
index.search("engine").collect {|record| record.key.key})
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_open_same_name
|
202
|
-
users_created = Groonga::Hash.create(:name => "Users")
|
203
|
-
users_opened = Groonga::Hash.open(:name => "Users")
|
204
|
-
users_opened.add("morita")
|
205
|
-
assert_equal(1, users_created.size)
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_has_key?
|
209
|
-
users = Groonga::Hash.create(:name => "Users")
|
210
|
-
assert_false(users.has_key?("morita"))
|
211
|
-
users.add("morita")
|
212
|
-
assert_true(users.has_key?("morita"))
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_big_key
|
216
|
-
hash = Groonga::Hash.create(:key_type => "UInt64")
|
217
|
-
assert_nothing_raised do
|
218
|
-
hash.add(1 << 63)
|
219
|
-
end
|
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
|
312
|
-
end
|