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,180 +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 IndexColumnTest < Test::Unit::TestCase
19
- include GroongaTestUtils
20
-
21
- def setup
22
- setup_database
23
- end
24
-
25
- def test_index?
26
- articles = Groonga::Array.create(:name => "Articles")
27
- articles.define_column("content", "Text")
28
-
29
- terms = Groonga::Hash.create(:name => "Terms",
30
- :default_tokenizer => "TokenBigram")
31
- content_index = terms.define_index_column("content", articles,
32
- :with_section => true)
33
- assert_predicate(content_index, :index?)
34
- end
35
-
36
- def test_vector?
37
- articles = Groonga::Array.create(:name => "Articles")
38
- articles.define_column("content", "Text")
39
-
40
- terms = Groonga::Hash.create(:name => "Terms",
41
- :default_tokenizer => "TokenBigram")
42
- content_index = terms.define_index_column("content", articles,
43
- :with_section => true)
44
- assert_not_predicate(content_index, :vector?)
45
- end
46
-
47
- def test_scalar?
48
- articles = Groonga::Array.create(:name => "Articles")
49
- articles.define_column("content", "Text")
50
-
51
- terms = Groonga::Hash.create(:name => "Terms",
52
- :default_tokenizer => "TokenBigram")
53
- content_index = terms.define_index_column("content", articles,
54
- :with_section => true)
55
- assert_not_predicate(content_index, :scalar?)
56
- end
57
-
58
- def test_array_set_with_record
59
- articles = Groonga::Array.create(:name => "Articles")
60
- articles.define_column("content", "Text")
61
-
62
- terms = Groonga::Hash.create(:name => "Terms",
63
- :default_tokenizer => "TokenBigram")
64
- content_index = terms.define_index_column("content", articles,
65
- :with_section => true)
66
-
67
- content = <<-EOC
68
- groonga は組み込み型の全文検索エンジンライブラリです。
69
- DBMSやスクリプト言語処理系等に組み込むことによって、その
70
- 全文検索機能を強化することができます。また、リレーショナ
71
- ルモデルに基づくデータストア機能を内包しており、groonga
72
- 単体でも高速なデータストアサーバとして使用することができ
73
- ます。
74
-
75
- ■全文検索方式
76
- 転置索引型の全文検索エンジンです。転置索引は圧縮されてファ
77
- イルに格納され、検索時のディスク読み出し量を小さく、かつ
78
- 局所的に抑えるように設計されています。用途に応じて以下の
79
- 索引タイプを選択できます。
80
- EOC
81
-
82
- groonga = articles.add(:content => content)
83
-
84
- content.split(/\n{2,}/).each_with_index do |sentence, i|
85
- content_index[groonga] = {:value => sentence, :section => i + 1}
86
- end
87
- assert_equal([groonga],
88
- content_index.search("エンジン").collect {|record| record.key})
89
- end
90
-
91
- def test_shorter_query_than_ngram
92
- articles = Groonga::Array.create(:name => "Articles")
93
- articles.define_column("content", "Text")
94
-
95
- terms = Groonga::PatriciaTrie.create(:name => "Terms",
96
- :default_tokenizer => "TokenBigram")
97
- content_index = terms.define_index_column("content", articles,
98
- :source => "Articles.content")
99
- articles.add(:content => 'l')
100
- articles.add(:content => 'll')
101
- articles.add(:content => 'hello')
102
-
103
- assert_search(["hello"], content_index, "he")
104
- assert_search(["ll", "hello"], content_index, "ll")
105
- assert_search(["l", "ll", "hello"], content_index, "l")
106
- end
107
-
108
- def test_with_section?
109
- define_index_column_with_flags
110
- assert_equal({
111
- :section => true,
112
- :weight => false,
113
- :position => false,
114
- },
115
- {
116
- :section => context["Tags.section"].with_section?,
117
- :weight => context["Tags.weight"].with_section?,
118
- :position => context["Tags.position"].with_section?,
119
- })
120
- end
121
-
122
- def test_with_weight?
123
- define_index_column_with_flags
124
- assert_equal({
125
- :section => false,
126
- :weight => true,
127
- :position => false,
128
- },
129
- {
130
- :section => context["Tags.section"].with_weight?,
131
- :weight => context["Tags.weight"].with_weight?,
132
- :position => context["Tags.position"].with_weight?,
133
- })
134
- end
135
-
136
- def test_with_position?
137
- define_index_column_with_flags
138
- assert_equal({
139
- :section => false,
140
- :weight => false,
141
- :position => true,
142
- },
143
- {
144
- :section => context["Tags.section"].with_position?,
145
- :weight => context["Tags.weight"].with_position?,
146
- :position => context["Tags.position"].with_position?,
147
- })
148
- end
149
-
150
- private
151
- def assert_search(expected, content_index, keyword)
152
- result = content_index.search(keyword).collect do |entry|
153
- entry.key["content"]
154
- end
155
- assert_equal(expected, result)
156
- end
157
-
158
- def define_index_column_with_flags
159
- Groonga::Schema.define do |schema|
160
- schema.create_table("Articles") do |table|
161
- table.text("tags", :type => :vector)
162
- end
163
-
164
- schema.create_table("Tags",
165
- :type => :patricia_trie,
166
- :key_type => "ShortText",
167
- :default_tokenizer => "TokenDelimit") do |table|
168
- table.index("Articles.tags",
169
- :name => "section",
170
- :with_section => true)
171
- table.index("Articles.tags",
172
- :name => "weight",
173
- :with_weight => true)
174
- table.index("Articles.tags",
175
- :name => "position",
176
- :with_position => true)
177
- end
178
- end
179
- end
180
- end
@@ -1,93 +0,0 @@
1
- class IndexCursorTest < Test::Unit::TestCase
2
- include GroongaTestUtils
3
-
4
- def setup
5
- setup_database
6
- setup_schema
7
- setup_records
8
- end
9
-
10
- def test_open_cursor
11
- postings = []
12
- @terms.open_cursor do |table_cursor|
13
- index_cursor = nil
14
- @content_index.open_cursor(table_cursor) do |cursor|
15
- cursor.each do |posting|
16
- postings << posting.to_hash
17
- end
18
- index_cursor = cursor
19
- end
20
- assert_predicate(index_cursor, :closed?)
21
- end
22
-
23
- assert_equal(expected_postings, postings)
24
- end
25
-
26
- def test_enumerable
27
- postings = nil
28
- @terms.open_cursor do |table_cursor|
29
- @content_index.open_cursor(table_cursor) do |cursor|
30
- postings = cursor.collect do |posting|
31
- posting.to_hash
32
- end
33
- end
34
- end
35
-
36
- assert_equal(expected_postings, postings)
37
- end
38
-
39
- private
40
- def create_hashes(keys, values)
41
- hashes = []
42
- values.each do |value|
43
- hash = {}
44
- keys.each_with_index do |key, i|
45
- hash[key] = value[i]
46
- end
47
- hashes << hash
48
- end
49
- hashes
50
- end
51
-
52
- def setup_schema
53
- Groonga::Schema.define do |schema|
54
- schema.create_table("Articles") do |table|
55
- table.text("content")
56
- end
57
-
58
- schema.create_table("Terms",
59
- :type => :hash,
60
- :default_tokenizer => :bigram_split_symbol_alpha) do |table|
61
- table.index("Articles.content")
62
- end
63
- end
64
-
65
- @articles = Groonga["Articles"]
66
- @terms = Groonga["Terms"]
67
- @content_index = Groonga["Terms.Articles_content"]
68
- end
69
-
70
- def setup_records
71
- @articles.add(:content => "l")
72
- @articles.add(:content => "ll")
73
- @articles.add(:content => "hello")
74
- end
75
-
76
- def expected_postings
77
- parameters = [:record_id, :section_id, :term_id, :position,
78
- :term_frequency, :weight, :n_rest_postings]
79
-
80
- expected = [
81
- [1, 1, 1, 0, 1, 0, 1],
82
- [2, 1, 1, 0, 1, 0, 1],
83
- [2, 1, 2, 0, 1, 0, 1],
84
- [3, 1, 2, 0, 1, 0, 1],
85
- [3, 1, 3, 0, 1, 0, 0],
86
- [3, 1, 4, 1, 1, 0, 0],
87
- [3, 1, 5, 3, 1, 0, 0],
88
- [3, 1, 6, 4, 1, 0, 0]
89
- ]
90
-
91
- create_hashes(parameters, expected)
92
- end
93
- end
data/test/test-logger.rb DELETED
@@ -1,37 +0,0 @@
1
- # Copyright (C) 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
- class LoggerTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- def setup
20
- @default_log_path = Groonga::Logger.log_path
21
- @default_query_log_path = Groonga::Logger.query_log_path
22
- end
23
-
24
- def teardown
25
- Groonga::Logger.log_path = @default_log_path
26
- Groonga::Logger.query_log_path = @default_query_log_path
27
- end
28
-
29
- def test_reopen
30
- if File.exist?(@default_log_path)
31
- FileUtils.mv(@default_log_path, "#{@default_log_path}.old")
32
- end
33
- assert_false(File.exist?(@default_log_path))
34
- Groonga::Logger.reopen
35
- assert_true(File.exist?(@default_log_path))
36
- end
37
- end
@@ -1,249 +0,0 @@
1
- # Copyright (C) 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
- class PaginationTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- setup :setup_database
20
-
21
- setup
22
- def setup_data
23
- Groonga::Schema.define do |schema|
24
- schema.create_table("Users",
25
- :type => :hash,
26
- :key_type => "ShortText") do |table|
27
- table.uint32(:number)
28
- end
29
- end
30
- @users = context["Users"]
31
- 150.times do |i|
32
- @users.add("user#{i + 1}", :number => i + 1)
33
- end
34
- end
35
-
36
- def test_default
37
- assert_paginate({
38
- :current_page => 1,
39
- :page_size => 10,
40
- :n_pages => 15,
41
- :n_records => 150,
42
- :start_offset => 1,
43
- :end_offset => 10,
44
- :have_previous_page? => false,
45
- :previous_page => nil,
46
- :have_next_page? => true,
47
- :next_page => 2,
48
- :first_page? => true,
49
- :last_page? => false,
50
- :have_pages? => true,
51
- })
52
- end
53
-
54
- def test_no_entries
55
- @users.each do |user|
56
- user.delete
57
- end
58
- assert_paginate({
59
- :current_page => 1,
60
- :page_size => 10,
61
- :n_pages => 1,
62
- :n_records => 0,
63
- :start_offset => nil,
64
- :end_offset => nil,
65
- :have_previous_page? => false,
66
- :previous_page => nil,
67
- :have_next_page? => false,
68
- :next_page => nil,
69
- :first_page? => true,
70
- :last_page? => true,
71
- :have_pages? => false,
72
- :keys => [],
73
- })
74
- end
75
-
76
- def test_page
77
- assert_paginate({
78
- :current_page => 6,
79
- :page_size => 10,
80
- :n_pages => 15,
81
- :n_records => 150,
82
- :start_offset => 51,
83
- :end_offset => 60,
84
- :have_previous_page? => true,
85
- :previous_page => 5,
86
- :have_next_page? => true,
87
- :next_page => 7,
88
- :first_page? => false,
89
- :last_page? => false,
90
- :have_pages? => true,
91
- },
92
- :page => 6)
93
- end
94
-
95
- def test_max_page
96
- assert_paginate({
97
- :current_page => 15,
98
- :page_size => 10,
99
- :n_pages => 15,
100
- :n_records => 150,
101
- :start_offset => 141,
102
- :end_offset => 150,
103
- :have_previous_page? => true,
104
- :previous_page => 14,
105
- :have_next_page? => false,
106
- :next_page => nil,
107
- :first_page? => false,
108
- :last_page? => true,
109
- :have_pages? => true,
110
- },
111
- :page => 15)
112
- end
113
-
114
- def test_too_large_page
115
- assert_raise(Groonga::TooLargePage) do
116
- assert_paginate({},
117
- :page => 16)
118
- end
119
- end
120
-
121
- def test_zero_page
122
- assert_raise(Groonga::TooSmallPage) do
123
- assert_paginate({},
124
- :page => 0)
125
- end
126
- end
127
-
128
- def test_negative_page
129
- assert_raise(Groonga::TooSmallPage) do
130
- assert_paginate({},
131
- :page => -1)
132
- end
133
- end
134
-
135
- def test_size
136
- assert_paginate({
137
- :current_page => 1,
138
- :page_size => 7,
139
- :n_pages => 22,
140
- :n_records => 150,
141
- :start_offset => 1,
142
- :end_offset => 7,
143
- :have_previous_page? => false,
144
- :previous_page => nil,
145
- :have_next_page? => true,
146
- :next_page => 2,
147
- :first_page? => true,
148
- :last_page? => false,
149
- :have_pages? => true,
150
- },
151
- :size => 7)
152
- end
153
-
154
- def test_max_size
155
- assert_paginate({
156
- :current_page => 1,
157
- :page_size => 150,
158
- :n_pages => 1,
159
- :n_records => 150,
160
- :start_offset => 1,
161
- :end_offset => 150,
162
- :have_previous_page? => false,
163
- :previous_page => nil,
164
- :have_next_page? => false,
165
- :next_page => nil,
166
- :first_page? => true,
167
- :last_page? => true,
168
- :have_pages? => false,
169
- },
170
- :size => 150)
171
- end
172
-
173
- def test_too_large_size
174
- assert_paginate({
175
- :current_page => 1,
176
- :page_size => 151,
177
- :n_pages => 1,
178
- :n_records => 150,
179
- :start_offset => 1,
180
- :end_offset => 150,
181
- :have_previous_page? => false,
182
- :previous_page => nil,
183
- :have_next_page? => false,
184
- :next_page => nil,
185
- :first_page? => true,
186
- :last_page? => true,
187
- :have_pages? => false,
188
- },
189
- :size => 151)
190
- end
191
-
192
- def test_zero_size
193
- assert_raise(Groonga::TooSmallPageSize) do
194
- assert_paginate({},
195
- :size => 0)
196
- end
197
- end
198
-
199
- def test_negative_size
200
- assert_raise(Groonga::TooSmallPageSize) do
201
- assert_paginate({},
202
- :size => -1)
203
- end
204
- end
205
-
206
- def test_full
207
- assert_paginate({
208
- :current_page => 2,
209
- :page_size => 50,
210
- :n_pages => 3,
211
- :n_records => 150,
212
- :start_offset => 51,
213
- :end_offset => 100,
214
- :have_previous_page? => true,
215
- :previous_page => 1,
216
- :have_next_page? => true,
217
- :next_page => 3,
218
- :first_page? => false,
219
- :last_page? => false,
220
- :have_pages? => true,
221
- },
222
- :page => 2,
223
- :size => 50)
224
- end
225
-
226
- private
227
- def assert_paginate(expected, options={})
228
- users = @users.paginate([["number"]], options)
229
- if expected[:keys].nil?
230
- range = (expected[:start_offset]..expected[:end_offset])
231
- expected[:keys] = range.collect {|i| "user#{i}"}
232
- end
233
- assert_equal(expected,
234
- :current_page => users.current_page,
235
- :page_size => users.page_size,
236
- :n_pages => users.n_pages,
237
- :n_records => users.n_records,
238
- :start_offset => users.start_offset,
239
- :end_offset => users.end_offset,
240
- :previous_page => users.previous_page,
241
- :have_previous_page? => users.have_previous_page?,
242
- :next_page => users.next_page,
243
- :have_next_page? => users.have_next_page?,
244
- :first_page? => users.first_page?,
245
- :last_page? => users.last_page?,
246
- :have_pages? => users.have_pages?,
247
- :keys => users.collect(&:key))
248
- end
249
- end