rroonga 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.ja.rdoc +29 -0
- data/NEWS.rdoc +29 -0
- data/Rakefile +5 -3
- data/ext/groonga/rb-grn-array.c +1 -1
- data/ext/groonga/rb-grn-context.c +15 -28
- data/ext/groonga/rb-grn-exception.c +46 -1
- data/ext/groonga/rb-grn-expression.c +22 -13
- data/ext/groonga/rb-grn-fix-size-column.c +2 -8
- data/ext/groonga/rb-grn-hash.c +8 -1
- data/ext/groonga/rb-grn-object.c +1 -1
- data/ext/groonga/rb-grn-patricia-trie.c +23 -1
- data/ext/groonga/rb-grn-table-key-support.c +22 -0
- data/ext/groonga/rb-grn-table.c +37 -5
- data/ext/groonga/rb-grn-utils.c +20 -2
- data/ext/groonga/rb-groonga.c +76 -38
- data/extconf.rb +17 -1
- data/html/developer.html +32 -7
- data/html/footer.html.erb +5 -0
- data/html/heading-mark.svg +393 -0
- data/html/index.html +33 -3
- data/lib/groonga.rb +3 -7
- data/lib/groonga/context.rb +2 -13
- data/lib/groonga/expression-builder.rb +273 -67
- data/lib/groonga/pagination.rb +143 -0
- data/lib/groonga/record.rb +2 -0
- data/lib/groonga/schema.rb +140 -29
- data/rroonga-build.rb +2 -2
- 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/groonga-test-utils.rb +3 -2
- data/test/run-test.rb +14 -2
- data/test/test-column.rb +7 -7
- data/test/test-context-select.rb +34 -11
- data/test/test-exception.rb +3 -0
- data/test/test-expression-builder.rb +11 -0
- data/test/test-expression.rb +3 -6
- data/test/test-gqtp.rb +3 -5
- data/test/test-pagination.rb +249 -0
- data/test/test-record.rb +36 -8
- data/test/test-remote.rb +11 -4
- data/test/test-schema-create-table.rb +251 -0
- data/test/test-schema.rb +4 -24
- data/test/test-table-offset-and-limit.rb +3 -5
- data/test/test-table-select-mecab.rb +80 -0
- data/test/test-table-select-weight.rb +104 -0
- data/test/test-table.rb +22 -4
- data/test/test-version.rb +1 -1
- data/text/TUTORIAL.ja.rdoc +2 -0
- data/text/expression.rdoc +1 -0
- metadata +96 -35
data/test/test-record.rb
CHANGED
@@ -31,8 +31,8 @@ class RecordTest < Test::Unit::TestCase
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def setup_users_table
|
34
|
-
@users = Groonga::
|
35
|
-
|
34
|
+
@users = Groonga::Hash.create(:name => "Users",
|
35
|
+
:key_type => "ShortText")
|
36
36
|
@users.define_column("addresses", @addresses, :type => "vector")
|
37
37
|
end
|
38
38
|
|
@@ -93,19 +93,47 @@ class RecordTest < Test::Unit::TestCase
|
|
93
93
|
|
94
94
|
def test_set_object_id
|
95
95
|
groonga = @bookmarks.add
|
96
|
-
daijiro = @users.add
|
97
|
-
daijiro["name"] = "daijiro"
|
96
|
+
daijiro = @users.add("daijiro")
|
98
97
|
assert_nil(groonga["user"])
|
99
|
-
groonga["user"] = daijiro
|
98
|
+
groonga["user"] = daijiro
|
100
99
|
assert_equal(daijiro, groonga["user"])
|
101
100
|
end
|
102
101
|
|
103
102
|
def test_set_nil
|
104
|
-
groonga = @bookmarks.add
|
103
|
+
groonga = @bookmarks.add(:content => "groonga")
|
104
|
+
assert_equal("groonga", groonga["content"])
|
105
105
|
groonga["content"] = nil
|
106
106
|
assert_nil(groonga["content"])
|
107
107
|
end
|
108
108
|
|
109
|
+
def test_set_empty_string
|
110
|
+
groonga = @bookmarks.add(:content => "groonga")
|
111
|
+
assert_equal("groonga", groonga["content"])
|
112
|
+
groonga["content"] = ""
|
113
|
+
assert_nil(groonga["content"])
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_set_nil_reference
|
117
|
+
groonga = @bookmarks.add(:user => "daijiro",
|
118
|
+
:uri => "http://groonga.org/")
|
119
|
+
groonga.user = nil
|
120
|
+
assert_nil(groonga.user)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_set_empty_key_reference
|
124
|
+
groonga = @bookmarks.add(:user => "daijiro",
|
125
|
+
:uri => "http://groonga.org/")
|
126
|
+
assert_equal(@users["daijiro"], groonga.user)
|
127
|
+
groonga["user"] = ""
|
128
|
+
assert_nil(groonga.user)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_set_string_to_integer_column
|
132
|
+
groonga = @bookmarks.add(:content => "groonga")
|
133
|
+
groonga.rate = "100"
|
134
|
+
assert_equal(100, groonga.rate)
|
135
|
+
end
|
136
|
+
|
109
137
|
def test_delete
|
110
138
|
bookmark1 = @bookmarks.add
|
111
139
|
bookmark2 = @bookmarks.add
|
@@ -236,8 +264,8 @@ class RecordTest < Test::Unit::TestCase
|
|
236
264
|
end
|
237
265
|
|
238
266
|
def test_method_chain
|
239
|
-
morita = @users.add(
|
267
|
+
morita = @users.add("morita")
|
240
268
|
groonga = @bookmarks.add(:user => morita, :uri => "http://groonga.org")
|
241
|
-
assert_equal("morita", groonga.user.
|
269
|
+
assert_equal("morita", groonga.user.key)
|
242
270
|
end
|
243
271
|
end
|
data/test/test-remote.rb
CHANGED
@@ -46,9 +46,16 @@ class RemoteTest < Test::Unit::TestCase
|
|
46
46
|
assert_equal(0, _context.send("status"))
|
47
47
|
id, result = _context.receive
|
48
48
|
assert_equal(0, id)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
values = JSON.load(result)
|
50
|
+
assert_equal(["alloc_count", "starttime", "uptime", "version"],
|
51
|
+
values.keys.sort)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_invalid_select
|
55
|
+
context.connect(:host => @host, :port => @port)
|
56
|
+
|
57
|
+
assert_raise(Groonga::InvalidArgument) do
|
58
|
+
context.select("bogus", :query => "()()")
|
59
|
+
end
|
53
60
|
end
|
54
61
|
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
# Copyright (C) 2009-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
|
+
module SchemaCreateTableTests
|
17
|
+
def test_normal
|
18
|
+
assert_nil(context["Posts"])
|
19
|
+
Groonga::Schema.create_table("Posts", options) do |table|
|
20
|
+
end
|
21
|
+
assert_not_nil(context["Posts"])
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_force
|
25
|
+
Groonga::Schema.create_table("Posts", options) do |table|
|
26
|
+
table.string("name")
|
27
|
+
end
|
28
|
+
assert_not_nil(context["Posts.name"])
|
29
|
+
|
30
|
+
Groonga::Schema.create_table("Posts",
|
31
|
+
options(:type => differnt_type,
|
32
|
+
:force => true)) do |table|
|
33
|
+
end
|
34
|
+
assert_nil(context["Posts.name"])
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_different_type
|
38
|
+
Groonga::Schema.create_table("Posts", options) do |table|
|
39
|
+
end
|
40
|
+
|
41
|
+
assert_raise(Groonga::Schema::TableCreationWithDifferentOptions) do
|
42
|
+
Groonga::Schema.create_table("Posts",
|
43
|
+
options(:type => differnt_type)) do |table|
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_same_options
|
49
|
+
Groonga::Schema.create_table("Posts", options) do |table|
|
50
|
+
end
|
51
|
+
|
52
|
+
Groonga::Schema.create_table("Posts", options) do |table|
|
53
|
+
end
|
54
|
+
assert_not_nil(context["Posts"])
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_same_value_type
|
58
|
+
Groonga::Schema.create_table("Posts",
|
59
|
+
options(:value_type => "UInt32")) do |table|
|
60
|
+
end
|
61
|
+
|
62
|
+
Groonga::Schema.create_table("Posts",
|
63
|
+
options(:value_type => "UInt32")) do |table|
|
64
|
+
end
|
65
|
+
assert_equal(context["UInt32"], context["Posts"].range)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_differnt_value_type
|
69
|
+
Groonga::Schema.create_table("Posts", options) do |table|
|
70
|
+
end
|
71
|
+
|
72
|
+
assert_raise(Groonga::Schema::TableCreationWithDifferentOptions) do
|
73
|
+
Groonga::Schema.create_table("Posts",
|
74
|
+
options(:value_type => "Int32")) do |table|
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_same_sub_records
|
80
|
+
Groonga::Schema.create_table("Posts",
|
81
|
+
options(:sub_records => true)) do |table|
|
82
|
+
end
|
83
|
+
|
84
|
+
Groonga::Schema.create_table("Posts",
|
85
|
+
options(:sub_records => true)) do |table|
|
86
|
+
end
|
87
|
+
assert_true(context["Posts"].support_sub_records?)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_differnt_sub_records
|
91
|
+
Groonga::Schema.create_table("Posts",
|
92
|
+
options(:sub_records => true)) do |table|
|
93
|
+
end
|
94
|
+
|
95
|
+
assert_raise(Groonga::Schema::TableCreationWithDifferentOptions) do
|
96
|
+
Groonga::Schema.create_table("Posts",
|
97
|
+
options(:sub_records => false)) do |table|
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
def options(addional_options={})
|
104
|
+
default_options.merge(addional_options)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
module SchemaCreateTableWithKeyTests
|
109
|
+
def test_same_key_type
|
110
|
+
Groonga::Schema.create_table("Posts",
|
111
|
+
options(:key_type => "ShortText")) do |table|
|
112
|
+
end
|
113
|
+
|
114
|
+
Groonga::Schema.create_table("Posts",
|
115
|
+
options(:key_type => "ShortText")) do |table|
|
116
|
+
end
|
117
|
+
assert_equal(context["ShortText"], context["Posts"].domain)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_differnt_key_type
|
121
|
+
Groonga::Schema.create_table("Posts", options) do |table|
|
122
|
+
end
|
123
|
+
|
124
|
+
assert_raise(Groonga::Schema::TableCreationWithDifferentOptions) do
|
125
|
+
Groonga::Schema.create_table("Posts",
|
126
|
+
options(:key_type => "ShortText")) do |table|
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_same_default_tokenizer
|
132
|
+
_options = options(:key_type => "ShortText",
|
133
|
+
:default_tokenizer => "TokenBigram")
|
134
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
135
|
+
end
|
136
|
+
|
137
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
138
|
+
end
|
139
|
+
assert_equal(context["TokenBigram"], context["Posts"].default_tokenizer)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_differnt_default_tokenizer
|
143
|
+
_options = options(:key_type => "ShortText")
|
144
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
145
|
+
end
|
146
|
+
|
147
|
+
_options = _options.merge(:default_tokenizer => "TokenBigram")
|
148
|
+
assert_raise(Groonga::Schema::TableCreationWithDifferentOptions) do
|
149
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_same_key_normalize
|
155
|
+
_options = options(:key_type => "ShortText",
|
156
|
+
:key_normalize => true)
|
157
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
158
|
+
end
|
159
|
+
|
160
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
161
|
+
end
|
162
|
+
assert_true(context["Posts"].normalize_key?)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_differnt_key_normalize
|
166
|
+
_options = options(:key_type => "ShortText",
|
167
|
+
:key_normalize => true)
|
168
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
169
|
+
end
|
170
|
+
|
171
|
+
_options = _options.merge(:key_normalize => false)
|
172
|
+
assert_raise(Groonga::Schema::TableCreationWithDifferentOptions) do
|
173
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
class SchemaCreateTableArrayTest < Test::Unit::TestCase
|
180
|
+
include GroongaTestUtils
|
181
|
+
include SchemaCreateTableTests
|
182
|
+
|
183
|
+
setup :setup_database
|
184
|
+
|
185
|
+
private
|
186
|
+
def default_options
|
187
|
+
{}
|
188
|
+
end
|
189
|
+
|
190
|
+
def differnt_type
|
191
|
+
:hash
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
class SchemaCreateTableHashTest < Test::Unit::TestCase
|
196
|
+
include GroongaTestUtils
|
197
|
+
include SchemaCreateTableTests
|
198
|
+
include SchemaCreateTableWithKeyTests
|
199
|
+
|
200
|
+
setup :setup_database
|
201
|
+
|
202
|
+
private
|
203
|
+
def default_options
|
204
|
+
{:type => :hash}
|
205
|
+
end
|
206
|
+
|
207
|
+
def differnt_type
|
208
|
+
:patricia_trie
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
class SchemaCreateTablePatriciaTrieTest < Test::Unit::TestCase
|
213
|
+
include GroongaTestUtils
|
214
|
+
include SchemaCreateTableTests
|
215
|
+
include SchemaCreateTableWithKeyTests
|
216
|
+
|
217
|
+
setup :setup_database
|
218
|
+
|
219
|
+
def test_same_key_with_sis
|
220
|
+
_options = options(:key_type => "ShortText",
|
221
|
+
:key_with_sis => true)
|
222
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
223
|
+
end
|
224
|
+
|
225
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
226
|
+
end
|
227
|
+
assert_true(context["Posts"].register_key_with_sis?)
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_differnt_key_with_sis
|
231
|
+
_options = options(:key_type => "ShortText",
|
232
|
+
:key_with_sis => true)
|
233
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
234
|
+
end
|
235
|
+
|
236
|
+
_options = _options.merge(:key_with_sis => false)
|
237
|
+
assert_raise(Groonga::Schema::TableCreationWithDifferentOptions) do
|
238
|
+
Groonga::Schema.create_table("Posts", _options) do |table|
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
private
|
244
|
+
def default_options
|
245
|
+
{:type => :patricia_trie}
|
246
|
+
end
|
247
|
+
|
248
|
+
def differnt_type
|
249
|
+
:array
|
250
|
+
end
|
251
|
+
end
|
data/test/test-schema.rb
CHANGED
@@ -18,28 +18,6 @@ class SchemaTest < Test::Unit::TestCase
|
|
18
18
|
|
19
19
|
setup :setup_database
|
20
20
|
|
21
|
-
def test_create_table
|
22
|
-
assert_nil(context["Posts"])
|
23
|
-
Groonga::Schema.create_table("Posts") do |table|
|
24
|
-
end
|
25
|
-
assert_not_nil(context["Posts"])
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_create_table_force
|
29
|
-
Groonga::Schema.create_table("Posts") do |table|
|
30
|
-
table.string("name")
|
31
|
-
end
|
32
|
-
assert_not_nil(context["Posts.name"])
|
33
|
-
|
34
|
-
Groonga::Schema.create_table("Posts") do |table|
|
35
|
-
end
|
36
|
-
assert_not_nil(context["Posts.name"])
|
37
|
-
|
38
|
-
Groonga::Schema.create_table("Posts", :force => true) do |table|
|
39
|
-
end
|
40
|
-
assert_nil(context["Posts.name"])
|
41
|
-
end
|
42
|
-
|
43
21
|
def test_remove_table
|
44
22
|
Groonga::Array.create(:name => "Posts")
|
45
23
|
assert_not_nil(context["Posts"])
|
@@ -266,7 +244,7 @@ class SchemaTest < Test::Unit::TestCase
|
|
266
244
|
table.text :content
|
267
245
|
end
|
268
246
|
|
269
|
-
assert_raise(
|
247
|
+
assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do
|
270
248
|
Groonga::Schema.create_table("Posts") do |table|
|
271
249
|
table.integer :content
|
272
250
|
end
|
@@ -341,7 +319,7 @@ class SchemaTest < Test::Unit::TestCase
|
|
341
319
|
table.index "Posts.content"
|
342
320
|
end
|
343
321
|
|
344
|
-
assert_raise(
|
322
|
+
assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do
|
345
323
|
Groonga::Schema.create_table("Terms") do |table|
|
346
324
|
table.index "Posts.name", :name => "Posts_content"
|
347
325
|
end
|
@@ -455,5 +433,7 @@ EOS
|
|
455
433
|
|
456
434
|
assert_not_nil(context["Items.text"])
|
457
435
|
assert_not_nil(context["TermsText.Items_text"])
|
436
|
+
assert_nil(Groonga::Context.default["Items.text"])
|
437
|
+
assert_nil(Groonga::Context.default["TermsText.Items_text"])
|
458
438
|
end
|
459
439
|
end
|
@@ -18,7 +18,7 @@ module TestOffsetAndLimitSupport
|
|
18
18
|
assert_equal(((100 + 0)...200).to_a, ids(:offset => 0))
|
19
19
|
assert_equal(((100 + 32)...200).to_a, ids(:offset => 32))
|
20
20
|
assert_equal(((100 + 99)...200).to_a, ids(:offset => 99))
|
21
|
-
assert_raise(Groonga::
|
21
|
+
assert_raise(Groonga::TooLargeOffset) do
|
22
22
|
ids(:offset => 100)
|
23
23
|
end
|
24
24
|
end
|
@@ -27,7 +27,7 @@ module TestOffsetAndLimitSupport
|
|
27
27
|
assert_equal(((200 - 1)...200).to_a, ids(:offset => -1))
|
28
28
|
assert_equal(((200 - 32)...200).to_a, ids(:offset => -32))
|
29
29
|
assert_equal(((200 - 100)...200).to_a, ids(:offset => -100))
|
30
|
-
assert_raise(Groonga::
|
30
|
+
assert_raise(Groonga::TooSmallOffset) do
|
31
31
|
ids(:offset => -101)
|
32
32
|
end
|
33
33
|
end
|
@@ -47,9 +47,7 @@ module TestOffsetAndLimitSupport
|
|
47
47
|
assert_equal(all_ids[0..-1], ids(:limit => -1))
|
48
48
|
assert_equal(all_ids[0..-32], ids(:limit => -32))
|
49
49
|
assert_equal(all_ids[0..-100], ids(:limit => -100))
|
50
|
-
|
51
|
-
ids(:offset => -101)
|
52
|
-
end
|
50
|
+
assert_equal([], ids(:limit => -101))
|
53
51
|
end
|
54
52
|
|
55
53
|
private
|
@@ -0,0 +1,80 @@
|
|
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 TableSelectMecabTest < Test::Unit::TestCase
|
19
|
+
include GroongaTestUtils
|
20
|
+
|
21
|
+
setup :setup_database
|
22
|
+
|
23
|
+
setup
|
24
|
+
def check_mecab_availability
|
25
|
+
omit("MeCab isn't available") if context["TokenMecab"].nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
setup
|
29
|
+
def setup_tables
|
30
|
+
Groonga::Schema.define do |schema|
|
31
|
+
schema.create_table("Users", :key_type => "ShortText") do |table|
|
32
|
+
end
|
33
|
+
|
34
|
+
schema.create_table("Comments", :type => :array) do |table|
|
35
|
+
table.short_text("title")
|
36
|
+
table.text("content")
|
37
|
+
table.time("created_at")
|
38
|
+
table.reference("user", "Users")
|
39
|
+
end
|
40
|
+
|
41
|
+
schema.create_table("Terms",
|
42
|
+
:type => :patricia_trie,
|
43
|
+
:default_tokenizer => "TokenMecab") do |table|
|
44
|
+
table.index("Comments.title", :with_section => true)
|
45
|
+
table.index("Comments.content", :with_section => true)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
setup
|
51
|
+
def setup_comments
|
52
|
+
@comments = context["Comments"]
|
53
|
+
@hello = @comments.add(:title => "Hello",
|
54
|
+
:content => "Hello Good-bye!",
|
55
|
+
:created_at => Time.parse("2009-08-09"),
|
56
|
+
:user => "morita")
|
57
|
+
@hello_only_in_content =
|
58
|
+
@comments.add(:title => "(no title)",
|
59
|
+
:content => "Hello! Hello! Hello!",
|
60
|
+
:created_at => Time.parse("2009-07-09"))
|
61
|
+
@test = @comments.add(:title => "title",
|
62
|
+
:content => "test",
|
63
|
+
:created_at => Time.parse("2009-06-09"),
|
64
|
+
:user => "gunyara-kun")
|
65
|
+
@japanese =
|
66
|
+
@comments.add(:title => "日本語",
|
67
|
+
:content => "うちのボロTVはまだ現役です",
|
68
|
+
:created_at => Time.parse("2009-06-09"),
|
69
|
+
:user => "darashi")
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_match
|
73
|
+
result = @comments.select do |record|
|
74
|
+
record.content =~ "ボロ"
|
75
|
+
end
|
76
|
+
assert_equal_select_result(["日本語"], result) do |record|
|
77
|
+
record.title
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|