rroonga 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/Rakefile +21 -2
  2. data/bin/grndump +3 -2
  3. data/ext/groonga/extconf.rb +1 -6
  4. data/ext/groonga/rb-grn-array.c +58 -31
  5. data/ext/groonga/rb-grn-column.c +220 -148
  6. data/ext/groonga/rb-grn-context.c +46 -32
  7. data/ext/groonga/rb-grn-database.c +102 -90
  8. data/ext/groonga/rb-grn-double-array-trie.c +205 -163
  9. data/ext/groonga/rb-grn-encoding-support.c +2 -3
  10. data/ext/groonga/rb-grn-encoding.c +13 -8
  11. data/ext/groonga/rb-grn-exception.c +1 -1
  12. data/ext/groonga/rb-grn-expression.c +110 -133
  13. data/ext/groonga/rb-grn-fix-size-column.c +5 -4
  14. data/ext/groonga/rb-grn-geo-point.c +55 -0
  15. data/ext/groonga/rb-grn-hash.c +120 -82
  16. data/ext/groonga/rb-grn-index-column.c +66 -70
  17. data/ext/groonga/rb-grn-index-cursor.c +3 -0
  18. data/ext/groonga/rb-grn-logger.c +33 -51
  19. data/ext/groonga/rb-grn-object.c +2 -0
  20. data/ext/groonga/rb-grn-operator.c +1 -1
  21. data/ext/groonga/rb-grn-patricia-trie.c +287 -232
  22. data/ext/groonga/rb-grn-plugin.c +11 -14
  23. data/ext/groonga/rb-grn-snippet.c +37 -54
  24. data/ext/groonga/rb-grn-table-cursor-key-support.c +3 -3
  25. data/ext/groonga/rb-grn-table-cursor.c +8 -6
  26. data/ext/groonga/rb-grn-table-key-support.c +22 -29
  27. data/ext/groonga/rb-grn-table.c +355 -279
  28. data/ext/groonga/rb-grn-type.c +18 -25
  29. data/ext/groonga/rb-grn-utils.c +77 -7
  30. data/ext/groonga/rb-grn-variable-size-column.c +12 -20
  31. data/ext/groonga/rb-grn-view.c +56 -51
  32. data/ext/groonga/rb-grn.h +28 -1
  33. data/ext/groonga/rb-groonga.c +1 -0
  34. data/lib/groonga.rb +2 -0
  35. data/lib/groonga/command.rb +3 -1
  36. data/lib/groonga/database.rb +27 -0
  37. data/lib/groonga/dumper.rb +96 -17
  38. data/lib/groonga/geo-point.rb +216 -0
  39. data/lib/groonga/schema.rb +29 -46
  40. data/rroonga-build.rb +1 -1
  41. data/rroonga.gemspec +90 -0
  42. data/test/groonga-test-utils.rb +168 -0
  43. data/test/run-test.rb +60 -0
  44. data/test/test-accessor.rb +36 -0
  45. data/test/test-array.rb +146 -0
  46. data/test/test-column.rb +350 -0
  47. data/test/test-command-select.rb +181 -0
  48. data/test/test-context.rb +130 -0
  49. data/test/test-database-dumper.rb +259 -0
  50. data/test/test-database.rb +173 -0
  51. data/test/test-double-array-trie.rb +189 -0
  52. data/test/test-encoding.rb +33 -0
  53. data/test/test-exception.rb +230 -0
  54. data/test/test-expression-builder.rb +602 -0
  55. data/test/test-expression.rb +134 -0
  56. data/test/test-fix-size-column.rb +77 -0
  57. data/test/test-geo-point.rb +190 -0
  58. data/test/test-gqtp.rb +70 -0
  59. data/test/test-hash.rb +367 -0
  60. data/test/test-index-column.rb +180 -0
  61. data/test/test-index-cursor.rb +123 -0
  62. data/test/test-logger.rb +37 -0
  63. data/test/test-pagination.rb +249 -0
  64. data/test/test-patricia-trie.rb +440 -0
  65. data/test/test-plugin.rb +35 -0
  66. data/test/test-procedure.rb +37 -0
  67. data/test/test-query-log.rb +258 -0
  68. data/test/test-record.rb +577 -0
  69. data/test/test-remote.rb +63 -0
  70. data/test/test-schema-create-table.rb +267 -0
  71. data/test/test-schema-dumper.rb +235 -0
  72. data/test/test-schema-type.rb +208 -0
  73. data/test/test-schema-view.rb +90 -0
  74. data/test/test-schema.rb +886 -0
  75. data/test/test-snippet.rb +130 -0
  76. data/test/test-table-dumper.rb +353 -0
  77. data/test/test-table-offset-and-limit.rb +100 -0
  78. data/test/test-table-select-mecab.rb +80 -0
  79. data/test/test-table-select-normalize.rb +57 -0
  80. data/test/test-table-select-weight.rb +123 -0
  81. data/test/test-table-select.rb +191 -0
  82. data/test/test-table-traverse.rb +304 -0
  83. data/test/test-table.rb +711 -0
  84. data/test/test-type.rb +79 -0
  85. data/test/test-variable-size-column.rb +147 -0
  86. data/test/test-variable.rb +28 -0
  87. data/test/test-vector-column.rb +76 -0
  88. data/test/test-version.rb +61 -0
  89. data/test/test-view.rb +72 -0
  90. metadata +330 -202
