rroonga 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/README.textile +71 -0
  2. data/Rakefile +213 -128
  3. data/TODO +0 -0
  4. data/example/bookmark.rb +12 -12
  5. data/ext/groonga/Makefile +233 -0
  6. data/ext/groonga/extconf.rb +1 -1
  7. data/ext/groonga/rb-grn-column.c +5 -5
  8. data/ext/groonga/rb-grn-index-column.c +31 -0
  9. data/ext/groonga/rb-grn-index-cursor.c +106 -0
  10. data/ext/groonga/rb-grn-logger.c +5 -5
  11. data/ext/groonga/rb-grn-object.c +48 -0
  12. data/ext/groonga/rb-grn-patricia-trie.c +1 -1
  13. data/ext/groonga/rb-grn-plugin.c +32 -0
  14. data/ext/groonga/rb-grn-posting.c +51 -0
  15. data/ext/groonga/rb-grn-table-cursor.c +6 -1
  16. data/ext/groonga/rb-grn-table.c +31 -13
  17. data/ext/groonga/rb-grn.h +21 -3
  18. data/ext/groonga/rb-groonga.c +3 -1
  19. data/lib/groonga.rb +1 -0
  20. data/lib/groonga/dumper.rb +25 -5
  21. data/lib/groonga/expression-builder.rb +2 -2
  22. data/lib/groonga/pagination.rb +99 -7
  23. data/lib/groonga/posting.rb +87 -0
  24. data/lib/groonga/record.rb +118 -11
  25. data/lib/groonga/schema.rb +18 -1
  26. data/test/groonga-test-utils.rb +1 -6
  27. data/test/run-test.rb +13 -28
  28. data/test/test-column.rb +4 -0
  29. data/test/test-database-dumper.rb +53 -10
  30. data/test/test-hash.rb +6 -6
  31. data/test/test-index-cursor.rb +93 -0
  32. data/test/test-plugin.rb +6 -0
  33. data/test/test-record.rb +162 -1
  34. data/test/test-schema-type.rb +6 -0
  35. data/test/test-schema.rb +17 -0
  36. data/test/test-table.rb +7 -2
  37. data/test/test-type.rb +9 -1
  38. metadata +135 -245
  39. data/AUTHORS +0 -5
  40. data/NEWS.ja.rdoc +0 -344
  41. data/NEWS.rdoc +0 -346
  42. data/README.ja.rdoc +0 -68
  43. data/README.rdoc +0 -68
  44. data/example/search/config.ru +0 -230
  45. data/example/search/public/css/groonga.css +0 -122
  46. data/ext/.gitignore +0 -2
  47. data/html/bar.svg +0 -153
  48. data/html/developer.html +0 -151
  49. data/html/developer.svg +0 -469
  50. data/html/download.svg +0 -253
  51. data/html/favicon.ico +0 -0
  52. data/html/favicon.svg +0 -591
  53. data/html/footer.html.erb +0 -33
  54. data/html/head.html.erb +0 -4
  55. data/html/header.html.erb +0 -17
  56. data/html/heading-mark.svg +0 -393
  57. data/html/index.html +0 -243
  58. data/html/install.svg +0 -636
  59. data/html/logo.svg +0 -612
  60. data/html/ranguba.css +0 -342
  61. data/html/readme.svg +0 -256
  62. data/html/tutorial.svg +0 -559
  63. data/license/LGPL +0 -504
  64. data/test-unit-notify/Rakefile +0 -47
  65. data/test-unit-notify/lib/test/unit/notify.rb +0 -104
  66. data/test-unit/COPYING +0 -56
  67. data/test-unit/GPL +0 -340
  68. data/test-unit/PSFL +0 -271
  69. data/test-unit/Rakefile +0 -53
  70. data/test-unit/TODO +0 -5
  71. data/test-unit/bin/testrb +0 -5
  72. data/test-unit/html/bar.svg +0 -153
  73. data/test-unit/html/developer.svg +0 -469
  74. data/test-unit/html/favicon.ico +0 -0
  75. data/test-unit/html/favicon.svg +0 -82
  76. data/test-unit/html/heading-mark.svg +0 -393
  77. data/test-unit/html/index.html +0 -247
  78. data/test-unit/html/index.html.ja +0 -270
  79. data/test-unit/html/install.svg +0 -636
  80. data/test-unit/html/logo.svg +0 -483
  81. data/test-unit/html/test-unit.css +0 -339
  82. data/test-unit/html/tutorial.svg +0 -559
  83. data/test-unit/lib/test/unit.rb +0 -328
  84. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
  85. data/test-unit/lib/test/unit/assertions.rb +0 -1334
  86. data/test-unit/lib/test/unit/attribute.rb +0 -125
  87. data/test-unit/lib/test/unit/autorunner.rb +0 -363
  88. data/test-unit/lib/test/unit/collector.rb +0 -36
  89. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  90. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  91. data/test-unit/lib/test/unit/collector/load.rb +0 -144
  92. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  93. data/test-unit/lib/test/unit/color-scheme.rb +0 -106
  94. data/test-unit/lib/test/unit/color.rb +0 -96
  95. data/test-unit/lib/test/unit/diff.rb +0 -740
  96. data/test-unit/lib/test/unit/error.rb +0 -130
  97. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  98. data/test-unit/lib/test/unit/failure.rb +0 -136
  99. data/test-unit/lib/test/unit/fixture.rb +0 -176
  100. data/test-unit/lib/test/unit/notification.rb +0 -129
  101. data/test-unit/lib/test/unit/omission.rb +0 -191
  102. data/test-unit/lib/test/unit/pending.rb +0 -150
  103. data/test-unit/lib/test/unit/priority.rb +0 -180
  104. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  105. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  106. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  107. data/test-unit/lib/test/unit/testcase.rb +0 -483
  108. data/test-unit/lib/test/unit/testresult.rb +0 -121
  109. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  110. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  111. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -430
  112. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
  113. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -82
  114. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -53
  115. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  116. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  117. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -42
  118. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  119. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  120. data/test-unit/lib/test/unit/util/output.rb +0 -31
  121. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  122. data/test-unit/lib/test/unit/version.rb +0 -7
  123. data/test-unit/sample/adder.rb +0 -13
  124. data/test-unit/sample/subtracter.rb +0 -12
  125. data/test-unit/sample/test_adder.rb +0 -20
  126. data/test-unit/sample/test_subtracter.rb +0 -20
  127. data/test-unit/sample/test_user.rb +0 -23
  128. data/test-unit/test/collector/test-descendant.rb +0 -133
  129. data/test-unit/test/collector/test-load.rb +0 -442
  130. data/test-unit/test/collector/test_dir.rb +0 -406
  131. data/test-unit/test/collector/test_objectspace.rb +0 -100
  132. data/test-unit/test/run-test.rb +0 -15
  133. data/test-unit/test/test-attribute.rb +0 -86
  134. data/test-unit/test/test-color-scheme.rb +0 -69
  135. data/test-unit/test/test-color.rb +0 -47
  136. data/test-unit/test/test-diff.rb +0 -518
  137. data/test-unit/test/test-emacs-runner.rb +0 -60
  138. data/test-unit/test/test-fixture.rb +0 -287
  139. data/test-unit/test/test-notification.rb +0 -33
  140. data/test-unit/test/test-omission.rb +0 -81
  141. data/test-unit/test/test-pending.rb +0 -70
  142. data/test-unit/test/test-priority.rb +0 -119
  143. data/test-unit/test/test-testcase.rb +0 -544
  144. data/test-unit/test/test_assertions.rb +0 -1197
  145. data/test-unit/test/test_error.rb +0 -26
  146. data/test-unit/test/test_failure.rb +0 -33
  147. data/test-unit/test/test_testresult.rb +0 -113
  148. data/test-unit/test/test_testsuite.rb +0 -129
  149. data/test-unit/test/testunit-test-util.rb +0 -14
  150. data/test-unit/test/ui/test_tap.rb +0 -33
  151. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  152. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  153. data/test-unit/test/util/test-output.rb +0 -11
  154. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  155. data/test-unit/test/util/test_observable.rb +0 -102
  156. data/test-unit/test/util/test_procwrapper.rb +0 -36
  157. data/test/.gitignore +0 -1
  158. data/text/expression.rdoc +0 -285
  159. data/text/tutorial.ja.rdoc +0 -433
