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-type.rb
DELETED
@@ -1,61 +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 TypeTest < Test::Unit::TestCase
|
17
|
-
include GroongaTestUtils
|
18
|
-
|
19
|
-
setup :setup_database
|
20
|
-
|
21
|
-
def test_new
|
22
|
-
type = Groonga::Type.new("user-id", :type => :integer)
|
23
|
-
assert_equal("user-id", type.name)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_builtins
|
27
|
-
assert_equal_type("Object", Groonga::Type::OBJECT) # FIXME!!!
|
28
|
-
assert_equal_type("Bool", Groonga::Type::BOOLEAN)
|
29
|
-
assert_equal_type("Bool", Groonga::Type::BOOL)
|
30
|
-
assert_equal_type("Int8", Groonga::Type::INT8)
|
31
|
-
assert_equal_type("UInt8", Groonga::Type::UINT8)
|
32
|
-
assert_equal_type("Int16", Groonga::Type::INT16)
|
33
|
-
assert_equal_type("UInt16", Groonga::Type::UINT16)
|
34
|
-
assert_equal_type("Int32", Groonga::Type::INT32)
|
35
|
-
assert_equal_type("UInt32", Groonga::Type::UINT32)
|
36
|
-
assert_equal_type("Int64", Groonga::Type::INT64)
|
37
|
-
assert_equal_type("UInt64", Groonga::Type::UINT64)
|
38
|
-
assert_equal_type("Float", Groonga::Type::FLOAT)
|
39
|
-
assert_equal_type("Time", Groonga::Type::TIME)
|
40
|
-
assert_equal_type("ShortText", Groonga::Type::SHORT_TEXT)
|
41
|
-
assert_equal_type("Text", Groonga::Type::TEXT)
|
42
|
-
assert_equal_type("LongText", Groonga::Type::LONG_TEXT)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_inspect
|
46
|
-
assert_equal("#<Groonga::Type id: <#{Groonga::Type::LONG_TEXT}>, " +
|
47
|
-
"name: <LongText>, " +
|
48
|
-
"path: (temporary), " +
|
49
|
-
"domain: (nil), " +
|
50
|
-
"range: <2147483648>, " +
|
51
|
-
"flags: <>>",
|
52
|
-
context["<longtext>"].inspect)
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
def assert_equal_type(expected_name, id)
|
57
|
-
type = Groonga::Context.default[id]
|
58
|
-
assert_equal(expected_name,
|
59
|
-
type ? type.name : type)
|
60
|
-
end
|
61
|
-
end
|
@@ -1,98 +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 VariableSizeColumnTest < Test::Unit::TestCase
|
17
|
-
include GroongaTestUtils
|
18
|
-
|
19
|
-
def setup
|
20
|
-
setup_database
|
21
|
-
|
22
|
-
setup_users_table
|
23
|
-
setup_users
|
24
|
-
end
|
25
|
-
|
26
|
-
def setup_users_table
|
27
|
-
@users_path = @tables_dir + "users"
|
28
|
-
@users = Groonga::Array.create(:name => "Users",
|
29
|
-
:path => @users_path.to_s)
|
30
|
-
|
31
|
-
@users_name_column_path = @columns_dir + "name"
|
32
|
-
@name = @users.define_column("name", "ShortText",
|
33
|
-
:path => @users_name_column_path.to_s)
|
34
|
-
|
35
|
-
@users_friends_column_path = @columns_dir + "friends"
|
36
|
-
@friends = @users.define_column("friends", @users,
|
37
|
-
:type => :vector,
|
38
|
-
:path => @users_friends_column_path.to_s)
|
39
|
-
|
40
|
-
@users_nick_names_column_path = @columns_dir + "nick_names"
|
41
|
-
@nick_names =
|
42
|
-
@users.define_column("nick_names", "ShortText",
|
43
|
-
:type => :vector,
|
44
|
-
:path => @users_nick_names_column_path.to_s)
|
45
|
-
end
|
46
|
-
|
47
|
-
def setup_users
|
48
|
-
@morita = @users.add(:name => "mori daijiro")
|
49
|
-
@gunyara_kun = @users.add(:name => "Tasuku SUENAGA")
|
50
|
-
@yu = @users.add(:name => "Yutaro Shimamura")
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_inspect
|
54
|
-
assert_equal("#<Groonga::VariableSizeColumn " +
|
55
|
-
"id: <#{@name.id}>, " +
|
56
|
-
"name: <Users.name>, " +
|
57
|
-
"path: <#{@users_name_column_path}>, " +
|
58
|
-
"domain: <Users>, " +
|
59
|
-
"range: <ShortText>, " +
|
60
|
-
"flags: <>" +
|
61
|
-
">",
|
62
|
-
@name.inspect)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_domain
|
66
|
-
assert_equal(@users, @name.domain)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_table
|
70
|
-
assert_equal(@users, @name.table)
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_vector_append
|
74
|
-
assert_equal([], @morita["friends"])
|
75
|
-
@morita.append("friends", @yu)
|
76
|
-
assert_equal([@yu], @morita["friends"])
|
77
|
-
@morita.append("friends", @gunyara_kun)
|
78
|
-
assert_equal([@yu, @gunyara_kun], @morita["friends"])
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_vector_prepend
|
82
|
-
assert_equal([], @morita["friends"])
|
83
|
-
@morita.prepend("friends", @yu)
|
84
|
-
assert_equal([@yu], @morita["friends"])
|
85
|
-
@morita.prepend("friends", @gunyara_kun)
|
86
|
-
assert_equal([@gunyara_kun, @yu], @morita["friends"])
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_string_vector
|
90
|
-
omit("append/prepend for non table domain column " +
|
91
|
-
"isn't supported by groonga.")
|
92
|
-
assert_equal([], @morita["nick_names"])
|
93
|
-
@morita.append("nick_names", "morita")
|
94
|
-
assert_equal(["morita"], @morita["nick_names"])
|
95
|
-
@morita.prepend("nick_names", "moritapo")
|
96
|
-
assert_equal(["moritapo", "morita"], @morita["nick_names"])
|
97
|
-
end
|
98
|
-
end
|
data/test/test-variable.rb
DELETED
@@ -1,28 +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 VariableTest < Test::Unit::TestCase
|
17
|
-
include GroongaTestUtils
|
18
|
-
|
19
|
-
setup :setup_database
|
20
|
-
|
21
|
-
def test_value
|
22
|
-
expression = Groonga::Expression.new
|
23
|
-
variable = expression.define_variable
|
24
|
-
assert_nil(variable.value)
|
25
|
-
variable.value = "morita"
|
26
|
-
assert_equal("morita", variable.value)
|
27
|
-
end
|
28
|
-
end
|
data/test/test-vector-column.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# Copyright (C) 2010 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 VectorColumnTest < Test::Unit::TestCase
|
17
|
-
include GroongaTestUtils
|
18
|
-
|
19
|
-
def setup
|
20
|
-
setup_database
|
21
|
-
setup_tables
|
22
|
-
end
|
23
|
-
|
24
|
-
def setup_tables
|
25
|
-
Groonga::Schema.define do |schema|
|
26
|
-
schema.create_table("Users",
|
27
|
-
:type => :hash,
|
28
|
-
:key_type => "UInt32") do |table|
|
29
|
-
end
|
30
|
-
|
31
|
-
schema.create_table("Communities",
|
32
|
-
:type => :hash,
|
33
|
-
:key_type => "ShortText") do |table|
|
34
|
-
table.reference("users", "Users", :type => :vector)
|
35
|
-
end
|
36
|
-
|
37
|
-
schema.create_table("Areas",
|
38
|
-
:type => :hash,
|
39
|
-
:key_type => "ShortText") do |table|
|
40
|
-
table.reference("communities", "Communities", :type => :vector)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
@users = Groonga::Context.default["Users"]
|
45
|
-
@communities = Groonga::Context.default["Communities"]
|
46
|
-
@areas = Groonga::Context.default["Areas"]
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_set_records
|
50
|
-
groonga = @communities.add("groonga")
|
51
|
-
morita = @users.add(29)
|
52
|
-
groonga["users"] = [morita]
|
53
|
-
|
54
|
-
assert_equal([29], @users.collect {|record| record.key})
|
55
|
-
assert_equal([29], groonga["users"].collect {|record| record.key})
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_set_nonexistent_keys
|
59
|
-
shinjuku = @areas.add("Shinjuku")
|
60
|
-
shinjuku["communities"] = ["groonga", "Senna"]
|
61
|
-
|
62
|
-
assert_equal(["groonga", "Senna"],
|
63
|
-
@communities.collect {|record| record.key})
|
64
|
-
assert_equal(["groonga", "Senna"],
|
65
|
-
shinjuku["communities"].collect {|record| record.key})
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_set_nil
|
69
|
-
groonga = @communities.add("groonga")
|
70
|
-
assert_equal([], groonga["users"])
|
71
|
-
groonga["users"] = nil
|
72
|
-
assert_equal([], groonga["users"]) # should return nil?
|
73
|
-
# Can groonga tell us
|
74
|
-
# that the value is empty?
|
75
|
-
end
|
76
|
-
end
|
data/test/test-version.rb
DELETED
@@ -1,31 +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 VersionTest < Test::Unit::TestCase
|
17
|
-
def test_build_version
|
18
|
-
assert_match(/\A\d+\.\d+\.\d+\z/, Groonga.build_version)
|
19
|
-
assert_match(Groonga.build_version, Groonga::BUILD_VERSION.join("."))
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_version
|
23
|
-
assert_match(/\A\d+\.\d+\.\d+\z/, Groonga.version)
|
24
|
-
assert_match(Groonga.version, Groonga::VERSION.join("."))
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_bindings_version
|
28
|
-
assert_match(/\A\d+\.\d+\.\d+\z/, Groonga.bindings_version)
|
29
|
-
assert_match(Groonga.bindings_version, Groonga::BINDINGS_VERSION.join("."))
|
30
|
-
end
|
31
|
-
end
|
data/text/TUTORIAL.ja.rdoc
DELETED
@@ -1,392 +0,0 @@
|
|
1
|
-
= チュートリアル
|
2
|
-
|
3
|
-
このページでは簡単なアプリケーションの作成を通して
|
4
|
-
Ruby/groongaの操作方法を紹介します。
|
5
|
-
|
6
|
-
== インストール
|
7
|
-
|
8
|
-
Ruby/groongaはRubyGemsでインストールできます。
|
9
|
-
|
10
|
-
% sudo gem install groonga
|
11
|
-
|
12
|
-
== データベースの作成
|
13
|
-
|
14
|
-
簡単なブックマークアプリケーション用のデータベースを作ってみ
|
15
|
-
ます。以下のようにgroongaライブラリを読み込んでirbを起動しま
|
16
|
-
す。
|
17
|
-
|
18
|
-
% irb --simple-prompt -rubygems -rgroonga
|
19
|
-
>>
|
20
|
-
|
21
|
-
まず、エンコーディングを設定します。ここではUTF-8を利用します。
|
22
|
-
|
23
|
-
>> $KCODE = "UTF-8"
|
24
|
-
=> "UTF-8"
|
25
|
-
>> Groonga::Context.default_options = {:encoding => :utf8}
|
26
|
-
=> {:encoding=>:utf8}
|
27
|
-
|
28
|
-
それでは、ファイルを指定してデータベースを作成します。
|
29
|
-
|
30
|
-
>> Groonga::Database.create(:path => "/tmp/bookmark.db")
|
31
|
-
=> #<Groonga::Database ...>
|
32
|
-
|
33
|
-
ここで作成したデータベースは、これ以降、暗黙のうちに利用され
|
34
|
-
ます。最初にデータベースを作成したら特に意識する必要はありま
|
35
|
-
せん。
|
36
|
-
|
37
|
-
== テーブルの定義
|
38
|
-
|
39
|
-
groongaには以下の3種類のテーブルがあります。
|
40
|
-
|
41
|
-
[Groonga::Hash]
|
42
|
-
ハッシュテーブル。主キーでレコードを管理します。キーと完全
|
43
|
-
一致するレコードを非常に高速に検索することができます。
|
44
|
-
[Groonga::PatriciaTrie]
|
45
|
-
パトリシアトライ。ハッシュテーブルに比べて完全一致検索の速
|
46
|
-
度がやや遅いですが、前方一致検索・共通接頭辞探索などの検索
|
47
|
-
が行えます。またカーソルを用いてキーの昇降順にレコードを取
|
48
|
-
り出すことができます。
|
49
|
-
[Groonga::Array]
|
50
|
-
配列。主キーの存在しないテーブルです。レコードはIDによって
|
51
|
-
識別します。
|
52
|
-
|
53
|
-
ここではハッシュテーブルを利用して、<tt>Items</tt>という名前のテー
|
54
|
-
ブルを作成します。キーは文字列とします。
|
55
|
-
|
56
|
-
>> items = Groonga::Hash.create(:name => "Items", :key_type => "ShortText")
|
57
|
-
=> #<Groonga::Hash ...>
|
58
|
-
|
59
|
-
|
60
|
-
これで<tt>Items</tt>という名前のテーブルが作成できました。
|
61
|
-
|
62
|
-
テーブルはRubyのHashのように扱えます。
|
63
|
-
|
64
|
-
例えば、以下のように+size+でテーブルに登録されているレコード
|
65
|
-
の件数を取得できます。
|
66
|
-
|
67
|
-
>> items.size
|
68
|
-
0
|
69
|
-
|
70
|
-
== レコードを追加する
|
71
|
-
|
72
|
-
<tt>Items</tt>テーブルにレコードを追加します。
|
73
|
-
|
74
|
-
>> items.add("http://ja.wikipedia.org/wiki/Ruby")
|
75
|
-
=> #<Groonga::Record ...>
|
76
|
-
>> items.add("http://www.ruby-lang.org/")
|
77
|
-
=> #<Groonga::Record ...>
|
78
|
-
|
79
|
-
件数を確認すると確かに2件増えています。
|
80
|
-
|
81
|
-
>> items.size
|
82
|
-
=> 2
|
83
|
-
|
84
|
-
主キーを指定してレコードを取り出す時には以下のようにします。
|
85
|
-
|
86
|
-
>> items.find("http://ja.wikipedia.org/wiki/Ruby")
|
87
|
-
=> #<Groonga::Record ...>
|
88
|
-
|
89
|
-
== 全文検索を行う
|
90
|
-
|
91
|
-
各itemのタイトル文字列を登録して、全文検索できるようにしてみ
|
92
|
-
ましょう。
|
93
|
-
|
94
|
-
まず<tt>Items</tt>テーブルに+title+という名前のカラムを追加します。
|
95
|
-
|
96
|
-
>> title_column = items.define_column("title", "Text")
|
97
|
-
=> #<Groonga::VarSizeColumn ...>
|
98
|
-
|
99
|
-
2番目の引数は、追加するカラムのデータ型を示しています。
|
100
|
-
<tt><int></tt>、<tt>Text</tt>、<tt><longtext></tt>等の型が基本型として用意されて
|
101
|
-
います。
|
102
|
-
|
103
|
-
全文検索するためには、文字列を分解して得られる各単語を格納す
|
104
|
-
るためのテーブルを別途しなければなりません。ここではTermsと
|
105
|
-
いう名前でテーブルを定義します。
|
106
|
-
|
107
|
-
>> terms = Groonga::Hash.create(:name => "Terms",
|
108
|
-
:key_type => "ShortText",
|
109
|
-
:default_tokenizer => "TokenBigram")
|
110
|
-
=> #<Groonga::Hash ...>
|
111
|
-
|
112
|
-
ここでは、トークナイザとして<tt>:default_tokenzier =>
|
113
|
-
"TokenBigram"</tt> を指定しています。トークナイザとは文字
|
114
|
-
列を単語に分解するオブジェクトのことです。デフォルトではトー
|
115
|
-
クナイザは指定されていません。全文検索を利用するためにはトー
|
116
|
-
クナイザを指定する必要があるので、ここではN-gramの一種である
|
117
|
-
バイグラムを指定しています。
|
118
|
-
|
119
|
-
N-gramを利用した全文検索では、分解したN文字とその出現位置を利
|
120
|
-
用して全文検索を行います。N-gramのNは文字列を何文字毎に分解す
|
121
|
-
るかの文字数になります。groongaは1文字で分解するユニグラム、
|
122
|
-
2文字のバイグラム、3文字のトリグラムをサポートしています。
|
123
|
-
|
124
|
-
単語格納用テーブルの準備ができたので、<tt>Items</tt>テーブ
|
125
|
-
ルの+title+カラムに対するインデックスを定義します。
|
126
|
-
|
127
|
-
>> title_index_column = terms.define_index_column("item_title", items,
|
128
|
-
:source => "Items.title")
|
129
|
-
=> #<Groonga::IndexColumn ...>
|
130
|
-
|
131
|
-
少し違和感を感じるかも知れませんが、<tt>Items</tt>テーブル
|
132
|
-
のカラムに対するインデックスは、<tt>Terms</tt>テーブルのカ
|
133
|
-
ラムとして定義します。
|
134
|
-
|
135
|
-
<tt>Items</tt>にレコードが登録されると、その中に含まれる単
|
136
|
-
語に該当するレコードが<tt>Terms</tt>に自動的に追加されるよ
|
137
|
-
うになります。
|
138
|
-
|
139
|
-
<tt>Terms</tt>は、文書に含まれる語彙に相当する、やや特殊な
|
140
|
-
テーブルだと言えます。しかし、他のテーブルと同様に語彙テーブ
|
141
|
-
ルには自由にカラムを追加し、単語毎の様々な属性を管理すること
|
142
|
-
ができます。これはある種の検索処理を行う際には非常に便利に機
|
143
|
-
能します。
|
144
|
-
|
145
|
-
これでテーブルの定義は完了です。
|
146
|
-
|
147
|
-
先ほど登録した各レコードの+title+カラムに値をセットします。
|
148
|
-
|
149
|
-
>> items.find("http://ja.wikipedia.org/wiki/Ruby")["title"] = "Ruby"
|
150
|
-
=> "Ruby"
|
151
|
-
>> items.find("http://www.ruby-lang.org/")["title"] = "オブジェクトスクリプト言語Ruby"
|
152
|
-
"オブジェクトスクリプト言語Ruby"
|
153
|
-
|
154
|
-
以下のようにして検索することができます。
|
155
|
-
|
156
|
-
>> title_index_column.search("Ruby").collect {|record| record.key.key}
|
157
|
-
["http://ja.wikipedia.org/wiki/Ruby", "http://www.ruby-lang.org/"]
|
158
|
-
|
159
|
-
検索結果はGroonga::Hashで返されます。ハッシュのキーに見つかっ
|
160
|
-
た<tt>Items</tt>のレコードが入っています。上の例では
|
161
|
-
+record.key+で<tt>Items</tt>のレコードを取得して、さらにそ
|
162
|
-
のキーを指定して(+record.key.key+)で<tt>Items</tt>のキー
|
163
|
-
を返しています。
|
164
|
-
|
165
|
-
|
166
|
-
== マルチユーザ向けのブックマークアプリケーション
|
167
|
-
|
168
|
-
ここまでで作った単機能のアプリケーションをもう少し拡張して、
|
169
|
-
複数のユーザが、それぞれにコメントを記入できるブックマークア
|
170
|
-
プリケーションにしてみましょう。
|
171
|
-
|
172
|
-
まず、ユーザ情報とコメント情報を格納するテーブルを追加して、
|
173
|
-
下図のようなテーブル構成にします。
|
174
|
-
|
175
|
-
http://qwik.jp/senna/senna2.files/rect4605.png
|
176
|
-
|
177
|
-
まず、<tt>Users</tt>テーブルを追加します。
|
178
|
-
|
179
|
-
>> users = Groonga::Hash.create(:name => "Users",
|
180
|
-
:key_type => "ShortText")
|
181
|
-
=> #<Groonga::Hash ...>
|
182
|
-
>> users.define_column("name", "Text")
|
183
|
-
=> #<Groonga::VarSizeColumn ...>
|
184
|
-
|
185
|
-
|
186
|
-
次に、<tt>Comments</tt>テーブルを追加します。
|
187
|
-
|
188
|
-
>> comments = Groonga::Array.create(:name => "Comments")
|
189
|
-
=> #<Groonga::Array ...>
|
190
|
-
>> comments.define_column("item", items)
|
191
|
-
=> #<Groonga::FixSizeColumn ..>
|
192
|
-
>> comments.define_column("author", users)
|
193
|
-
=> #<Groonga::FixSizeColumn ..>
|
194
|
-
>> comments.define_column("content", "Text")
|
195
|
-
=> #<Groonga::VarSizeColumn ..>
|
196
|
-
>> comments.define_column("issued", "Time")
|
197
|
-
=> #<Groonga::FixSizeColumn ..>
|
198
|
-
|
199
|
-
<tt>Comments</tt>テーブルの+content+カラムを全文検索できる
|
200
|
-
ようにインデックスを定義します。
|
201
|
-
|
202
|
-
>> terms.define_index_column("comment_content", comments,
|
203
|
-
:source => "Comments.content")
|
204
|
-
=> #<Groonga::IndexColumn ...>
|
205
|
-
|
206
|
-
これでテーブルが定義できました。
|
207
|
-
|
208
|
-
続いてユーザを何人か追加します。
|
209
|
-
|
210
|
-
>> users.add("moritan", :name => "モリタン")
|
211
|
-
=> #<Groonga::Record ...>
|
212
|
-
>> users.add("taporobo", :name => "タポロボ")
|
213
|
-
=> #<Groonga::Record ...>
|
214
|
-
|
215
|
-
次に、実際にユーザがブックマークを貼る時の処理を実行してみま
|
216
|
-
しょう。
|
217
|
-
|
218
|
-
ユーザ+moritan+が、はてなダイアリーのとあるページをブックマーク
|
219
|
-
したと想定します。
|
220
|
-
|
221
|
-
まず対象のページが<tt>Items</tt>テーブルに登録済かどうか調
|
222
|
-
べます。
|
223
|
-
|
224
|
-
>> items.find("http://d.hatena.ne.jp/brazil/20050829/1125321936")
|
225
|
-
=> nil
|
226
|
-
|
227
|
-
未登録なのでまず当該ページを<tt>Items</tt>に登録します。
|
228
|
-
|
229
|
-
>> items.add("http://d.hatena.ne.jp/brazil/20050829/1125321936",
|
230
|
-
:title => "[翻訳]JavaScript: 世界で最も誤解されたプログラミング言語")
|
231
|
-
=> #<Groonga::Record ...>
|
232
|
-
|
233
|
-
次に、登録したitemを+item+カラムの値に指定して
|
234
|
-
<tt>Comments</tt>にレコードを登録します。
|
235
|
-
|
236
|
-
>> comments.add(:item => "http://d.hatena.ne.jp/brazil/20050829/1125321936",
|
237
|
-
:author => "moritan",
|
238
|
-
:content => "JavaScript LISP",
|
239
|
-
:issued => 1187430026)
|
240
|
-
=> #<Groonga::Record ...>
|
241
|
-
|
242
|
-
== メソッド化
|
243
|
-
|
244
|
-
上記の一連の手続きをメソッドにまとめてみます。
|
245
|
-
|
246
|
-
>> @items = items
|
247
|
-
>> @comments = comments
|
248
|
-
>> def add_bookmark(url, title, author, content, issued)
|
249
|
-
>> item = @items.find(url) || @items.add(url, :title => title)
|
250
|
-
>> @comments.add(:item => item,
|
251
|
-
>> :author => author,
|
252
|
-
>> :content => content,
|
253
|
-
>> :issued => issued)
|
254
|
-
>> end
|
255
|
-
|
256
|
-
+itmes+と+comments+をインスタンス変数に代入しているのはメソッ
|
257
|
-
ド内からでも見えるようにするためです。
|
258
|
-
|
259
|
-
+add_bookmark+は以下のような手順を実行しています。
|
260
|
-
|
261
|
-
* <tt>Items</tt>テーブルに該当ページのレコードがあるかどうか調べる。
|
262
|
-
* レコードがなければ追加する。
|
263
|
-
* <tt>Comments</tt>テーブルにレコードを登録する。
|
264
|
-
|
265
|
-
作成したメソッドを呼び出していくつかブックマークを登録してみ
|
266
|
-
ましょう。
|
267
|
-
|
268
|
-
>> add_bookmark("http://practical-scheme.net/docs/cont-j.html",
|
269
|
-
"なんでも継続", "moritan", "継続 LISP Scheme", 1187568692)
|
270
|
-
=> #<Groonga::Record ...>
|
271
|
-
>> add_bookmark("http://d.hatena.ne.jp/higepon/20070815/1187192864",
|
272
|
-
"末尾再帰", "taporobo", "末尾再帰 Scheme LISP", 1187568793)
|
273
|
-
=> #<Groonga::Record ...>
|
274
|
-
>> add_bookmark("http://practical-scheme.net/docs/cont-j.html",
|
275
|
-
"なんでも継続", "taporobo", "トランポリン LISP continuation",
|
276
|
-
1187568692)
|
277
|
-
=> #<Groonga::Record ...>
|
278
|
-
|
279
|
-
== 全文検索その2
|
280
|
-
|
281
|
-
登録したレコードに対して全文検索を実行してみます。
|
282
|
-
|
283
|
-
>> records = comments.select do |record|
|
284
|
-
>> record["content"] =~ "LISP"
|
285
|
-
>> end
|
286
|
-
>> records.each do |record|
|
287
|
-
>> record = record.key
|
288
|
-
>> p [record.id,
|
289
|
-
>> record[".issued"],
|
290
|
-
>> record[".item.title"],
|
291
|
-
>> record[".author.name"],
|
292
|
-
>> record[".content"]]
|
293
|
-
>> end
|
294
|
-
[1, Sat Aug 18 18:40:26 +0900 2007, "[翻訳]JavaScript: 世界で最も誤解されたプログラミング言語", "モリタン", "JavaScript LISP"]
|
295
|
-
[2, Mon Aug 20 09:11:32 +0900 2007, "なんでも継続", "モリタン", "継続 LISP Scheme"]
|
296
|
-
[3, Mon Aug 20 09:13:13 +0900 2007, "末尾再帰", "タポロボ", "末尾再帰 Scheme LISP"]
|
297
|
-
[4, Mon Aug 20 09:11:32 +0900 2007, "なんでも継続", "タポロボ", "トランポリン LISP continuation"]
|
298
|
-
|
299
|
-
カラムへのアクセスは、カラム名を+.+で繋いで複合データ型の要素
|
300
|
-
を再帰的に辿ることができます。(同様の出力を普通のRDBで実現す
|
301
|
-
るためには、<tt>Items</tt>テーブル、<tt>Comments</tt>テー
|
302
|
-
ブル、<tt>Users</tt>テーブルのJOIN操作が必要になります。)
|
303
|
-
|
304
|
-
上の式の中で、肝心の検索処理は、第一引数の式を評価する時点で
|
305
|
-
完了していて、レコードセットオブジェクトとしてメモリに蓄積さ
|
306
|
-
れています。
|
307
|
-
|
308
|
-
>> records
|
309
|
-
#<Groonga::Hash ..., size: <4>>
|
310
|
-
|
311
|
-
レコードセットは、出力する前に様々に加工することができます。
|
312
|
-
|
313
|
-
以下は、日付で降順にソートしてから出力した例です。
|
314
|
-
|
315
|
-
>> records.sort([{:key => ".issued", :order => "descending"}]).each do |record|
|
316
|
-
>> record = record.key
|
317
|
-
>> p [record.id,
|
318
|
-
>> record[".issued"],
|
319
|
-
>> record[".item.title"],
|
320
|
-
>> record[".author.name"],
|
321
|
-
>> record[".content"]]
|
322
|
-
>> end
|
323
|
-
[3, Mon Aug 20 09:13:13 +0900 2007, "末尾再帰", "タポロボ", "末尾再帰 Scheme LISP"]
|
324
|
-
[2, Mon Aug 20 09:11:32 +0900 2007, "なんでも継続", "モリタン", "継続 LISP Scheme"]
|
325
|
-
[4, Mon Aug 20 09:11:32 +0900 2007, "なんでも継続", "タポロボ", "トランポリン LISP continuation"]
|
326
|
-
[1, Sat Aug 18 18:40:26 +0900 2007, "[翻訳]JavaScript: 世界で最も誤解されたプログラミング言語", "モリタン", "JavaScript LISP"]
|
327
|
-
|
328
|
-
同じitemが何度も出てくると検索結果が見にくいので、item毎にグ
|
329
|
-
ループ化してみます。
|
330
|
-
|
331
|
-
>> records.group([".item"]).each do |record|
|
332
|
-
>> item = record.key
|
333
|
-
>> p [record.n_sub_records,
|
334
|
-
>> item.key,
|
335
|
-
>> item[".title"]]
|
336
|
-
>> end
|
337
|
-
[1, "http://d.hatena.ne.jp/brazil/20050829/1125321936", "[翻訳]JavaScript: 世界で最も誤解されたプログラミング言語"]
|
338
|
-
[2, "http://practical-scheme.net/docs/cont-j.html", "なんでも継続"]
|
339
|
-
[1, "http://d.hatena.ne.jp/higepon/20070815/1187192864", "末尾再帰"]
|
340
|
-
|
341
|
-
+n_sub_records+というのはグループ化した単位に含まれるレコード
|
342
|
-
の件数を示します。SQLで言えば、GROUP BY句を含むクエリのcount
|
343
|
-
関数のような働きです。
|
344
|
-
|
345
|
-
== 少し複雑な検索
|
346
|
-
|
347
|
-
↓はまだ動かない!!!
|
348
|
-
|
349
|
-
さらに実用的な検索について考えてみましょう。
|
350
|
-
|
351
|
-
ブックマークが大量に蓄積されるに従って、より的確に適合度を算
|
352
|
-
出する必要性に迫られます。
|
353
|
-
|
354
|
-
今のところ検索対象として利用できるのは<tt>Items.title</tt>
|
355
|
-
と<tt>Comments.content</tt>ですが、<tt>Items.title</tt>は
|
356
|
-
元ページから得られるやや信頼できる情報なのに対して、
|
357
|
-
<tt>Comments.content</tt>はブックマークユーザが任意に設定で
|
358
|
-
きる情報で、やや信憑性に乏しいと言えます。しかし、再現率を確
|
359
|
-
保するためにはユーザのコメントも是非対象に含めたいところです。
|
360
|
-
|
361
|
-
そこで、以下のようなポリシーで検索を行うことにします。
|
362
|
-
|
363
|
-
* <tt>Items.title</tt>か<tt>Comments.content</tt>のいずれ
|
364
|
-
かにマッチするitemを検索する。
|
365
|
-
* ただし、<tt>Items.title</tt>にマッチしたレコードはスコア
|
366
|
-
を10倍重み付けする。
|
367
|
-
* 同一のitemに対して、キーワードにマッチする<tt>comment</tt>
|
368
|
-
が複数存在した場合は、それぞれの<tt>comment</tt>のスコアの
|
369
|
-
和を、該当するitemのスコアとする。
|
370
|
-
|
371
|
-
以下のようにして、commentとitemとそれぞれに対する検索結果を求
|
372
|
-
めます。
|
373
|
-
|
374
|
-
>> ruby_comments = @comments.select {|record| record["content"] =~ "Ruby"}
|
375
|
-
#<Groonga::Hash ..., size: <2>>
|
376
|
-
>> ruby_items = @items.select("*W1:50 title:@Ruby")
|
377
|
-
#<Groonga::Hash ..., size: <2>>
|
378
|
-
|
379
|
-
_ruby_comments_の結果をitem毎にグループ化し、_ruby_items_と
|
380
|
-
unionして出力します。
|
381
|
-
|
382
|
-
>> ruby_items = ruby_comments.group([".item"]).union!(ruby_items)
|
383
|
-
#<Groonga::Hash ..., size: <4>>
|
384
|
-
>> ruby_items.sort([{:key => "._score", :order => "descendant"}]).each do |record|
|
385
|
-
>> p [record["._score"], record[".title"]]
|
386
|
-
>> end
|
387
|
-
[1, "るびま"]
|
388
|
-
[1, "オブジェクトスクリプト言語Ruby"]
|
389
|
-
[1, "Ruby"]
|
390
|
-
[1, "ラングバ"]
|
391
|
-
|
392
|
-
これで目的の結果が得られました。(FIXME: 得られていない!)
|