rroonga 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +21 -2
- data/bin/grndump +3 -2
- data/ext/groonga/extconf.rb +1 -6
- data/ext/groonga/rb-grn-array.c +58 -31
- data/ext/groonga/rb-grn-column.c +220 -148
- data/ext/groonga/rb-grn-context.c +46 -32
- data/ext/groonga/rb-grn-database.c +102 -90
- data/ext/groonga/rb-grn-double-array-trie.c +205 -163
- data/ext/groonga/rb-grn-encoding-support.c +2 -3
- data/ext/groonga/rb-grn-encoding.c +13 -8
- data/ext/groonga/rb-grn-exception.c +1 -1
- data/ext/groonga/rb-grn-expression.c +110 -133
- data/ext/groonga/rb-grn-fix-size-column.c +5 -4
- data/ext/groonga/rb-grn-geo-point.c +55 -0
- data/ext/groonga/rb-grn-hash.c +120 -82
- data/ext/groonga/rb-grn-index-column.c +66 -70
- data/ext/groonga/rb-grn-index-cursor.c +3 -0
- data/ext/groonga/rb-grn-logger.c +33 -51
- data/ext/groonga/rb-grn-object.c +2 -0
- data/ext/groonga/rb-grn-operator.c +1 -1
- data/ext/groonga/rb-grn-patricia-trie.c +287 -232
- data/ext/groonga/rb-grn-plugin.c +11 -14
- data/ext/groonga/rb-grn-snippet.c +37 -54
- data/ext/groonga/rb-grn-table-cursor-key-support.c +3 -3
- data/ext/groonga/rb-grn-table-cursor.c +8 -6
- data/ext/groonga/rb-grn-table-key-support.c +22 -29
- data/ext/groonga/rb-grn-table.c +355 -279
- data/ext/groonga/rb-grn-type.c +18 -25
- data/ext/groonga/rb-grn-utils.c +77 -7
- data/ext/groonga/rb-grn-variable-size-column.c +12 -20
- data/ext/groonga/rb-grn-view.c +56 -51
- data/ext/groonga/rb-grn.h +28 -1
- data/ext/groonga/rb-groonga.c +1 -0
- data/lib/groonga.rb +2 -0
- data/lib/groonga/command.rb +3 -1
- data/lib/groonga/database.rb +27 -0
- data/lib/groonga/dumper.rb +96 -17
- data/lib/groonga/geo-point.rb +216 -0
- data/lib/groonga/schema.rb +29 -46
- data/rroonga-build.rb +1 -1
- data/rroonga.gemspec +90 -0
- data/test/groonga-test-utils.rb +168 -0
- data/test/run-test.rb +60 -0
- data/test/test-accessor.rb +36 -0
- data/test/test-array.rb +146 -0
- data/test/test-column.rb +350 -0
- data/test/test-command-select.rb +181 -0
- data/test/test-context.rb +130 -0
- data/test/test-database-dumper.rb +259 -0
- data/test/test-database.rb +173 -0
- data/test/test-double-array-trie.rb +189 -0
- data/test/test-encoding.rb +33 -0
- data/test/test-exception.rb +230 -0
- data/test/test-expression-builder.rb +602 -0
- data/test/test-expression.rb +134 -0
- data/test/test-fix-size-column.rb +77 -0
- data/test/test-geo-point.rb +190 -0
- data/test/test-gqtp.rb +70 -0
- data/test/test-hash.rb +367 -0
- data/test/test-index-column.rb +180 -0
- data/test/test-index-cursor.rb +123 -0
- data/test/test-logger.rb +37 -0
- data/test/test-pagination.rb +249 -0
- data/test/test-patricia-trie.rb +440 -0
- data/test/test-plugin.rb +35 -0
- data/test/test-procedure.rb +37 -0
- data/test/test-query-log.rb +258 -0
- data/test/test-record.rb +577 -0
- data/test/test-remote.rb +63 -0
- data/test/test-schema-create-table.rb +267 -0
- data/test/test-schema-dumper.rb +235 -0
- data/test/test-schema-type.rb +208 -0
- data/test/test-schema-view.rb +90 -0
- data/test/test-schema.rb +886 -0
- data/test/test-snippet.rb +130 -0
- data/test/test-table-dumper.rb +353 -0
- data/test/test-table-offset-and-limit.rb +100 -0
- data/test/test-table-select-mecab.rb +80 -0
- data/test/test-table-select-normalize.rb +57 -0
- data/test/test-table-select-weight.rb +123 -0
- data/test/test-table-select.rb +191 -0
- data/test/test-table-traverse.rb +304 -0
- data/test/test-table.rb +711 -0
- data/test/test-type.rb +79 -0
- data/test/test-variable-size-column.rb +147 -0
- data/test/test-variable.rb +28 -0
- data/test/test-vector-column.rb +76 -0
- data/test/test-version.rb +61 -0
- data/test/test-view.rb +72 -0
- metadata +330 -202
@@ -0,0 +1,602 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) 2009-2012 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 ExpressionBuilderTest < Test::Unit::TestCase
|
18
|
+
include GroongaTestUtils
|
19
|
+
|
20
|
+
setup :setup_database
|
21
|
+
setup :setup_tables
|
22
|
+
setup :setup_data
|
23
|
+
|
24
|
+
def setup_tables
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup_data
|
28
|
+
end
|
29
|
+
|
30
|
+
class EqualityTest < self
|
31
|
+
def setup_tables
|
32
|
+
Groonga::Schema.define do |schema|
|
33
|
+
schema.create_table("Users",
|
34
|
+
:type => :hash,
|
35
|
+
:key_type => "ShortText") do |table|
|
36
|
+
table.short_text("name")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@users = Groonga["Users"]
|
41
|
+
end
|
42
|
+
|
43
|
+
def define_users_name_index
|
44
|
+
Groonga::Schema.define do |schema|
|
45
|
+
schema.create_table("Terms",
|
46
|
+
:type => :patricia_trie,
|
47
|
+
:default_tokenizer => "TokenBigram",
|
48
|
+
:key_type => "ShortText") do |table|
|
49
|
+
table.index("Users.name")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def setup_data
|
55
|
+
@users.add("morita", :name => "mori daijiro")
|
56
|
+
@users.add("gunyara-kun", :name => "Tasuku SUENAGA")
|
57
|
+
@users.add("yu", :name => "Yutaro Shimamura")
|
58
|
+
end
|
59
|
+
|
60
|
+
class EqualTest < self
|
61
|
+
def test_without_index
|
62
|
+
result = @users.select do |record|
|
63
|
+
record["name"] == "mori daijiro"
|
64
|
+
end
|
65
|
+
assert_equal(["morita"],
|
66
|
+
result.collect {|record| record.key.key})
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_with_index
|
70
|
+
define_users_name_index
|
71
|
+
result = @users.select do |record|
|
72
|
+
record["name"] == "mori daijiro"
|
73
|
+
end
|
74
|
+
assert_equal(["morita"],
|
75
|
+
result.collect {|record| record.key.key})
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class NotEqualTest < self
|
80
|
+
setup :only_ruby19
|
81
|
+
|
82
|
+
def test_without_index
|
83
|
+
result = @users.select do |record|
|
84
|
+
record["name"] != "mori daijiro"
|
85
|
+
end
|
86
|
+
assert_equal(["gunyara-kun", "yu"],
|
87
|
+
result.collect {|record| record.key.key})
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_with_index
|
91
|
+
define_users_name_index
|
92
|
+
result = @users.select do |record|
|
93
|
+
record["name"] != "mori daijiro"
|
94
|
+
end
|
95
|
+
assert_equal(["gunyara-kun", "yu"],
|
96
|
+
result.collect {|record| record.key.key})
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class RelationTest < self
|
102
|
+
def setup_tables
|
103
|
+
Groonga::Schema.define do |schema|
|
104
|
+
schema.create_table("Users",
|
105
|
+
:type => :hash,
|
106
|
+
:key_type => "ShortText") do |table|
|
107
|
+
table.uint32("hp")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
@users = Groonga["Users"]
|
112
|
+
end
|
113
|
+
|
114
|
+
def setup_data
|
115
|
+
@users.add("morita", :hp => 100)
|
116
|
+
@users.add("gunyara-kun", :hp => 150)
|
117
|
+
@users.add("yu", :hp => 200)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_less
|
121
|
+
result = @users.select do |record|
|
122
|
+
record["hp"] < 150
|
123
|
+
end
|
124
|
+
assert_equal(["morita"], result.collect {|record| record.key.key})
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_less_equal
|
128
|
+
result = @users.select do |record|
|
129
|
+
record["hp"] <= 150
|
130
|
+
end
|
131
|
+
assert_equal(["morita", "gunyara-kun"],
|
132
|
+
result.collect {|record| record.key.key})
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_greater
|
136
|
+
result = @users.select do |record|
|
137
|
+
record["hp"] > 150
|
138
|
+
end
|
139
|
+
assert_equal(["yu"], result.collect {|record| record.key.key})
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_greater_equal
|
143
|
+
result = @users.select do |record|
|
144
|
+
record["hp"] >= 150
|
145
|
+
end
|
146
|
+
assert_equal(["gunyara-kun", "yu"],
|
147
|
+
result.collect {|record| record.key.key})
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class LogicalTest < self
|
152
|
+
def setup_tables
|
153
|
+
Groonga::Schema.define do |schema|
|
154
|
+
schema.create_table("Users",
|
155
|
+
:type => :hash,
|
156
|
+
:key_type => "ShortText") do |table|
|
157
|
+
table.uint32("hp")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
@users = Groonga["Users"]
|
162
|
+
end
|
163
|
+
|
164
|
+
def setup_data
|
165
|
+
@users.add("morita", :hp => 100)
|
166
|
+
@users.add("gunyara-kun", :hp => 150)
|
167
|
+
@users.add("yu", :hp => 200)
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_and
|
171
|
+
result = @users.select do |record|
|
172
|
+
(record["hp"] > 100) & (record["hp"] <= 200)
|
173
|
+
end
|
174
|
+
assert_equal(["gunyara-kun", "yu"],
|
175
|
+
result.collect {|record| record.key.key})
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_and_array
|
179
|
+
result = @users.select do |record|
|
180
|
+
conditions = []
|
181
|
+
conditions << (record.hp > 100)
|
182
|
+
conditions << (record.hp <= 200)
|
183
|
+
conditions
|
184
|
+
end
|
185
|
+
assert_equal(["gunyara-kun", "yu"],
|
186
|
+
result.collect {|record| record.key.key})
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_or
|
190
|
+
result = @users.select do |record|
|
191
|
+
(record["hp"] == 150) | (record["hp"] > 150)
|
192
|
+
end
|
193
|
+
assert_equal(["gunyara-kun", "yu"],
|
194
|
+
result.collect {|record| record.key.key})
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
class FullTextSearchTest < self
|
199
|
+
def setup_tables
|
200
|
+
Groonga::Schema.define do |schema|
|
201
|
+
schema.create_table("Users",
|
202
|
+
:type => :hash,
|
203
|
+
:key_type => "ShortText") do |table|
|
204
|
+
table.short_text("name")
|
205
|
+
end
|
206
|
+
|
207
|
+
schema.create_table("Terms",
|
208
|
+
:type => :patricia_trie,
|
209
|
+
:default_tokenizer => "TokenBigram",
|
210
|
+
:key_type => "ShortText") do |table|
|
211
|
+
table.index("Users.name")
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
@users = Groonga["Users"]
|
216
|
+
end
|
217
|
+
|
218
|
+
def setup_data
|
219
|
+
@users.add("morita", :name => "mori daijiro")
|
220
|
+
@users.add("gunyara-kun", :name => "Tasuku SUENAGA")
|
221
|
+
@users.add("yu", :name => "Yutaro Shimamura")
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_match
|
225
|
+
result = @users.select do |record|
|
226
|
+
record["name"] =~ "ro"
|
227
|
+
end
|
228
|
+
assert_equal(["morita", "yu"],
|
229
|
+
result.collect {|record| record.key.key})
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_nil_match
|
233
|
+
@users.select do |record|
|
234
|
+
exception = ArgumentError.new("match word should not be nil: Users.name")
|
235
|
+
assert_raise(exception) do
|
236
|
+
record["name"] =~ nil
|
237
|
+
end
|
238
|
+
record["name"] == "dummy"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_query_string
|
243
|
+
result = @users.select("name:@ro")
|
244
|
+
assert_equal(["morita", "yu"],
|
245
|
+
result.collect {|record| record.key.key})
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
class PrefixSearchTest < self
|
250
|
+
def setup_tables
|
251
|
+
Groonga::Schema.define do |schema|
|
252
|
+
schema.create_table("Sections",
|
253
|
+
:type => :patricia_trie,
|
254
|
+
:key_type => "ShortText") do |table|
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
@sections = Groonga["Sections"]
|
259
|
+
end
|
260
|
+
|
261
|
+
def setup_data
|
262
|
+
@sections.add("search/core")
|
263
|
+
@sections.add("suggest/all")
|
264
|
+
@sections.add("search/all")
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_match
|
268
|
+
result = @sections.select do |record|
|
269
|
+
record.key.prefix_search("search")
|
270
|
+
end
|
271
|
+
assert_equal(["search/all", "search/core"].sort,
|
272
|
+
result.collect {|record| record.key.key}.sort)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
class SuffixSearchTest < self
|
277
|
+
def test_patricia_trie_use_index
|
278
|
+
Groonga::Schema.define do |schema|
|
279
|
+
schema.create_table("Users",
|
280
|
+
:type => :patricia_trie,
|
281
|
+
:key_with_sis => true,
|
282
|
+
:key_type => "ShortText") do |table|
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
users = Groonga["Users"]
|
287
|
+
users.add("ひろゆき")
|
288
|
+
users.add("まさゆき")
|
289
|
+
users.add("ゆきひろ")
|
290
|
+
|
291
|
+
result = users.select do |record|
|
292
|
+
record.key.suffix_search("ゆき")
|
293
|
+
end
|
294
|
+
assert_equal(["ひろゆき", "まさゆき", "ろゆき", "さゆき", "ゆき"].sort,
|
295
|
+
result.collect {|record| record.key.key}.sort)
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_patricia_trie_not_use_index
|
299
|
+
Groonga::Schema.define do |schema|
|
300
|
+
schema.create_table("Users",
|
301
|
+
:type => :patricia_trie,
|
302
|
+
:key_type => "ShortText") do |table|
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
users = Groonga["Users"]
|
307
|
+
users.add("ひろゆき")
|
308
|
+
users.add("まさゆき")
|
309
|
+
users.add("ゆきひろ")
|
310
|
+
|
311
|
+
result = users.select do |record|
|
312
|
+
record.key.suffix_search("ゆき")
|
313
|
+
end
|
314
|
+
assert_equal(["ひろゆき", "まさゆき"].sort,
|
315
|
+
result.collect {|record| record.key.key}.sort)
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_column
|
319
|
+
Groonga::Schema.define do |schema|
|
320
|
+
schema.create_table("Users") do |table|
|
321
|
+
table.short_text(:name)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
users = Groonga["Users"]
|
326
|
+
users.add(:name => "ひろゆき")
|
327
|
+
users.add(:name => "まさゆき")
|
328
|
+
users.add(:name => "ゆきひろ")
|
329
|
+
|
330
|
+
result = users.select do |record|
|
331
|
+
record.name.suffix_search("ゆき")
|
332
|
+
end
|
333
|
+
assert_equal(["ひろゆき", "まさゆき"].sort,
|
334
|
+
result.collect {|record| record.key.name}.sort)
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
class SimilarSearchTest < self
|
339
|
+
def setup_tables
|
340
|
+
Groonga::Schema.define do |schema|
|
341
|
+
schema.create_table("Documents",
|
342
|
+
:type => :hash,
|
343
|
+
:key_type => "ShortText") do |table|
|
344
|
+
table.text("content")
|
345
|
+
end
|
346
|
+
|
347
|
+
schema.create_table("Terms",
|
348
|
+
:type => :patricia_trie,
|
349
|
+
:key_type => "ShortText",
|
350
|
+
:default_tokenizer => "TokenBigram",
|
351
|
+
:key_normalize => true) do |table|
|
352
|
+
table.index("Documents.content")
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
@documents = Groonga["Documents"]
|
357
|
+
end
|
358
|
+
|
359
|
+
def setup_data
|
360
|
+
@documents.add("Groonga overview", :content => <<-EOC)
|
361
|
+
Groonga is a fast and accurate full text search engine based on
|
362
|
+
inverted index. One of the characteristics of groonga is that a newly
|
363
|
+
registered document instantly appears in search results. Also, groonga
|
364
|
+
allows updates without read locks. These characteristics result in
|
365
|
+
superior performance on real-time applications.
|
366
|
+
EOC
|
367
|
+
@documents.add("Full text search and Instant update", :content => <<-EOC)
|
368
|
+
In widely used DBMSs, updates are immediately processed, for example,
|
369
|
+
a newly registered record appears in the result of the next query. In
|
370
|
+
contrast, some full text search engines do not support instant
|
371
|
+
updates, because it is difficult to dynamically update inverted
|
372
|
+
indexes, the underlying data structure.
|
373
|
+
EOC
|
374
|
+
@documents.add("Column store and aggregate query", :content => <<-EOC)
|
375
|
+
People can collect more than enough data in the Internet era. However,
|
376
|
+
it is difficult to extract informative knowledge from a large
|
377
|
+
database, and such a task requires a many-sided analysis through trial
|
378
|
+
and error. For example, search refinement by date, time and location
|
379
|
+
may reveal hidden patterns. Aggregate queries are useful to perform
|
380
|
+
this kind of tasks.
|
381
|
+
EOC
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_table
|
385
|
+
result = @documents.select do |record|
|
386
|
+
record.content.similar_search("fast full text search real time")
|
387
|
+
end
|
388
|
+
assert_equal(["Groonga overview", "Column store and aggregate query"].sort,
|
389
|
+
result.collect {|record| record.key.key}.sort)
|
390
|
+
end
|
391
|
+
|
392
|
+
def test_column
|
393
|
+
result = @documents.column("content").select do |content|
|
394
|
+
content.similar_search("fast full text search real time")
|
395
|
+
end
|
396
|
+
assert_equal(["Groonga overview", "Column store and aggregate query"].sort,
|
397
|
+
result.collect {|record| record.key.key}.sort)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
class RecordTest < self
|
402
|
+
def setup_tables
|
403
|
+
Groonga::Schema.define do |schema|
|
404
|
+
schema.create_table("Users",
|
405
|
+
:type => :hash,
|
406
|
+
:key_type => "ShortText") do |table|
|
407
|
+
end
|
408
|
+
|
409
|
+
schema.create_table("Bookmarks") do |table|
|
410
|
+
table.reference("user", "Users")
|
411
|
+
table.short_text("uri")
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
@users = Groonga["Users"]
|
416
|
+
@bookmarks = Groonga["Bookmarks"]
|
417
|
+
end
|
418
|
+
|
419
|
+
def setup_data
|
420
|
+
@morita = @users.add("morita")
|
421
|
+
@gunyara_kun = @users.add("gunyara-kun")
|
422
|
+
|
423
|
+
@bookmarks.add(:user => @morita, :uri => "http://groonga.org/")
|
424
|
+
@bookmarks.add(:user => @morita, :uri => "http://ruby-lang.org/")
|
425
|
+
@bookmarks.add(:user => @gunyara_kun,
|
426
|
+
:uri => "http://dic.nicovideo.jp/")
|
427
|
+
end
|
428
|
+
|
429
|
+
def test_object
|
430
|
+
result = @bookmarks.select do |record|
|
431
|
+
record["user"] == @morita
|
432
|
+
end
|
433
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
434
|
+
result.collect {|record| record.key["uri"]})
|
435
|
+
end
|
436
|
+
|
437
|
+
def test_id
|
438
|
+
result = @bookmarks.select do |record|
|
439
|
+
record["user"] == @morita.id
|
440
|
+
end
|
441
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
442
|
+
result.collect {|record| record.key["uri"]})
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_record_like_object
|
446
|
+
morita = Object.new
|
447
|
+
morita_singleton_class = (class << morita; self; end)
|
448
|
+
morita_id = @morita.id
|
449
|
+
morita_singleton_class.send(:define_method, :record_id) do
|
450
|
+
morita_id
|
451
|
+
end
|
452
|
+
result = @bookmarks.select do |record|
|
453
|
+
record["user"] == morita
|
454
|
+
end
|
455
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
456
|
+
result.collect {|record| record.key["uri"]})
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
class AccessorTest < self
|
461
|
+
def setup_tables
|
462
|
+
Groonga::Schema.define do |schema|
|
463
|
+
schema.create_table("Sections",
|
464
|
+
:type => :patricia_trie,
|
465
|
+
:key_type => "ShortText") do |table|
|
466
|
+
end
|
467
|
+
|
468
|
+
schema.create_table("Users",
|
469
|
+
:type => :hash,
|
470
|
+
:key_type => "ShortText") do |table|
|
471
|
+
table.short_text("name")
|
472
|
+
end
|
473
|
+
|
474
|
+
schema.create_table("Bookmarks") do |table|
|
475
|
+
table.reference("user", "Users")
|
476
|
+
table.short_text("uri")
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
@users = Groonga["Users"]
|
481
|
+
@bookmarks = Groonga["Bookmarks"]
|
482
|
+
end
|
483
|
+
|
484
|
+
def setup_data
|
485
|
+
@morita = @users.add("morita", :name => "mori daijiro")
|
486
|
+
@gunyara_kun = @users.add("gunyara-kun", :name => "Tasuku SUENAGA")
|
487
|
+
|
488
|
+
@bookmarks.add(:user => @morita, :uri => "http://groonga.org/")
|
489
|
+
@bookmarks.add(:user => @morita, :uri => "http://ruby-lang.org/")
|
490
|
+
@bookmarks.add(:user => @gunyara_kun , :uri => "http://dic.nicovideo.jp/")
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_nested_column
|
494
|
+
result = @bookmarks.select do |record|
|
495
|
+
record["user.name"] == @morita["name"]
|
496
|
+
end
|
497
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
498
|
+
result.collect {|record| record["uri"]})
|
499
|
+
end
|
500
|
+
|
501
|
+
def test_method_chain
|
502
|
+
result = @bookmarks.select do |record|
|
503
|
+
record.user.name == @morita["name"]
|
504
|
+
end
|
505
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
506
|
+
result.collect {|record| record["uri"]})
|
507
|
+
end
|
508
|
+
|
509
|
+
def test_deep_method_chain
|
510
|
+
Groonga::Schema.define do |schema|
|
511
|
+
schema.create_table("Pets",
|
512
|
+
:type => :hash,
|
513
|
+
:key_type => "ShortText") do |table|
|
514
|
+
table.short_text("name")
|
515
|
+
end
|
516
|
+
|
517
|
+
schema.change_table("Users") do |table|
|
518
|
+
table.reference("pet", "Pets")
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
pets = Groonga["Pets"]
|
523
|
+
pets.add("bob", :name => "morita Bob")
|
524
|
+
@morita["pet"] = "bob"
|
525
|
+
|
526
|
+
result = @bookmarks.select do |record|
|
527
|
+
record.user.pet.name == "morita Bob"
|
528
|
+
end
|
529
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
530
|
+
result.collect {|record| record["uri"]})
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
class PseudoColumnTest < self
|
535
|
+
def setup_tables
|
536
|
+
Groonga::Schema.define do |schema|
|
537
|
+
schema.create_table("Users",
|
538
|
+
:type => :hash,
|
539
|
+
:key_type => "ShortText") do |table|
|
540
|
+
table.short_text("name")
|
541
|
+
end
|
542
|
+
|
543
|
+
schema.create_table("Terms",
|
544
|
+
:type => :patricia_trie,
|
545
|
+
:default_tokenizer => "TokenBigram",
|
546
|
+
:key_type => "ShortText") do |table|
|
547
|
+
table.index("Users.name")
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
@users = Groonga["Users"]
|
552
|
+
end
|
553
|
+
|
554
|
+
def setup_data
|
555
|
+
@users.add("morita", :name => "mori daijiro")
|
556
|
+
@users.add("gunyara-kun", :name => "Tasuku SUENAGA")
|
557
|
+
@users.add("yu", :name => "Yutaro Shimamura")
|
558
|
+
end
|
559
|
+
|
560
|
+
def test_id
|
561
|
+
result = @users.select do |record|
|
562
|
+
record.id == 1
|
563
|
+
end
|
564
|
+
assert_equal(["morita"],
|
565
|
+
result.collect {|record| record.key.key})
|
566
|
+
end
|
567
|
+
|
568
|
+
def test_key
|
569
|
+
result = @users.select do |record|
|
570
|
+
record.key == "morita"
|
571
|
+
end
|
572
|
+
assert_equal(["morita"],
|
573
|
+
result.collect {|record| record.key.key})
|
574
|
+
end
|
575
|
+
|
576
|
+
def test_score
|
577
|
+
result = @users.select do |record|
|
578
|
+
(record.name =~ "mori") |
|
579
|
+
(record.name =~ "daijiro") |
|
580
|
+
(record.name =~ "Tasuku")
|
581
|
+
end
|
582
|
+
result = result.select do |record|
|
583
|
+
record.score == 2
|
584
|
+
end
|
585
|
+
assert_equal([["morita", 2]],
|
586
|
+
result.collect {|record| [record["_key"], record.key.score]})
|
587
|
+
end
|
588
|
+
|
589
|
+
def test_n_sub_records
|
590
|
+
result = @users.select do |record|
|
591
|
+
(record.name =~ "o") | (record.key == "yu")
|
592
|
+
end
|
593
|
+
result = result.select do |record|
|
594
|
+
record.n_sub_records > 1
|
595
|
+
end
|
596
|
+
matched_records = result.collect do |record|
|
597
|
+
[record["_key"], record.key.n_sub_records]
|
598
|
+
end
|
599
|
+
assert_equal([["yu", 2]], matched_records)
|
600
|
+
end
|
601
|
+
end
|
602
|
+
end
|