@@ -27,7 +27,7 @@ module Groonga
27
27
 
28
28
  VALID_COLUMN_NAME_RE = /\A[a-zA-Z\d_]+\z/
29
29
 
30
- def initialize(*args)
30
+ def initialize
31
31
  @table = nil
32
32
  @name = nil
33
33
  @query = nil
@@ -445,7 +445,7 @@ module Groonga
445
445
  end
446
446
  if object.range != @table
447
447
  raise ArgumentError,
448
- "differenct index column: <#{name}>: #{object.inspect}"
448
+ "different index column: <#{name}>: #{object.inspect}"
449
449
  end
450
450
  column_expression_builder(object, name)
451
451
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2010-2011 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,13 @@
17
17
 
18
18
  module Groonga
19
19
  class TooSmallPage < Error
20
- attr_reader :page, :available_pages
20
+ # Table#paginate で小さすぎるページ番号を指定した場合に
21
+ # 発生する。
22
+
23
+ # 指定したページ番号。
24
+ attr_reader :page
25
+ # 有効なページ。Range。
26
+ attr_reader :available_pages
21
27
  def initialize(page, available_pages)
22
28
  @page = page
23
29
  @available_pages = available_pages
@@ -27,7 +33,13 @@ module Groonga
27
33
  end
28
34
 
