rroonga 2.0.2 → 2.0.3

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.
Files changed (62) hide show
  1. data/AUTHORS +5 -0
  2. data/Gemfile +1 -12
  3. data/Rakefile +4 -57
  4. data/bin/grndump +11 -1
  5. data/ext/groonga/extconf.rb +125 -54
  6. data/ext/groonga/rb-grn-context.c +25 -7
  7. data/ext/groonga/rb-grn-database.c +25 -0
  8. data/ext/groonga/rb-grn-object.c +19 -7
  9. data/ext/groonga/rb-grn-table.c +8 -10
  10. data/ext/groonga/rb-grn.h +9 -2
  11. data/lib/groonga/dumper.rb +2 -2
  12. data/lib/groonga/expression-builder.rb +33 -18
  13. data/rroonga-build.rb +1 -1
  14. metadata +97 -180
  15. data/TODO +0 -0
  16. data/test/groonga-test-utils.rb +0 -139
  17. data/test/run-test.rb +0 -60
  18. data/test/test-accessor.rb +0 -36
  19. data/test/test-array.rb +0 -123
  20. data/test/test-column.rb +0 -350
  21. data/test/test-command-select.rb +0 -147
  22. data/test/test-context.rb +0 -130
  23. data/test/test-database-dumper.rb +0 -259
  24. data/test/test-database.rb +0 -148
  25. data/test/test-double-array-trie.rb +0 -164
  26. data/test/test-encoding.rb +0 -33
  27. data/test/test-exception.rb +0 -96
  28. data/test/test-expression-builder.rb +0 -269
  29. data/test/test-expression.rb +0 -134
  30. data/test/test-fix-size-column.rb +0 -77
  31. data/test/test-gqtp.rb +0 -70
  32. data/test/test-hash.rb +0 -344
  33. data/test/test-index-column.rb +0 -180
  34. data/test/test-index-cursor.rb +0 -93
  35. data/test/test-logger.rb +0 -37
  36. data/test/test-pagination.rb +0 -249
  37. data/test/test-patricia-trie.rb +0 -415
  38. data/test/test-plugin.rb +0 -35
  39. data/test/test-procedure.rb +0 -37
  40. data/test/test-query-log.rb +0 -258
  41. data/test/test-record.rb +0 -569
  42. data/test/test-remote.rb +0 -63
  43. data/test/test-schema-create-table.rb +0 -267
  44. data/test/test-schema-dumper.rb +0 -235
  45. data/test/test-schema-type.rb +0 -208
  46. data/test/test-schema-view.rb +0 -90
  47. data/test/test-schema.rb +0 -886
  48. data/test/test-snippet.rb +0 -130
  49. data/test/test-table-cursor.rb +0 -187
  50. data/test/test-table-dumper.rb +0 -83
  51. data/test/test-table-offset-and-limit.rb +0 -100
  52. data/test/test-table-select-mecab.rb +0 -80
  53. data/test/test-table-select-normalize.rb +0 -57
  54. data/test/test-table-select-weight.rb +0 -123
  55. data/test/test-table-select.rb +0 -191
  56. data/test/test-table.rb +0 -675
  57. data/test/test-type.rb +0 -79
  58. data/test/test-variable-size-column.rb +0 -147
  59. data/test/test-variable.rb +0 -28
  60. data/test/test-vector-column.rb +0 -76
  61. data/test/test-version.rb +0 -61
  62. data/test/test-view.rb +0 -72