@@ -0,0 +1,130 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2009-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 SnippetTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+
21
+ def setup_encoding
22
+ Groonga::Encoding.default = :utf8
23
+ end
24
+
25
+ def test_new_without_arguments
26
+ assert_nothing_raised do
27
+ Groonga::Snippet.new
28
+ end
29
+ end
30
+
31
+ def test_execute
32
+ snippet = Groonga::Snippet.new
33
+ snippet.add_keyword("検索", :open_tag => "[[", :close_tag => "]]")
34
+ assert_equal(["groonga は組み込み型の全文[[検索]]エンジンライブラリです。DBMSやスクリプト",
35
+ "組み込むことによって、その全文[[検索]]機能を強化することができます。ま"],
36
+ snippet.execute(text))
37
+ end
38
+
39
+ def test_execute_with_nil
40
+ snippet = Groonga::Snippet.new
41
+ snippet.add_keyword("検索", :open_tag => "[[", :close_tag => "]]")
42
+ message = "snippet text must be String: <nil>"
43
+ assert_raise(Groonga::InvalidArgument.new(message)) do
44
+ snippet.execute(nil)
45
+ end
46
+ end
47
+
48
+ def test_invalid_encoding
49
+ Groonga::Context.default.encoding = :shift_jis
50
+ snippet = Groonga::Snippet.new
51
+ snippet.add_keyword("検索")
52
+ assert_equal([], snippet.execute(text))
53
+ end
54
+
55
+ def test_default_tag
56
+ snippet = Groonga::Snippet.new(:default_open_tag => "<<",
57
+ :default_close_tag => ">>")
58
+ snippet.add_keyword("全文")
59
+ assert_equal(["groonga は組み込み型の<<全文>>検索エンジンライブラリです。DBMSやスクリプト",
60
+ "等に組み込むことによって、その<<全文>>検索機能を強化することができます"],
61
+ snippet.execute(text))
62
+ end
63
+
64
+ def test_width
65
+ snippet = Groonga::Snippet.new(:width => 30,
66
+ :default_open_tag => "{",
67
+ :default_close_tag => "}")
68
+ snippet.add_keyword("データ")
69
+ assert_equal(["基づく{データ}ストア機",
70
+ "高速\nな{データ}ストア"],
71
+ snippet.execute(text))
72
+ end
73
+
74
+ def test_max_results
75
+ snippet = Groonga::Snippet.new(:width => 30,
76
+ :max_results => 1,
77
+ :default_open_tag => "{",
78
+ :default_close_tag => "}")
79
+ snippet.add_keyword("データ")
80
+ assert_equal(["基づく{データ}ストア機"],
81
+ snippet.execute(text))
82
+ end
83
+
84
+ def test_normalize
85
+ options_without_normalize = {
86
+ :width => 30,
87
+ :default_open_tag => "{",
88
+ :default_close_tag => "}",
89
+ }
90
+ snippet = Groonga::Snippet.new(options_without_normalize)
91
+ snippet.add_keyword("処理系等")
92
+ assert_equal([], snippet.execute(text))
93
+
94
+ options_with_normalize = options_without_normalize.merge(:normalize => true)
95
+ snippet = Groonga::Snippet.new(options_with_normalize)
96
+ snippet.add_keyword("処理系等")
97
+ assert_equal(["ト言語{処理\n系等}に組"],
98
+ snippet.execute(text))
99
+ end
100
+
101
+ def test_html_escape
102
+ text = "groonga は組み込み型の全文検索エンジン&データストアライブラリです。"
103
+ options_without_html_escape = {
104
+ :width => 30,
105
+ :default_open_tag => "<",
106
+ :default_close_tag => ">",
107
+ }
108
+ snippet = Groonga::Snippet.new(options_without_html_escape)
109
+ snippet.add_keyword("エンジン")
110
+ assert_equal(["文検索<エンジン>&デー"],
111
+ snippet.execute(text))
112
+
113
+ options_with_html_escape =
114
+ options_without_html_escape.merge(:html_escape => true)
115
+ snippet = Groonga::Snippet.new(options_with_html_escape)
116
+ snippet.add_keyword("エンジン")
117
+ assert_equal(["文検索<エンジン>&amp;デー"],
118
+ snippet.execute(text))
119
+ end
120
+
121
+ private
122
+ def text
123
+ <<-EOT
124
+ groonga は組み込み型の全文検索エンジンライブラリです。DBMSやスクリプト言語処理
125
+ 系等に組み込むことによって、その全文検索機能を強化することができます。また、リ
126
+ レーショナルモデルに基づくデータストア機能を内包しており、groonga単体でも高速
127
+ なデータストアサーバとして使用することができます。
128
+ EOT
129
+ end
130
+ end
@@ -0,0 +1,353 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011-2012 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 TableDumperTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+
21
+ setup :setup_database, :before => :append
22
+
23
+ private
24
+ def dump(table_name, options={})
25
+ Groonga::TableDumper.new(context[table_name], options).dump
26
+ end
27
+
28
+ def users
29
+ context["Users"]
30
+ end
31
+
32
+ def posts
33
+ context["Posts"]
34
+ end
35
+
36
+ class TextTest < self
37
+ class ScalarTest < self
38
+ def setup
39
+ Groonga::Schema.define do |schema|
40
+ schema.create_table("Users") do |table|
41
+ table.text("name")
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_empty
47
+ assert_equal(<<-EOS, dump("Users"))
48
+ load --table Users
49
+ [
50
+ ["_id","name"]
51
+ ]
52
+ EOS
53
+ end
54
+
55
+ def test_with_records
56
+ users.add(:name => "mori")
57
+ assert_equal(<<-EOS, dump("Users"))
58
+ load --table Users
59
+ [
60
+ ["_id","name"],
61
+ [1,"mori"]
62
+ ]
63
+ EOS
64
+ end
65
+
66
+ def test_invalid_utf8
67
+ need_encoding
68
+
69
+ users.add(:name => "森\xff大二郎")
70
+ error_output = StringIO.new
71
+ assert_equal(<<-EOS, dump("Users", :error_output => error_output))
72
+ load --table Users
73
+ [
74
+ ["_id","name"],
75
+ [1,"森大二郎"]
76
+ ]
77
+ EOS
78
+ assert_equal("warning: ignore invalid encoding character: " +
79
+ "<Users[1].name>: <0xff>: before: <森>\n",
80
+ error_output.string)
81
+ end
82
+ end
83
+
84
+ class VectorTest < self
85
+ def setup
86
+ Groonga::Schema.define do |schema|
87
+ schema.create_table("Posts") do |table|
88
+ table.text("tags", :type => :vector)
89
+ end
90
+ end
91
+ end
92
+
93
+ def test_empty
94
+ assert_equal(<<-EOS, dump("Posts"))
95
+ load --table Posts
96
+ [
97
+ ["_id","tags"]
98
+ ]
99
+ EOS
100
+ end
101
+
102
+ def test_ascii
103
+ posts.add(:tags => ["search", "mori"])
104
+ assert_equal(<<-EOS, dump("Posts"))
105
+ load --table Posts
106
+ [
107
+ ["_id","tags"],
108
+ [1,["search","mori"]]
109
+ ]
110
+ EOS
111
+ end
112
+
113
+ def test_non_ascii
114
+ posts.add(:tags => ["検索", "森"])
115
+ assert_equal(<<-EOS, dump("Posts"))
116
+ load --table Posts
117
+ [
118
+ ["_id","tags"],
119
+ [1,["検索","森"]]
120
+ ]
121
+ EOS
122
+ end
123
+ end
124
+ end
125
+
126
+ class ReferenceTest < self
127
+ class ScalarTest < self
128
+ def setup
129
+ Groonga::Schema.define do |schema|
130
+ schema.create_table("Users",
131
+ :type => :patricia_trie,
132
+ :key_type => "ShortText") do |table|
133
+ table.text("name")
134
+ end
135
+
136
+ schema.create_table("Posts") do |table|
137
+ table.reference("author", "Users")
138
+ end
139
+
140
+ schema.change_table("Users") do |table|
141
+ table.index("Posts.author")
142
+ end
143
+ end
144
+ end
145
+
146
+ def test_empty
147
+ assert_equal(<<-EOS, dump("Posts"))
148
+ load --table Posts
149
+ [
150
+ ["_id","author"]
151
+ ]
152
+ EOS
153
+ end
154
+
155
+ def test_ascii
156
+ posts.add(:author => "mori")
157
+ assert_equal(<<-EOS, dump("Posts"))
158
+ load --table Posts
159
+ [
160
+ ["_id","author"],
161
+ [1,"mori"]
162
+ ]
163
+ EOS
164
+ end
165
+
166
+ def test_non_ascii
167
+ posts.add(:author => "森")
168
+ assert_equal(<<-EOS, dump("Posts"))
169
+ load --table Posts
170
+ [
171
+ ["_id","author"],
172
+ [1,"森"]
173
+ ]
174
+ EOS
175
+ end
176
+ end
177
+ end
178
+
179
+ class TimeTest < self
180
+ def setup
181
+ Groonga::Schema.define do |schema|
182
+ schema.create_table("Posts") do |table|
183
+ table.time("created_at")
184
+ end
185
+ end
186
+ end
187
+
188
+ def test_empty
189
+ assert_equal(<<-EOS, dump("Posts"))
190
+ load --table Posts
191
+ [
192
+ ["_id","created_at"]
193
+ ]
194
+ EOS
195
+ end
196
+
197
+ def test_with_records
198
+ posts.add(:created_at => Time.parse("2010-03-08 16:52 +0900"))
199
+ assert_equal(<<-EOS, dump("Posts"))
200
+ load --table Posts
201
+ [
202
+ ["_id","created_at"],
203
+ [1,1268034720.0]
204
+ ]
205
+ EOS
206
+ end
207
+ end
208
+
209
+ class IntegerTest < self
210
+ def setup
211
+ Groonga::Schema.define do |schema|
212
+ schema.create_table("Posts") do |table|
213
+ table.integer("rank")
214
+ end
215
+ end
216
+ end
217
+
218
+ def test_empty
219
+ assert_equal(<<-EOS, dump("Posts"))
220
+ load --table Posts
221
+ [
222
+ ["_id","rank"]
223
+ ]
224
+ EOS
225
+ end
226
+
227
+ def test_with_records
228
+ posts.add(:rank => 10)
229
+ assert_equal(<<-EOS, dump("Posts"))
230
+ load --table Posts
231
+ [
232
+ ["_id","rank"],
233
+ [1,10]
234
+ ]
235
+ EOS
236
+ end
237
+ end
238
+
239
+ class UnsignedIntegerTest < self
240
+ def setup
241
+ Groonga::Schema.define do |schema|
242
+ schema.create_table("Posts") do |table|
243
+ table.unsigned_integer("n_goods")
244
+ end
245
+ end
246
+ end
247
+
248
+ def test_empty
249
+ assert_equal(<<-EOS, dump("Posts"))
250
+ load --table Posts
251
+ [
252
+ ["_id","n_goods"]
253
+ ]
254
+ EOS
255
+ end
256
+
257
+ def test_with_records
258
+ posts.add(:n_goods => 4)
259
+ assert_equal(<<-EOS, dump("Posts"))
260
+ load --table Posts
261
+ [
262
+ ["_id","n_goods"],
263
+ [1,4]
264
+ ]
265
+ EOS
266
+ end
267
+ end
268
+
269
+ class TokyoGeoPointTest < self
270
+ def setup
271
+ Groonga::Schema.define do |schema|
272
+ schema.create_table("Posts") do |table|
273
+ table.tokyo_geo_point("location")
274
+ end
275
+ end
276
+ end
277
+
278
+ def test_empty
279
+ assert_equal(<<-EOS, dump("Posts"))
280
+ load --table Posts
281
+ [
282
+ ["_id","location"]
283
+ ]
284
+ EOS
285
+ end
286
+
287
+ def test_with_records
288
+ posts.add(:location => "146481001x-266559998")
289
+ assert_equal(<<-EOS, dump("Posts"))
290
+ load --table Posts
291
+ [
292
+ ["_id","location"],
293
+ [1,"146481001x-266559998"]
294
+ ]
295
+ EOS
296
+ end
297
+ end
298
+
299
+ class WGS84GeoPointTest < self
300
+ def setup
301
+ Groonga::Schema.define do |schema|
302
+ schema.create_table("Posts") do |table|
303
+ table.wgs84_geo_point("location")
304
+ end
305
+ end
306
+ end
307
+
308
+ def test_empty
309
+ assert_equal(<<-EOS, dump("Posts"))
310
+ load --table Posts
311
+ [
312
+ ["_id","location"]
313
+ ]
314
+ EOS
315
+ end
316
+
317
+ def test_with_records
318
+ posts.add(:location => "40.689167x-74.044444")
319
+ assert_equal(<<-EOS, dump("Posts"))
320
+ load --table Posts
321
+ [
322
+ ["_id","location"],
323
+ [1,"146481001x-266559998"]
324
+ ]
325
+ EOS
326
+ end
327
+ end
328
+
329
+ class PatriciaTrieTest < self
330
+ def setup
331
+ Groonga::Schema.define do |schema|
332
+ schema.create_table("Users",
333
+ :type => :patricia_trie,
334
+ :key_type => "ShortText") do |table|
335
+ table.text("name")
336
+ end
337
+ end
338
+ end
339
+
340
+ def test_order_by_default
341
+ users.add("s-yata", :name => "Susumu Yata")
342
+ users.add("mori", :name => "mori daijiro")
343
+ assert_equal(<<-EOS, dump("Users"))
344
+ load --table Users
345
+ [
346
+ [\"_key\",\"name\"],
347
+ [\"mori\",\"mori daijiro\"],
348
+ [\"s-yata\",\"Susumu Yata\"]
349
+ ]
350
+ EOS
351
+ end
352
+ end
353
+ end