29
35
  class TooLargePage < Error
30
- attr_reader :page, :available_pages
36
+ # Table#paginate で大きすぎるページ番号を指定した場合に
37
+ # 発生する。
38
+
39
+ # 指定したページ番号。
40
+ attr_reader :page
41
+ # 有効なページ。Range。
42
+ attr_reader :available_pages
31
43
  def initialize(page, available_pages)
32
44
  @page = page
33
45
  @available_pages = available_pages
@@ -37,7 +49,13 @@ module Groonga
37
49
  end
38
50
 
39
51
  class TooSmallPageSize < Error
40
- attr_reader :page_size, :available_page_sizes
52
+ # Table#paginate で小さすぎるページサイズを指定した場合
53
+ # に発生する。
54
+
55
+ # 指定したページサイズ。
56
+ attr_reader :page_size
57
+ # 有効なページサイズ。Range。
58
+ attr_reader :available_page_sizes
41
59
  def initialize(page_size, available_page_sizes)
42
60
  @page_size = page_size
43
61
  @available_page_sizes = available_page_sizes
@@ -47,6 +65,44 @@ module Groonga
47
65
  end
48
66
 
49
67
  class Table
68
+
69
+ # ページネーション用便利メソッド。ページネーションをした
70
+ # い場合は #sort よりも #paginate の方が便利。
71
+ #
72
+ # 説明文(descriptionカラム)を「Ruby」で全文検索し、検
73
+ # 索結果をスコアの高い順にソートして、10項目ずつ表示する
74
+ # 場合は以下のようになる。
75
+ #
76
+ # query = "Ruby"
77
+ # entries = Groonga["entries"]
78
+ # selected_entries = entries.select do |record|
79
+ # entry.description =~ query
80
+ # end
81
+ # paged_entries = selected_entries.paginate(["_score", :desc],
82
+ # :page => 1,
83
+ # :size => 10)
84
+ #
85
+ # #sort と違い、返されるTableオブジェクトにはPagination
86
+ # モジュールがextendされており、以下のようにページネーショ
87
+ # ン情報を取得できる。
88
+ #
89
+ # puts "#{paged_entries.n_records}件ヒット"
90
+ # puts "#{paged_entries.start_offset}-#{paged_entries.end_offset}件を表示"
91
+ # paged_entries.each do |entry|
92
+ # puts entry.description
93
+ # end
94
+ #
95
+ # _sort_keys_ には ソートに用いる情報を指定する。
96
+ # 指定の仕方は #sort と同様なので、詳細は #sort を参照。
97
+ #
98
+ # _options_に指定可能な値は以下の通り。
99
+ #
100
+ # [+:size+]
101
+ # 1ページあたりに表示する最大項目数。デフォルトは10。
102
+ #
103
+ # [+:page+]
104
+ # ページ番号。ページ番号は0ベースではなく1ベースである
105
+ # ことに注意。デフォルトは1ページ目。
50
106
  def paginate(sort_keys, options={})
