rroonga 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
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,147 +0,0 @@
1
- # Copyright (C) 2010-2012 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 CommandSelectTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- setup :setup_database
20
- setup
21
- def setup_data
22
- Groonga::Schema.define do |schema|
23
- schema.create_table("Books",
24
- :type => :hash, :key_type => "ShortText") do |table|
25
- table.time("published")
26
- end
27
-
28
- schema.create_table("Users",
29
- :type => :hash, :key_type => "ShortText") do |table|
30
- table.reference("book", "Books")
31
- end
32
-
33
- schema.create_table("Bigram",
34
- :type => :patricia_trie,
35
- :key_type => "ShortText",
36
- :default_tokenizer => "TokenBigramSplitSymbolAlpha") do |table|
37
- table.index("Books._key")
38
- end
39
- end
40
-
41
- @books = Groonga["Books"]
42
- @users = Groonga["Users"]
43
-
44
- @books.add("the groonga book", :published => Time.parse("2010/04/01"))
45
- @books.add("the groonga book (2)", :published => Time.parse("2011/04/01"))
46
-
47
- @users.add("morita", :book => "the groonga book")
48
- @users.add("gunyara-kun", :book => "the groonga book")
49
- @users.add("yu")
50
- @users.add("ryoqun", :book => "the groonga book (2)")
51
- end
52
-
53
- def test_no_option
54
- result = context.select(@users)
55
- assert_equal([4,
56
- [{"_id" => 1, "_key" => "morita",
57
- "book" => "the groonga book"},
58
- {"_id" => 2, "_key" => "gunyara-kun",
59
- "book" => "the groonga book"},
60
- {"_id" => 3, "_key" => "yu",
61
- "book" => ""},
62
- {"_id" => 4, "_key" => "ryoqun",
63
- "book" => "the groonga book (2)"}]],
64
- [result.n_hits, result.records])
65
- end
66
-
67
- def test_output_columns
68
- result = context.select(@users, :output_columns => ["_key"])
69
- assert_equal([4,
70
- [{"_key" => "morita"},
71
- {"_key" => "gunyara-kun"},
72
- {"_key" => "yu"},
73
- {"_key" => "ryoqun"}]],
74
- [result.n_hits, result.records])
75
- end
76
-
77
- def test_drill_down
78
- result = context.select(@users,
79
- :output_columns => ["_key"],
80
- :drill_down => ["_key", "book"],
81
- :drill_down_output_columns => "_key",
82
- :drill_down_limit => 10)
83
- drill_down = normalize_drill_down(result.drill_down)
84
- assert_equal([4,
85
- [{"_key" => "morita"},
86
- {"_key" => "gunyara-kun"},
87
- {"_key" => "yu"},
88
- {"_key" => "ryoqun"}],
89
- {
90
- "_key" => [4, [{"_key" => "morita"},
91
- {"_key" => "gunyara-kun"},
92
- {"_key" => "yu"},
93
- {"_key" => "ryoqun"}]],
94
- "book" => [2, [{"_key" => "the groonga book"},
95
- {"_key" => "the groonga book (2)"}]],
96
- },
97
- ],
98
- [result.n_hits, result.records, drill_down])
99
- end
100
-
101
- def test_drill_down_with_no_hit
102
- result = context.select(@users,
103
- :filter => "_key == \"no\\ hit\"",
104
- :output_columns => ["_key"],
105
- :drill_down => ["_key", "book"],
106
- :drill_down_output_columns => "_key",
107
- :drill_down_limit => 10)
108
- drill_down = normalize_drill_down(result.drill_down)
109
- assert_equal([0, [],
110
- {
111
- "_key" => [0, []],
112
- "book" => [0, []],
113
- },
114
- ],
115
- [result.n_hits, result.records, drill_down])
116
- end
117
-
118
- def test_time
119
- result = context.select(@books)
120
- assert_equal([{
121
- "_id" => 1,
122
- "_key" => "the groonga book",
123
- "published" => Time.parse("2010/04/01"),
124
- },
125
- {
126
- "_id" => 2,
127
- "_key" => "the groonga book (2)",
128
- "published" => Time.parse("2011/04/01"),
129
- }],
130
- result.records)
131
- end
132
-
133
- def test_invalid
134
- assert_raise(Groonga::SyntaxError) do
135
- context.select(@books, :query => "<")
136
- end
137
- end
138
-
139
- private
140
- def normalize_drill_down(drill_down)
141
- normalized_drill_down = {}
142
- drill_down.each do |key, drill|
143
- normalized_drill_down[key] = [drill.n_hits, drill.records]
144
- end
145
- normalized_drill_down
146
- end
147
- end
data/test/test-context.rb DELETED
@@ -1,130 +0,0 @@
1
- # Copyright (C) 2009-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 ContextTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- def test_default
20
- context = Groonga::Context.default
21
- assert_equal(Groonga::Encoding.default, context.encoding)
22
- end
23
-
24
- def test_default_options
25
- Groonga::Context.default_options = {
26
- :encoding => :utf8,
27
- }
28
- context = Groonga::Context.default
29
- assert_equal(Groonga::Encoding::UTF8, context.encoding)
30
- end
31
-
32
- def test_create_database
33
- db_path = @tmp_dir + "db"
34
- assert_not_predicate(db_path, :exist?)
35
- context = Groonga::Context.new
36
- assert_equal(nil, context.database)
37
- database = context.create_database(db_path.to_s)
38
- assert_predicate(db_path, :exist?)
39
- assert_not_predicate(database, :closed?)
40
- assert_equal(database, context.database)
41
- end
42
-
43
- def test_create_temporary_database
44
- before_files = @tmp_dir.children
45
- context = Groonga::Context.new
46
- database = context.create_database
47
- assert_nil(database.name)
48
- assert_equal(before_files, @tmp_dir.children)
49
- end
50
-
51
- def test_open_database
52
- db_path = @tmp_dir + "db"
53
- database = Groonga::Database.create(:path => db_path.to_s)
54
- database.close
55
-
56
- assert_predicate(database, :closed?)
57
- called = false
58
- context = Groonga::Context.new
59
- context.open_database(db_path.to_s) do |_database|
60
- database = _database
61
- assert_not_predicate(database, :closed?)
62
- called = true
63
- end
64
- assert_true(called)
65
- assert_predicate(database, :closed?)
66
- end
67
-
68
- def test_encoding
69
- context = Groonga::Context.new
70
- assert_equal(Groonga::Encoding.default, context.encoding)
71
-
72
- context = Groonga::Context.new(:encoding => :utf8)
73
- assert_equal(Groonga::Encoding::UTF8, context.encoding)
74
- end
75
-
76
- def test_inspect
77
- context = Groonga::Context.new(:encoding => Groonga::Encoding::UTF8)
78
- assert_equal("#<Groonga::Context " +
79
- "encoding: <:utf8>, " +
80
- "database: <nil>>",
81
- context.inspect)
82
- end
83
-
84
- def test_inspect_with_database
85
- db = Groonga::Database.create
86
- context = Groonga::Context.default
87
- assert_equal("#<Groonga::Context " +
88
- "encoding: <#{Groonga::Encoding.default.inspect}>, " +
89
- "database: <#{db.inspect}>>",
90
- context.inspect)
91
- end
92
-
93
- def test_array_reference_by_string
94
- Groonga::Database.create
95
- context = Groonga::Context.default
96
- assert_equal("Int32", context["<int>"].name)
97
- end
98
-
99
- def test_array_reference_by_symbol
100
- Groonga::Database.create
101
- context = Groonga::Context.default
102
- assert_equal("Bool", context[:Bool].name)
103
- end
104
-
105
- def test_shortcut_access
106
- Groonga::Database.create
107
- assert_equal("ShortText", Groonga["ShortText"].name)
108
- end
109
-
110
- def test_support_zlib?
111
- assert_boolean(Groonga::Context.default.support_zlib?)
112
- end
113
-
114
- def test_support_lzo?
115
- assert_boolean(Groonga::Context.default.support_lzo?)
116
- end
117
-
118
- def test_match_escalation_threshold
119
- assert_equal(0, context.match_escalation_threshold)
120
- context.match_escalation_threshold = -1
121
- assert_equal(-1, context.match_escalation_threshold)
122
- end
123
-
124
- def test_close
125
- context = Groonga::Context.new
126
- assert_false(context.closed?)
127
- context.close
128
- assert_true(context.closed?)
129
- end
130
- end
@@ -1,259 +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 DatabaseDumperTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- setup :setup_database, :before => :append
20
-
21
- setup
22
- def setup_tables
23
- Groonga::Schema.define do |schema|
24
- schema.create_table("Tags",
25
- :type => :hash,
26
- :key_type => :short_text,
27
- :default_tokenizer => :delimit) do |table|
28
- table.text("name")
29
- end
30
-
31
- schema.create_table("Users",
32
- :type => :hash,
33
- :key_type => "ShortText") do |table|
34
- table.text("name")
35
- end
36
-
37
- schema.create_table("Posts") do |table|
38
- table.text("title")
39
- table.reference("author", "Users")
40
- table.integer("rank")
41
- table.unsigned_integer("n_goods")
42
- table.short_text("tag_text")
43
- table.reference("tags", "Tags", :type => :vector)
44
- table.boolean("published")
45
- table.time("created_at")
46
- end
47
-
48
- schema.change_table("Users") do |table|
49
- table.index("Posts.author")
50
- end
51
-
52
- schema.change_table("Tags") do |table|
53
- table.index("Posts.tag_text")
54
- end
55
- end
56
- end
57
-
58
- private
59
- def dump(options={})
60
- Groonga::DatabaseDumper.new(options).dump
61
- end
62
-
63
- def posts
64
- context["Posts"]
65
- end
66
-
67
- def dumped_schema
68
- <<-EOS
69
- table_create Posts TABLE_NO_KEY
70
- column_create Posts created_at COLUMN_SCALAR Time
71
- column_create Posts n_goods COLUMN_SCALAR UInt32
72
- column_create Posts published COLUMN_SCALAR Bool
73
- column_create Posts rank COLUMN_SCALAR Int32
74
- column_create Posts tag_text COLUMN_SCALAR ShortText
75
- column_create Posts title COLUMN_SCALAR Text
76
-
77
- table_create Tags TABLE_HASH_KEY --key_type ShortText --default_tokenizer TokenDelimit
78
- column_create Tags name COLUMN_SCALAR Text
79
-
80
- table_create Users TABLE_HASH_KEY --key_type ShortText
81
- column_create Users name COLUMN_SCALAR Text
82
-
83
- column_create Posts author COLUMN_SCALAR Users
84
- column_create Posts tags COLUMN_VECTOR Tags
85
-
86
- column_create Tags Posts_tag_text COLUMN_INDEX Posts tag_text
87
-
88
- column_create Users Posts_author COLUMN_INDEX Posts author
89
- EOS
90
- end
91
-
92
- class EmptyTest < DatabaseDumperTest
93
- def test_default
94
- assert_equal(dumped_schema, dump)
95
- end
96
- end
97
-
98
- class HaveDataTest < DatabaseDumperTest
99
- setup
100
- def setup_data
101
- posts.add(:author => "mori",
102
- :created_at => Time.parse("2010-03-08 16:52 JST"),
103
- :n_goods => 4,
104
- :published => true,
105
- :rank => 10,
106
- :tag_text => "search mori",
107
- :tags => ["search", "mori"],
108
- :title => "Why search engine find?")
109
- end
110
-
111
- def test_default
112
- assert_equal(<<-EOS, dump)
113
- #{dumped_schema.chomp}
114
-
115
- load --table Posts
116
- [
117
- ["_id","author","created_at","n_goods","published","rank","tag_text","tags","title"],
118
- [1,"mori",1268034720.0,4,true,10,"search mori",["search","mori"],"Why search engine find?"]
119
- ]
120
-
121
- load --table Tags
122
- [
123
- ["_key","name"],
124
- ["search",""],
125
- ["mori",""]
126
- ]
127
-
128
- load --table Users
129
- [
130
- ["_key","name"],
131
- ["mori",""]
132
- ]
133
- EOS
134
- end
135
-
136
- def test_limit_tables
137
- assert_equal(<<-EOS, dump(:tables => ["Posts"]))
138
- #{dumped_schema.chomp}
139
-
140
- load --table Posts
141
- [
142
- ["_id","author","created_at","n_goods","published","rank","tag_text","tags","title"],
143
- [1,"mori",1268034720.0,4,true,10,"search mori",["search","mori"],"Why search engine find?"]
144
- ]
145
- EOS
146
- end
147
-
148
- def test_limit_tables_with_regexp
149
- assert_equal(<<-EOS, dump(:tables => [/Posts?/]))
150
- #{dumped_schema.chomp}
151
-
152
- load --table Posts
153
- [
154
- ["_id","author","created_at","n_goods","published","rank","tag_text","tags","title"],
155
- [1,"mori",1268034720.0,4,true,10,"search mori",["search","mori"],"Why search engine find?"]
156
- ]
157
- EOS
158
- end
159
-
160
- def test_exclude_tables
161
- dump_options = {
162
- :exclude_tables => ["Posts"],
163
- }
164
- assert_equal(<<-EOS, dump(dump_options))
165
- #{dumped_schema.chomp}
166
-
167
- load --table Tags
168
- [
169
- ["_key","name"],
170
- ["search",""],
171
- ["mori",""]
172
- ]
173
-
174
- load --table Users
175
- [
176
- ["_key","name"],
177
- ["mori",""]
178
- ]
179
- EOS
180
- end
181
-
182
- def test_exclude_tables_with_regexp
183
- dump_options = {
184
- :exclude_tables => [/Posts?/],
185
- }
186
- assert_equal(<<-EOS, dump(dump_options))
187
- #{dumped_schema.chomp}
188
-
189
- load --table Tags
190
- [
191
- ["_key","name"],
192
- ["search",""],
193
- ["mori",""]
194
- ]
195
-
196
- load --table Users
197
- [
198
- ["_key","name"],
199
- ["mori",""]
200
- ]
201
- EOS
202
- end
203
-
204
- def test_tables_combination
205
- dump_options = {
206
- :exclude_tables => ["Posts"],
207
- :tables => ["Posts", "Users"],
208
- }
209
- assert_equal(<<-EOS, dump(dump_options))
210
- #{dumped_schema.chomp}
211
-
212
- load --table Users
213
- [
214
- ["_key","name"],
215
- ["mori",""]
216
- ]
217
- EOS
218
- end
219
-
220
- def test_no_schema
221
- assert_equal(<<-EOS, dump(:dump_schema => false))
222
- load --table Posts
223
- [
224
- ["_id","author","created_at","n_goods","published","rank","tag_text","tags","title"],
225
- [1,"mori",1268034720.0,4,true,10,"search mori",["search","mori"],"Why search engine find?"]
226
- ]
227
-
228
- load --table Tags
229
- [
230
- ["_key","name"],
231
- ["search",""],
232
- ["mori",""]
233
- ]
234
-
235
- load --table Users
236
- [
237
- ["_key","name"],
238
- ["mori",""]
239
- ]
240
- EOS
241
- end
242
-
243
- def test_no_tables
244
- assert_equal(<<-EOS, dump(:dump_tables => false))
245
- #{dumped_schema.chomp}
246
- EOS
247
- end
248
- end
249
-
250
- class PluginTest < DatabaseDumperTest
251
- def test_standard_plugin
252
- Groonga::Plugin.register("suggest/suggest")
253
- assert_equal("register suggest/suggest\n" +
254
- "\n" +
255
- dumped_schema,
256
- dump)
257
- end
258
- end
259
- end