rroonga 0.9.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +5 -0
- data/NEWS.ja.rdoc +114 -0
- data/NEWS.rdoc +116 -0
- data/README.ja.rdoc +65 -0
- data/README.rdoc +66 -0
- data/Rakefile +206 -0
- data/benchmark/common.rb +49 -0
- data/benchmark/read-write-many-small-items.rb +144 -0
- data/benchmark/write-many-small-items.rb +135 -0
- data/example/bookmark.rb +161 -0
- data/example/index-html.rb +89 -0
- data/example/search/config.ru +230 -0
- data/example/search/public/css/groonga.css +122 -0
- data/ext/.gitignore +2 -0
- data/ext/groonga/extconf.rb +93 -0
- data/ext/groonga/rb-grn-accessor.c +52 -0
- data/ext/groonga/rb-grn-array-cursor.c +36 -0
- data/ext/groonga/rb-grn-array.c +210 -0
- data/ext/groonga/rb-grn-column.c +573 -0
- data/ext/groonga/rb-grn-context.c +662 -0
- data/ext/groonga/rb-grn-database.c +472 -0
- data/ext/groonga/rb-grn-encoding-support.c +64 -0
- data/ext/groonga/rb-grn-encoding.c +257 -0
- data/ext/groonga/rb-grn-exception.c +1110 -0
- data/ext/groonga/rb-grn-expression-builder.c +75 -0
- data/ext/groonga/rb-grn-expression.c +731 -0
- data/ext/groonga/rb-grn-fix-size-column.c +166 -0
- data/ext/groonga/rb-grn-hash-cursor.c +38 -0
- data/ext/groonga/rb-grn-hash.c +294 -0
- data/ext/groonga/rb-grn-index-column.c +488 -0
- data/ext/groonga/rb-grn-logger.c +504 -0
- data/ext/groonga/rb-grn-object.c +1369 -0
- data/ext/groonga/rb-grn-operation.c +198 -0
- data/ext/groonga/rb-grn-patricia-trie-cursor.c +39 -0
- data/ext/groonga/rb-grn-patricia-trie.c +488 -0
- data/ext/groonga/rb-grn-procedure.c +52 -0
- data/ext/groonga/rb-grn-query.c +260 -0
- data/ext/groonga/rb-grn-record.c +40 -0
- data/ext/groonga/rb-grn-snippet.c +334 -0
- data/ext/groonga/rb-grn-table-cursor-key-support.c +69 -0
- data/ext/groonga/rb-grn-table-cursor.c +247 -0
- data/ext/groonga/rb-grn-table-key-support.c +714 -0
- data/ext/groonga/rb-grn-table.c +1977 -0
- data/ext/groonga/rb-grn-type.c +181 -0
- data/ext/groonga/rb-grn-utils.c +769 -0
- data/ext/groonga/rb-grn-variable-size-column.c +36 -0
- data/ext/groonga/rb-grn-variable.c +108 -0
- data/ext/groonga/rb-grn-view-accessor.c +53 -0
- data/ext/groonga/rb-grn-view-cursor.c +35 -0
- data/ext/groonga/rb-grn-view-record.c +41 -0
- data/ext/groonga/rb-grn-view.c +421 -0
- data/ext/groonga/rb-grn.h +698 -0
- data/ext/groonga/rb-groonga.c +107 -0
- data/extconf.rb +130 -0
- data/html/bar.svg +153 -0
- data/html/developer.html +117 -0
- data/html/developer.svg +469 -0
- data/html/download.svg +253 -0
- data/html/favicon.ico +0 -0
- data/html/favicon.xcf +0 -0
- data/html/footer.html.erb +28 -0
- data/html/head.html.erb +4 -0
- data/html/header.html.erb +17 -0
- data/html/index.html +147 -0
- data/html/install.svg +636 -0
- data/html/logo.xcf +0 -0
- data/html/ranguba.css +250 -0
- data/html/tutorial.svg +559 -0
- data/lib/1.8/groonga.so +0 -0
- data/lib/1.9/groonga.so +0 -0
- data/lib/groonga.rb +90 -0
- data/lib/groonga/context.rb +184 -0
- data/lib/groonga/expression-builder.rb +324 -0
- data/lib/groonga/patricia-trie.rb +85 -0
- data/lib/groonga/record.rb +311 -0
- data/lib/groonga/schema.rb +1191 -0
- data/lib/groonga/view-record.rb +56 -0
- data/license/GPL +340 -0
- data/license/LGPL +504 -0
- data/license/RUBY +59 -0
- data/misc/grnop2ruby.rb +49 -0
- data/pkg-config.rb +333 -0
- data/rroonga-build.rb +57 -0
- data/test-unit/Rakefile +40 -0
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/html/classic.html +15 -0
- data/test-unit/html/index.html +25 -0
- data/test-unit/html/index.html.ja +27 -0
- data/test-unit/lib/test/unit.rb +323 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
- data/test-unit/lib/test/unit/assertions.rb +1230 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +360 -0
- data/test-unit/lib/test/unit/collector.rb +36 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +144 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +102 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +724 -0
- data/test-unit/lib/test/unit/error.rb +130 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +136 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +129 -0
- data/test-unit/lib/test/unit/omission.rb +191 -0
- data/test-unit/lib/test/unit/pending.rb +150 -0
- data/test-unit/lib/test/unit/priority.rb +180 -0
- data/test-unit/lib/test/unit/runner/console.rb +52 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/runner/tap.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +476 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
- data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/test_adder.rb +20 -0
- data/test-unit/sample/test_subtracter.rb +20 -0
- data/test-unit/sample/test_user.rb +23 -0
- data/test-unit/test/collector/test-descendant.rb +133 -0
- data/test-unit/test/collector/test-load.rb +442 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +100 -0
- data/test-unit/test/run-test.rb +15 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +67 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +518 -0
- data/test-unit/test/test-emacs-runner.rb +60 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/test-notification.rb +33 -0
- data/test-unit/test/test-omission.rb +81 -0
- data/test-unit/test/test-pending.rb +70 -0
- data/test-unit/test/test-priority.rb +119 -0
- data/test-unit/test/test-testcase.rb +544 -0
- data/test-unit/test/test_assertions.rb +1151 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit-test-util.rb +14 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/.gitignore +1 -0
- data/test/groonga-test-utils.rb +134 -0
- data/test/run-test.rb +58 -0
- data/test/test-array.rb +90 -0
- data/test/test-column.rb +316 -0
- data/test/test-context-select.rb +93 -0
- data/test/test-context.rb +73 -0
- data/test/test-database.rb +113 -0
- data/test/test-encoding.rb +33 -0
- data/test/test-exception.rb +93 -0
- data/test/test-expression-builder.rb +217 -0
- data/test/test-expression.rb +134 -0
- data/test/test-fix-size-column.rb +65 -0
- data/test/test-gqtp.rb +72 -0
- data/test/test-hash.rb +305 -0
- data/test/test-index-column.rb +81 -0
- data/test/test-logger.rb +37 -0
- data/test/test-patricia-trie.rb +205 -0
- data/test/test-procedure.rb +37 -0
- data/test/test-query.rb +22 -0
- data/test/test-record.rb +243 -0
- data/test/test-remote.rb +54 -0
- data/test/test-schema-view.rb +90 -0
- data/test/test-schema.rb +459 -0
- data/test/test-snippet.rb +130 -0
- data/test/test-table-cursor.rb +153 -0
- data/test/test-table-offset-and-limit.rb +102 -0
- data/test/test-table-select-normalize.rb +53 -0
- data/test/test-table-select.rb +150 -0
- data/test/test-table.rb +594 -0
- data/test/test-type.rb +71 -0
- data/test/test-variable-size-column.rb +98 -0
- data/test/test-variable.rb +28 -0
- data/test/test-vector-column.rb +76 -0
- data/test/test-version.rb +31 -0
- data/test/test-view.rb +72 -0
- data/text/TUTORIAL.ja.rdoc +392 -0
- data/text/expression.rdoc +284 -0
- metadata +276 -0
@@ -0,0 +1,134 @@
|
|
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(){21,01,0PLUS}>",
|
82
|
+
expression.inspect)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_snippet
|
86
|
+
users = Groonga::Array.create(:name => "Users")
|
87
|
+
name = users.define_column("name", "ShortText")
|
88
|
+
terms = Groonga::Hash.create(:name => "Terms",
|
89
|
+
:key_type => "ShortText",
|
90
|
+
:default_tokenizer => "TokenBigram")
|
91
|
+
users.define_index_column("user_name", users,
|
92
|
+
:source => "Users.name",
|
93
|
+
:with_position => true)
|
94
|
+
|
95
|
+
expression = Groonga::Expression.new
|
96
|
+
variable = expression.define_variable(:domain => users)
|
97
|
+
expression.append_object(variable)
|
98
|
+
expression.parse("ラングバ OR Ruby OR groonga", :default_column => name)
|
99
|
+
expression.compile
|
100
|
+
|
101
|
+
snippet = expression.snippet([["[[", "]]"], ["<", ">"]],
|
102
|
+
:width => 30)
|
103
|
+
assert_equal(["[[ラングバ]]プロジェクト",
|
104
|
+
"ン[[groonga]]の機能を<Ruby>か",
|
105
|
+
"。[[groonga]]の機能を<Ruby>ら"],
|
106
|
+
snippet.execute("ラングバプロジェクトはカラムストア機能も" +
|
107
|
+
"備える高速・高機能な全文検索エンジンgroonga" +
|
108
|
+
"の機能をRubyから利用するためのライブラリを" +
|
109
|
+
"提供するプロジェクトです。groongaの機能を" +
|
110
|
+
"Rubyらしい読み書きしやすい構文で利用できる" +
|
111
|
+
"ことが利点です。"))
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_snippet_without_tags
|
115
|
+
users = Groonga::Array.create(:name => "Users")
|
116
|
+
name = users.define_column("name", "ShortText")
|
117
|
+
terms = Groonga::Hash.create(:name => "Terms",
|
118
|
+
:key_type => "ShortText",
|
119
|
+
:default_tokenizer => "TokenBigram")
|
120
|
+
users.define_index_column("user_name", users,
|
121
|
+
:source => "Users.name",
|
122
|
+
:with_position => true)
|
123
|
+
|
124
|
+
expression = Groonga::Expression.new
|
125
|
+
variable = expression.define_variable(:domain => users)
|
126
|
+
expression.append_object(variable)
|
127
|
+
expression.parse("ラングバ", :default_column => name)
|
128
|
+
expression.compile
|
129
|
+
|
130
|
+
snippet = expression.snippet([], :width => 30)
|
131
|
+
assert_equal(["ラングバプロジェクト"],
|
132
|
+
snippet.execute("ラングバプロジェクトはカラムストア機能も"))
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
ADDED
@@ -0,0 +1,72 @@
|
|
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, 0.0, 0.0], [[[1], [["user", "Users"]], ["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.0, 0.0], [[[0], [["user", "Users"]]]]],
|
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
|
+
result = JSON.parse(result)
|
69
|
+
result[0][1..2] = [0.0, 0.0] if result[0][0].zero?
|
70
|
+
result
|
71
|
+
end
|
72
|
+
end
|
data/test/test-hash.rb
ADDED
@@ -0,0 +1,305 @@
|
|
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_has_key?
|
202
|
+
users = Groonga::Hash.create(:name => "Users")
|
203
|
+
assert_false(users.has_key?("morita"))
|
204
|
+
users.add("morita")
|
205
|
+
assert_true(users.has_key?("morita"))
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_big_key
|
209
|
+
hash = Groonga::Hash.create(:key_type => "UInt64")
|
210
|
+
assert_nothing_raised do
|
211
|
+
hash.add(1 << 63)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_value_by_key
|
216
|
+
users = Groonga::Hash.create(:key_type => "ShortText",
|
217
|
+
:value_type => "Int32")
|
218
|
+
key = "niku"
|
219
|
+
users.add(key)
|
220
|
+
users.set_value(key, 29)
|
221
|
+
assert_equal(29, users.value(key))
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_value_by_id
|
225
|
+
users = Groonga::Hash.create(:key_type => "ShortText",
|
226
|
+
:value_type => "Int32")
|
227
|
+
user_id = users.add("niku").id
|
228
|
+
users.set_value(user_id, 29, :id => true)
|
229
|
+
assert_equal(29, users.value(user_id, :id => true))
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_id
|
233
|
+
users = Groonga::Hash.create(:key_type => "ShortText")
|
234
|
+
|
235
|
+
key = "niku"
|
236
|
+
assert_nil(users.id(key))
|
237
|
+
user_id = users.add(key).id
|
238
|
+
assert_equal(user_id, users.id(key))
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_set_multi_values
|
242
|
+
users = Groonga::Hash.create(:name => "Users",
|
243
|
+
:key_type => "ShortText")
|
244
|
+
users.define_column("self_introduction", "ShortText")
|
245
|
+
users.define_column("age", "UInt32")
|
246
|
+
|
247
|
+
key = "niku"
|
248
|
+
niku = users.add(key)
|
249
|
+
assert_equal({
|
250
|
+
"id" => niku.id,
|
251
|
+
"key" => key,
|
252
|
+
"self_introduction" => nil,
|
253
|
+
"age" => 0,
|
254
|
+
},
|
255
|
+
niku.attributes)
|
256
|
+
users[key] = {
|
257
|
+
"self_introduction" => "I'm a meet lover.",
|
258
|
+
"age" => 29
|
259
|
+
}
|
260
|
+
assert_equal({
|
261
|
+
"id" => niku.id,
|
262
|
+
"key" => key,
|
263
|
+
"self_introduction" => "I'm a meet lover.",
|
264
|
+
"age" => 29,
|
265
|
+
},
|
266
|
+
niku.attributes)
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_set_multi_values_for_nonexistent_record
|
270
|
+
users = Groonga::Hash.create(:name => "Users",
|
271
|
+
:key_type => "ShortText")
|
272
|
+
users.define_column("self_introduction", "ShortText")
|
273
|
+
users.define_column("age", "UInt32")
|
274
|
+
|
275
|
+
key = "niku"
|
276
|
+
users[key] = {
|
277
|
+
"self_introduction" => "I'm a meet lover.",
|
278
|
+
"age" => 29
|
279
|
+
}
|
280
|
+
|
281
|
+
assert_equal({
|
282
|
+
"id" => users[key].id,
|
283
|
+
"key" => key,
|
284
|
+
"self_introduction" => "I'm a meet lover.",
|
285
|
+
"age" => 29,
|
286
|
+
},
|
287
|
+
users[key].attributes)
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_set_multi_values_with_nonexistent_column
|
291
|
+
users = Groonga::Hash.create(:name => "Users",
|
292
|
+
:key_type => "ShortText")
|
293
|
+
users.define_column("self_introduction", "ShortText")
|
294
|
+
users.define_column("age", "UInt32")
|
295
|
+
|
296
|
+
key = "niku"
|
297
|
+
inspected_users = users.inspect.sub(/size: <0>/, "size: <1>")
|
298
|
+
message = "no such column: <\"nonexistent\">: <#{inspected_users}>"
|
299
|
+
assert_raise(Groonga::NoSuchColumn.new(message)) do
|
300
|
+
users[key] = {
|
301
|
+
"nonexistent" => "No!",
|
302
|
+
}
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|