51
107
  _size = size
52
108
  page_size = options[:size] || 10
@@ -74,60 +130,96 @@ module Groonga
74
130
 
75
131
  # ページネーション機能を追加するモジュール。
76
132
  #
77
- # ページ番号など、0ベースではなく1ベースです。
133
+ # ページ番号やレコードが何番目かは0ベースではなく1ベースで
134
+ # あることに注意すること。
78
135
  module Pagination
79
- attr_reader :current_page, :page_size, :n_pages, :n_records
80
-
136
+ # 現在のページ番号。
137
+ attr_reader :current_page
138
+ # 1ページあたりのレコード数。
139
+ attr_reader :page_size
140
+ # 全ページ数。
141
+ attr_reader :n_pages
142
+ # 全レコード数。
143
+ attr_reader :n_records
144
+
145
+ # 2ページ以上ある場合は+true+を返す。
81
146
  def have_pages?
82
147
  @n_pages > 1
83
148
  end
84
149
 
150
+ # 最初のページ番号。常に1を返す。
85
151
  def first_page
86
152
  1
87
153
  end
88
154
 
155
+ # 現在のページが最初のページなら+true+を返す。
89
156
  def first_page?
90
157
  @current_page == first_page
91
158
  end
92
159
 
160
+ # 最後のページ番号。
93
161
  def last_page
94
162
  @n_pages
95
163
  end
96
164
 
165
+ # 現在のページが最後のページなら+true+を返す。
97
166
  def last_page?
98
167
  @current_page == last_page
99
168
  end
100
169
 
170
+ # 次のページがあるなら+true+を返す。
101
171
  def have_next_page?
102
172
  @current_page < @n_pages
103
173
  end
104
174
 
175
+ # 次のページ番号を返す。次のページがない場合は+nil+を返
176
+ # す。
105
177
  def next_page
106
178
  have_next_page? ? @current_page + 1 : nil
107
179
  end
108
180
 
181
+ # 前のページがあるなら+true+を返す。
109
182
  def have_previous_page?
110
183
  @current_page > 1
111
184
  end
112
185
 
186
+ # 前のページ番号を返す。前のページがない場合は+nil+を返
187
+ # す。
113
188
  def previous_page
114
189
  have_previous_page? ? @current_page - 1 : nil
115
190
  end
116
191
 
192
+ # 1ページあたりのレコード数を返す。
117
193
  def n_records_in_page
118
194
  size
119
195
  end
120
196
 
197
+ # 現在のページに含まれているレコードのうち、先頭のレコー
198
+ # ドが何番目のレコードかを返す。0ベースではなく1ベースで
199
+ # あることに注意。つまり、最初のレコードは0番目のレコー
200
+ # ドではなく、1番目のレコードになる。
201
+ #
202
+ # レコードが1つもない場合は+nil+を返す。
121
203
  def start_offset
122
204
  return nil if @n_records.zero?
123
205
  1 + (@current_page - 1) * @page_size
124
206
  end
125
207
 
208
+ # 現在のページに含まれているレコードのうち、最後のレコー
209
+ # ドが何番目のレコードかを返す。0ベースではなく1ベースで
210
+ # あることに注意。つまり、最初のレコードは0番目のレコー
211
+ # ドではなく、1番目のレコードになる。
212
+ #
213
+ # レコードが1つもない場合は+nil+を返す。
126
214
  def end_offset
127
215
  return nil if @n_records.zero?
128
216
  [start_offset + @page_size - 1, @n_records].min
129
217
  end
130
218
 
219
+ # 最初のページから最後のページまでを含んだRangeを返す。
220
+ #
221
+ # 例えば、10ページある場合は以下を返す。
222
+ # 1..10
131
223
  def pages