@@ -1,415 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2009-2011 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 PatriciaTrieTest < Test::Unit::TestCase
19
- include GroongaTestUtils
20
- include ERB::Util
21
-
22
- setup :setup_database
23
-
24
- def test_support_key?
25
- assert_predicate(Groonga::PatriciaTrie.create(:name => "Users",
26
- :key_type => "ShortText"),
27
- :support_key?)
28
- end
29
-
30
- def test_encoding
31
- assert_equal(Groonga::Encoding.default,
32
- Groonga::PatriciaTrie.create.encoding)
33
- end
34
-
35
- def test_tokenizer
36
- trie = Groonga::PatriciaTrie.create
37
- assert_nil(trie.default_tokenizer)
38
- trie.default_tokenizer = "TokenTrigram"
39
- assert_equal(Groonga::Context.default["TokenTrigram"],
40
- trie.default_tokenizer)
41
- end
42
-
43
- def test_search
44
- users = Groonga::Array.create(:name => "Users")
45
- users.define_column("name", "ShortText")
46
-
47
- bookmarks = Groonga::PatriciaTrie.create(:name => "Bookmarks",
48
- :key_type => "ShortText")
49
- bookmarks.define_column("user_id", users)
50
-
51
- daijiro = users.add
52
- daijiro["name"] = "daijiro"
53
- gunyarakun = users.add
54
- gunyarakun["name"] = "gunyarakun"
55
-
56
- groonga = bookmarks.add("http://groonga.org/")
57
- groonga["user_id"] = daijiro
58
-
59
- records = bookmarks.search("http://groonga.org/")
60
- assert_equal(["daijiro"],
61
- records.records.collect {|record| record[".user_id.name"]})
62
- end
63
-
64
- def test_add
65
- users = Groonga::PatriciaTrie.create(:name => "Users")
66
- users.define_column("address", "Text")
67
- me = users.add("me", :address => "me@example.com")
68
- assert_equal("me@example.com", me[:address])
69
- end
70
-
71
- def test_default_tokenizer_on_create
72
- terms = Groonga::PatriciaTrie.create(:name => "Terms",
73
- :default_tokenizer => "TokenUnigram")
74
- assert_equal(context[Groonga::Type::UNIGRAM],
75
- terms.default_tokenizer)
76
- end
77
-
78
- def test_duplicated_name
79
- Groonga::PatriciaTrie.create(:name => "Users")
80
- assert_raise(Groonga::InvalidArgument) do
81
- Groonga::PatriciaTrie.create(:name => "Users")
82
- end
83
- end
84
-
85
- def test_has_key?
86
- users = Groonga::PatriciaTrie.create(:name => "Users")
87
- assert_false(users.has_key?("morita"))
88
- users.add("morita")
89
- assert_true(users.has_key?("morita"))
90
- end
91
-
92
- def test_scan
93
- Groonga::Context.default_options = {:encoding => "utf-8"}
94
- words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
95
- :key_normalize => true)
96
- words.add("リンク")
97
- arupaka = words.add("アルパカ")
98
- words.add("アルパカ(生物)")
99
- adventure_of_link = words.add('リンクの冒険')
100
- words.add('冒険')
101
- gaxtu = words.add('ガッ')
102
- muteki = words.add('MUTEKI')
103
- assert_equal([[muteki, "muTEki", 0, 6],
104
- [adventure_of_link, "リンクの冒険", 7, 18],
105
- [arupaka, "アルパカ", 42, 12],
106
- [gaxtu, "ガッ", 55, 6]],
107
- words.scan('muTEki リンクの冒険 ミリバール アルパカ ガッ'))
108
- end
109
-
110
- def test_tag_keys
111
- Groonga::Context.default_options = {:encoding => "utf-8"}
112
- words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
113
- :key_normalize => true)
114
- words.add('リンク')
115
- words.add('リンクの冒険')
116
- words.add('冒険')
117
- words.add('㍊')
118
- words.add('ガッ')
119
- words.add('MUTEKI')
120
-
121
- text = 'muTEki リンクの冒険 マッチしない ミリバール ガッ おわり'
122
- actual = words.tag_keys(text) do |record, word|
123
- "<#{word}(#{record.key})>"
124
- end
125
- assert_equal("<muTEki(muteki)> " +
126
- "<リンクの冒険(リンクの冒険)> " +
127
- "マッチしない " +
128
- "<ミリバール(ミリバール)> " +
129
- "<ガッ(ガッ)> " +
130
- "おわり",
131
- actual)
132
- end
133
-
134
- def test_tag_keys_other_text_handler
135
- Groonga::Context.default_options = {:encoding => "utf-8"}
136
- words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
137
- :key_normalize => true)
138
- words.add('ガッ')
139
- words.add('MUTEKI')
140
-
141
- text = 'muTEki マッチしない <> ガッ'
142
- other_text_handler = Proc.new do |string|
143
- h(string)
144
- end
145
- options = {:other_text_handler => other_text_handler}
146
- actual = words.tag_keys(text, options) do |record, word|
147
- "<span class=\"keyword\">#{h(word)}(#{h(record.key)})</span>\n"
148
- end
149
- assert_equal("<span class=\"keyword\">muTEki(muteki)</span>\n" +
150
- " マッチしない &lt;&gt; " +
151
- "<span class=\"keyword\">ガッ(ガッ)</span>\n",
152
- actual)
153
- end
154
-
155
- def test_tag_keys_with_last_match
156
- Groonga::Context.default_options = {:encoding => "utf-8"}
157
- words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
158
- :key_normalize => true)
159
- words.add('ガッ')
160
- words.add('MUTEKI')
161
-
162
- text = 'muTEki マッチしない ガッ'
163
- actual = words.tag_keys(text) do |record, word|
164
- "<#{word}(#{record.key})>"
165
- end
166
- assert_equal("<muTEki(muteki)> " +
167
- "マッチしない " +
168
- "<ガッ(ガッ)>",
169
- actual)
170
- end
171
-
172
- def test_tag_keys_with_no_match
173
- Groonga::Context.default_options = {:encoding => "utf-8"}
174
- words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
175
- :key_normalize => true)
176
-
177
- words.add('無敵')
178
- words.add('BOUKEN')
179
-
180
- text = 'muTEki リンクの冒険'
181
- actual = words.tag_keys(text) do |record, word|
182
- "<#{word}(#{record.key})>"
183
- end
184
- assert_equal(text, actual)
185
- end
186
-
187
- def test_prefix_search
188
- paths = Groonga::PatriciaTrie.create(:name => "Paths",
189
- :key_type => 'ShortText')
190
- paths.add('/')
191
- paths.add('/tmp')
192
- paths.add('/usr/bin')
193
- paths.add('/usr/local/bin')
194
-
195
- records = paths.prefix_search('/')
196
- assert_equal(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
197
- records.records.collect {|record| record["._key"]})
198
-
199
- records = paths.prefix_search('/usr')
200
- assert_equal(["/usr/local/bin", "/usr/bin"],
201
- records.records.collect {|record| record["._key"]})
202
-
203
- records = paths.prefix_search('/usr/local')
204
- assert_equal(["/usr/local/bin"],
205
- records.records.collect {|record| record["._key"]})
206
-
207
- records = paths.prefix_search('nonexistent')
208
- assert_equal([],
209
- records.records.collect {|record| record["._key"]})
210
- end
211
-
212
-
213
- def test_prefix_cursor
214
- paths = Groonga::PatriciaTrie.create(:name => "Paths",
215
- :key_type => 'ShortText')
216
- paths.add('/')
217
- paths.add('/tmp')
218
- paths.add('/usr/bin')
219
- paths.add('/usr/local/bin')
220
-
221
- assert_prefix_cursor(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
222
- paths, "/", {:order => :desc})
223
- assert_prefix_cursor(["/", "/tmp", "/usr/bin", "/usr/local/bin"],
224
- paths, "/")
225
- assert_prefix_cursor(["/usr/local/bin", "/usr/bin"],
226
- paths, "/usr/local",
227
- {:key_bytes => "/usr".size, :order => :desc})
228
- assert_prefix_cursor(["/tmp", "/usr/bin"],
229
- paths, "/",
230
- {:offset => 1, :limit => 2})
231
- end
232
-
233
- def assert_prefix_cursor(expected, tables, prefix, options={})
234
- actual = []
235
- tables.open_prefix_cursor(prefix, options) do |cursor|
236
- cursor.each do |record|
237
- actual << record.key
238
- end
239
- end
240
- assert_equal(expected, actual)
241
- end
242
-
243
- def test_rk_cursor
244
- terms = Groonga::PatriciaTrie.create(:name => "Terms",
245
- :key_type => 'ShortText')
246
- ["インデックス",
247
- "エヌグラム",
248
- "エンジン",
249
- "カネソナエタ",
250
- "カノウ",
251
- "キノウ",
252
- "キョウカ",
253
- "クミコミ",
254
- "クミコム",
255
- "グルンガ",
256
- "ケンサク",
257
- "ケンサクヨウキュウ",
258
- "ゲンゴ",
259
- "コウセイド",
260
- "コウソク",
261
- "コンパクト",
262
- "サクセイ",
263
- "ショリ",
264
- "ショリケイ",
265
- "ジッソウ",
266
- "ジュンスイ",
267
- "スクリプト",
268
- "セッケイ",
269
- "ゼンブン",
270
- "タイプ",
271
- "タンゴ",
272
- "ダイキボ",
273
- "テンチ",
274
- "ディービーエムエス",
275
- "トウ",
276
- "トクチョウ",
277
- "ブンショリョウ",
278
- "ヨウキュウ"].each do |term|
279
- terms.add(term)
280
- end
281
-
282
- assert_rk_cursor(["カネソナエタ",
283
- "カノウ",
284
- "キノウ",
285
- "キョウカ",
286
- "クミコミ",
287
- "クミコム",
288
- "ケンサク",
289
- "ケンサクヨウキュウ",
290
- "コウセイド",
291
- "コウソク",
292
- "コンパクト"],
293
- terms, "k")
294
- end
295
-
296
- def assert_rk_cursor(expected, tables, prefix, options={})
297
- actual = []
298
- tables.open_rk_cursor(prefix, options) do |cursor|
299
- cursor.each do |record|
300
- actual << record.key
301
- end
302
- end
303
- assert_equal(expected, actual.sort)
304
- end
305
-
306
- def test_near_cursor
307
- points = Groonga::PatriciaTrie.create(:name => "Points",
308
- :key_type => 'WGS84GeoPoint')
309
- ["130322053x504985073",
310
- "130285021x504715091",
311
- "130117012x504390088",
312
- "130335016x504662007",
313
- "130308044x504536008",
314
- "130306053x504530043",
315
- "130205016x505331054",
316
- "130222054x505270050",
317
- "130255017x504266011",
318
- "130239038x504251015",
319
- "129885039x503653023",
320
- "129809022x504597055",
321
- "130015001x504266057",
322
- "130089012x505045070",
323
- "130208017x504315098",
324
- "130347036x504325073",
325
- "130380061x505202034",
326
- "129903045x504648034",
327
- "130094061x505025099",
328
- "130133052x505120058",
329
- "130329069x505188046",
330
- "130226001x503769013",
331
- "129866001x504328017",
332
- "129786048x504792049",
333
- "129845056x504853081",
334
- "130055008x504968095",
335
- "130086003x504480071",
336
- "129680021x504441006",
337
- "129855010x504452003",
338
- "130280013x505208029",
339
- "129721099x504685024",
340
- "129690039x504418033",
341
- "130019020x505027021",
342
- "130046026x505082073",
343
- "130038025x505066028",
344
- "129917001x504675017"].each do |point|
345
- points.add(point)
346
- end
347
-
348
- assert_near_cursor(["129680021x504441006",
349
- "129690039x504418033",
350
- "129721099x504685024",
351
- "129786048x504792049",
352
- "129809022x504597055",
353
- "129845056x504853081",
354
- "129855010x504452003",
355
- "129866001x504328017",
356
- "129885039x503653023",
357
- "129903045x504648034"],
358
- points,
359
- "129786048x504792049",
360
- {:limit => 10})
361
- end
362
-
363
- def assert_near_cursor(expected, tables, prefix, options={})
364
- actual = []
365
- tables.open_near_cursor(prefix, options) do |cursor|
366
- cursor.each do |record|
367
- actual << record.key
368
- end
369
- end
370
- assert_equal(expected, actual)
371
- end
372
-
373
- def test_add_uint_key
374
- numbers = Groonga::PatriciaTrie.create(:name => "Numbers",
375
- :key_type => "UInt32")
376
- numbers.add(1)
377
- numbers.add(2)
378
- numbers.add(5)
379
- numbers.add(7)
380
- assert_equal([1, 2, 5, 7], numbers.collect {|number| number.key})
381
- end
382
-
383
- def test_added?
384
- users = Groonga::PatriciaTrie.create(:name => "Users",
385
- :key_type => "ShortText")
386
- bob = users.add("bob")
387
- assert_predicate(bob, :added?)
388
- bob_again = users.add("bob")
389
- assert_not_predicate(bob_again, :added?)
390
- end
391
-
392
- def test_defrag
393
- users = Groonga::PatriciaTrie.create(:name => "Users",
394
- :key_type => "ShortText")
395
- users.define_column("name", "ShortText")
396
- users.define_column("address", "ShortText")
397
- 1000.times do |i|
398
- users.add("user #{i}",
399
- :name => "user #{i}" * 1000,
400
- :address => "address #{i}" * 1000)
401
- end
402
- assert_equal(7, users.defrag)
403
- end
404
-
405
- def test_rename
406
- users = Groonga::PatriciaTrie.create(:name => "Users",
407
- :key_type => "ShortText")
408
- name = users.define_column("name", "ShortText")
409
- address = users.define_column("address", "ShortText")
410
-
411
- users.rename("People")
412
- assert_equal(["People", "People.name", "People.address"],
413
- [users.name, name.name, address.name])
414
- end
415
- end
data/test/test-plugin.rb DELETED
@@ -1,35 +0,0 @@
1
- # Copyright (C) 2011 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 PluginTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- setup :setup_sandbox
20
- setup :setup_database
21
- teardown :teardown_sandbox
22
-
23
- def test_register
24
- context = Groonga::Context.default
25
- assert_nil(context["suggest"])
26
- context.register_plugin("suggest/suggest")
27
- assert_not_nil(context["suggest"])
28
- end
29
-
30
- def test_system_plugins_dir
31
- suggest_plugin_path = "#{Groonga::Plugin.system_plugins_dir}/"
32
- suggest_plugin_path << "suggest/suggest#{Groonga::Plugin.suffix}"
33
- assert_send([File, :exist?, suggest_plugin_path])
34
- end
35
- end