132
224
  first_page..last_page
133
225
  end
@@ -0,0 +1,87 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 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
+ require 'English'
19
+
20
+ module Groonga
21
+ # This class keeps posting information.
22
+ #
23
+ # @since 1.2.1
24
+ class Posting
25
+ # The record ID.
26
+ attr_accessor :record_id
27
+
28
+ # The section ID.
29
+ attr_accessor :section_id
30
+
31
+ # The term ID.
32
+ attr_accessor :term_id
33
+
34
+ # The position.
35
+ attr_accessor :position
36
+
37
+ # The term frequency.
38
+ attr_accessor :term_frequency
39
+
40
+ # The weight.
41
+ attr_accessor :weight
42
+
43
+ # The number of rest posting information for the term ID.
44
+ attr_accessor :n_rest_postings
45
+
46
+ # Creates a new Posting.
47
+ #
48
+ # @return The new Posting.
49
+ def initialize(parameters=nil)
50
+ update(parameters || {})
51
+ end
52
+
53
+ # Updates all values.
54
+ #
55
+ # @param [Hash] parameters The name and value
56
+ # pairs. Omitted names are initialized as the default value.
57
+ # @option parameters [Integer] :record_id The record_id.
58
+ # @option parameters [Integer] :section_id The section_id.
59
+ # @option parameters [Integer] :term_id The term_id.
60
+ # @option parameters [Integer] :position The position.
61
+ # @option parameters [Integer] :term_frequency The term_frequency.
62
+ # @option parameters [Integer] :weight The weight.
63
+ # @option parameters [Integer] :n_rest_postings The n_rest_postings.
64
+ def update(parameters)
65
+ @record_id = parameters[:record_id] || nil
66
+ @section_id = parameters[:section_id] || nil
67
+ @term_id = parameters[:term_id] || nil
68
+ @position = parameters[:position] || 0
69
+ @term_frequency = parameters[:term_frequency] || 0
70
+ @weight = parameters[:weight] || 0
71
+ @n_rest_postings = parameters[:n_rest_postings] || 0
72
+ end
73
+
74
+ # Returns Hash created from attributes.
75
+ def to_hash
76
+ {
77
+ :record_id => @record_id,
78
+ :section_id => @section_id,
79
+ :term_id => @term_id,
80
+ :position => @position,
81
+ :term_frequency => @term_frequency,
82
+ :weight => @weight,
83
+ :n_rest_postings => @n_rest_postings
84
+ }
85
+ end
86
+ end
87
+ end
@@ -215,6 +215,15 @@ module Groonga
215
215
  self["_score"]
216
216
  end
217
217
 
218
+ # call-seq:
219
+ # record.support_score? -> true/false
220
+ #
221
+ # Groonga::Record#scoreが利用できる場合はtrueを
222
+ # 返す。
223
+ def support_score?
224
+ @table.have_column?("_score") # TODO delegate to Table
225
+ end
226
+
218
227
  # call-seq:
219
228
  # record.n_sub_records -> 件数
220
229
  #
@@ -285,17 +294,8 @@ module Groonga
285
294
  # 型のカラムでない全カラムを対象とし、カラムの名前をキーとし
286
295
  # たこのレコードのカラムの値のハッシュを返す。
287
296
  def attributes
288
- attributes = {"id" => id}
289
- attributes["key"] = key if support_key?
290
- table_name = @table.name
291
- columns.each do |column|
292
- next if column.is_a?(Groonga::IndexColumn)
293
- value = column[@id]
294
- # TODO: support recursive reference.
295
- value = value.attributes if value.is_a?(Groonga::Record)
296
- attributes[column.local_name] = value
297
- end
298
- attributes
297
+ accessor = AttributeHashBuilder.new(self)
298
+ accessor.build
299
299
  end
300
300
 
301
301
  # call-seq:
@@ -408,5 +408,112 @@ module Groonga
408
408
  super
409
409
  end
410
410
  end
411
+
412
+ class AttributeHashBuilder # :nodoc:
413
+ attr_reader :attributes
414
+
415
+ def initialize(root_record)
416
+ @root_record = root_record
417
+ @built_records = []
418
+ end
419
+
420
+ def build
421
+ build_attributes(@root_record)
422
+ end
423
+
424
+ private
425
+ def build_attributes(record)
426
+ building(record) do
427
+ attributes = create_attributes(record)
428
+ add_key(attributes, record)
429
+ add_score(attributes, record)
430
+ add_n_sub_records(attributes, record)
431
+ add_columns(attributes, record)
432
+
433
+ attributes
434
+ end
435
+ end
436
+
437
+ def build_recursive_attributes(record)
438
+ attributes = create_attributes(record)
439
+ add_table(attributes, record)
440
+ add_key(attributes, record)
441
+
442
+ attributes
443
+ end
444
+
445
+ def build_value(value)
446
+ if value.is_a?(Record)
447
+ if recursive?(value)
448
+ build_recursive_attributes(value)
449
+ else
450
+ build_attributes(value)
451
+ end
452
+ else
453
+ value
454
+ end
455
+ end
456
+
457
+ def build_vector(vector)
458
+ vector.collect do |element|
459
+ build_value(element)
460
+ end
461
+ end
462
+
463
+ def create_attributes(record)
464
+ {"_id" => record.id}
465
+ end
466
+
467
+ def add_table(attributes, record)
468
+ attributes["_table"] = record.table.name
469
+ end
470
+
471
+ def add_columns(attributes, record)
472
+ record.columns.each do |column|
473
+ next if column.is_a?(IndexColumn)
474
+
475
+ value = column[record.id]
476
+ attributes[column.local_name] = build_column(column, value)
477
+ end
478
+ end
479
+
480
+ def build_column(column, value)
481
+ if column.vector?
482
+ build_vector(value)
483
+ else
484
+ build_value(value)
485
+ end
486
+ end
487
+
488
+ def add_key(attributes, record)
489
+ if record.support_key?
490
+ attributes["_key"] = build_value(record.key)
491
+ end
492
+ end
493
+
494
+ def add_score(attributes, record)
495
+ if record.support_score?
496
+ attributes["_score"] = record.score
497
+ end
498
+ end
499
+
500
+ def add_n_sub_records(attributes, record)
501
+ if record.support_sub_records?
502
+ attributes["_nsubrecs"] = record.n_sub_records
503
+ end
504
+ end
505
+
506
+ def building(record)
507
+ @built_records.push(record)
508
+ returned_object = yield
509
+ @built_records.pop
510
+
511
+ returned_object
512
+ end
513
+
514
+ def recursive?(record)
515
+ @built_records.include?(record)
516
+ end
517
+ end
411
518
  end
412
519
  end
@@ -57,6 +57,15 @@ module Groonga
57
57
  end
58
58
  end
59
59
 
60
+ # カラムが存在しないときに発生する。
61
+ class ColumnNotExists < Error
62
+ attr_reader :name
63
+ def initialize(name)
64
+ @name = name
65
+ super("column doesn't exist: <#{@name}>")
66
+ end
67
+ end
68
+
60
69
  # すでに存在するテーブルと違うオプションでテーブルを作ろ
61
70
  # うとしたときに発生する。
62
71
  class TableCreationWithDifferentOptions < Error
@@ -467,6 +476,8 @@ module Groonga
467
476
  "time" => "Time",
468
477
  "date" => "Time",
469
478
  "boolean" => "Bool",
479
+ "delimit" => "TokenDelimit",
480
+ "token_delimit" => "TokenDelimit",
470
481
  "unigram" => "TokenUnigram",
471
482
  "token_unigram" => "TokenUnigram",
472
483
  "bigram" => "TokenBigram",
@@ -1463,7 +1474,13 @@ module Groonga
1463
1474
  else
1464
1475
  name = @name
1465
1476
  end
1466
- table.column(name).remove
1477
+ column = table.column(name)
1478
+
1479
+ if column.nil?
1480
+ raise ColumnNotExists.new(name)
1481
+ end
1482
+
1483
+ column.remove
1467
1484
  end
1468
1485
  end
1469
1486