rroonga 1.2.9 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Rakefile +1 -0
- data/bin/grntest-log-analyze +123 -0
- data/bin/groonga-query-log-extract +117 -0
- data/ext/groonga/rb-grn-accessor.c +7 -5
- data/ext/groonga/rb-grn-array-cursor.c +1 -1
- data/ext/groonga/rb-grn-array.c +34 -44
- data/ext/groonga/rb-grn-column.c +74 -38
- data/ext/groonga/rb-grn-context.c +19 -15
- data/ext/groonga/rb-grn-database.c +47 -42
- data/ext/groonga/rb-grn-double-array-trie-cursor.c +40 -0
- data/ext/groonga/rb-grn-double-array-trie.c +530 -0
- data/ext/groonga/rb-grn-encoding-support.c +1 -1
- data/ext/groonga/rb-grn-encoding.c +1 -1
- data/ext/groonga/rb-grn-exception.c +1 -1
- data/ext/groonga/rb-grn-expression-builder.c +1 -1
- data/ext/groonga/rb-grn-expression.c +63 -51
- data/ext/groonga/rb-grn-fix-size-column.c +7 -7
- data/ext/groonga/rb-grn-hash-cursor.c +1 -1
- data/ext/groonga/rb-grn-hash.c +42 -39
- data/ext/groonga/rb-grn-index-column.c +35 -31
- data/ext/groonga/rb-grn-index-cursor.c +1 -1
- data/ext/groonga/rb-grn-logger.c +23 -18
- data/ext/groonga/rb-grn-object.c +40 -27
- data/ext/groonga/rb-grn-operator.c +1 -1
- data/ext/groonga/rb-grn-patricia-trie-cursor.c +1 -1
- data/ext/groonga/rb-grn-patricia-trie.c +122 -90
- data/ext/groonga/rb-grn-plugin.c +8 -7
- data/ext/groonga/rb-grn-posting.c +1 -1
- data/ext/groonga/rb-grn-procedure.c +1 -1
- data/ext/groonga/rb-grn-query.c +12 -12
- data/ext/groonga/rb-grn-record.c +1 -1
- data/ext/groonga/rb-grn-snippet.c +26 -19
- data/ext/groonga/rb-grn-table-cursor-key-support.c +1 -1
- data/ext/groonga/rb-grn-table-cursor.c +4 -3
- data/ext/groonga/rb-grn-table-key-support.c +23 -23
- data/ext/groonga/rb-grn-table.c +268 -153
- data/ext/groonga/rb-grn-type.c +11 -7
- data/ext/groonga/rb-grn-utils.c +4 -1
- data/ext/groonga/rb-grn-variable-size-column.c +1 -1
- data/ext/groonga/rb-grn-variable.c +2 -2
- data/ext/groonga/rb-grn-view-accessor.c +1 -1
- data/ext/groonga/rb-grn-view-cursor.c +1 -1
- data/ext/groonga/rb-grn-view-record.c +1 -1
- data/ext/groonga/rb-grn-view.c +43 -34
- data/ext/groonga/rb-grn.h +6 -2
- data/ext/groonga/rb-groonga.c +1 -1
- data/lib/groonga.rb +4 -2
- data/lib/groonga/context.rb +16 -41
- data/lib/groonga/dumper.rb +6 -4
- data/lib/groonga/expression-builder.rb +52 -26
- data/lib/groonga/grntest-log.rb +206 -0
- data/lib/groonga/pagination.rb +21 -19
- data/lib/groonga/patricia-trie.rb +7 -10
- data/lib/groonga/posting.rb +1 -1
- data/lib/groonga/query-log.rb +348 -0
- data/lib/groonga/record.rb +47 -143
- data/lib/groonga/schema.rb +679 -406
- data/lib/groonga/view-record.rb +4 -10
- data/rroonga-build.rb +1 -1
- data/test/test-array.rb +25 -4
- data/test/test-column.rb +8 -8
- data/test/test-database.rb +2 -3
- data/test/test-double-array-trie.rb +164 -0
- data/test/test-expression-builder.rb +2 -2
- data/test/test-expression.rb +10 -9
- data/test/test-gqtp.rb +2 -2
- data/test/test-hash.rb +32 -8
- data/test/test-patricia-trie.rb +34 -10
- data/test/test-query-log.rb +258 -0
- data/test/test-record.rb +6 -5
- data/test/test-schema-create-table.rb +8 -0
- data/test/test-schema.rb +491 -234
- data/test/test-table.rb +17 -24
- metadata +123 -100
- data/ext/groonga/Makefile +0 -233
data/lib/groonga/schema.rb
CHANGED
@@ -24,9 +24,9 @@ module Groonga
|
|
24
24
|
# Groonga::Schemaを使うことにより簡単にテーブルやカラムを
|
25
25
|
# 追加・削除することができる。
|
26
26
|
#
|
27
|
-
# http://qwik.jp/senna/senna2.files/rect4605.png
|
28
|
-
# のようなスキーマを定義する場合は以下のようになる。
|
27
|
+
# !http://qwik.jp/senna/senna2.files/rect4605.png!
|
29
28
|
#
|
29
|
+
# @example 上図のようなスキーマを定義する場合は以下のようになる。
|
30
30
|
# Groonga::Schema.define do |schema|
|
31
31
|
# schema.create_table("Items") do |table|
|
32
32
|
# table.short_text("title")
|
@@ -148,192 +148,252 @@ module Groonga
|
|
148
148
|
|
149
149
|
class << self
|
150
150
|
|
151
|
-
# call-seq:
|
152
|
-
# Groonga::Schema.define(options={}) {|schema| ...}
|
153
|
-
#
|
154
151
|
# スキーマを定義する。ブロックにはGroonga::Schemaオブ
|
155
152
|
# ジェクトがわたるので、そのオブジェクトを利用してスキー
|
156
153
|
# マを定義する。以下の省略形。
|
157
|
-
#
|
154
|
+
# <pre>
|
158
155
|
# schema = Groonga::Scheme.new(options)
|
159
|
-
#
|
156
|
+
# ==...==
|
160
157
|
# schema.define
|
158
|
+
# </pre>
|
159
|
+
# @param [::Hash] options The name and value
|
160
|
+
# pairs. Omitted names are initialized as the default value.
|
161
|
+
# @option options [Groonga::Context] :content (Groonga::Context.default) The context
|
161
162
|
#
|
162
|
-
# _options_に指定可能な値は以下の通り。
|
163
|
-
#
|
164
|
-
# [+:context+]
|
165
163
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
166
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
167
164
|
def define(options={})
|
168
165
|
schema = new(options)
|
169
166
|
yield(schema)
|
170
167
|
schema.define
|
171
168
|
end
|
172
169
|
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
# schema.create_table(name, options) do |table|
|
180
|
-
# ...
|
181
|
-
# end
|
182
|
-
# end
|
183
|
-
#
|
170
|
+
# @example 名前が _name_ のテーブルを作成する。以下の省略形。
|
171
|
+
# Groonga::Schema.define do |schema|
|
172
|
+
# schema.create_table(name, options) do |table|
|
173
|
+
# ...
|
174
|
+
# end
|
175
|
+
# end
|
184
176
|
# ブロックにはGroonga::Schema::TableDefinitionオブジェ
|
185
177
|
# クトがわたるので、そのオブジェクトを利用してテーブル
|
186
178
|
# の詳細を定義する。
|
187
179
|
#
|
188
|
-
# _options_に指定可能な値は以下の通り。
|
189
|
-
#
|
190
|
-
# [
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
#
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
219
|
-
#
|
220
|
-
#
|
221
|
-
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
# [
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
239
|
-
#
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
#
|
251
|
-
#
|
252
|
-
#
|
253
|
-
#
|
254
|
-
#
|
255
|
-
#
|
256
|
-
#
|
257
|
-
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
180
|
+
# _options_ に指定可能な値は以下の通り。
|
181
|
+
# @overload create_table(name, options= {:type => :array}, &block)
|
182
|
+
# @param [::Hash] options The name and value
|
183
|
+
# pairs. Omitted names are initialized as the default value.
|
184
|
+
# @option options :force The force
|
185
|
+
#
|
186
|
+
# +true+ を指定すると既存の同名のテーブルが
|
187
|
+
# 存在していても、強制的にテーブルを作成する。
|
188
|
+
# @option options :type (:array) The type
|
189
|
+
#
|
190
|
+
# テーブルの型を指定する。
|
191
|
+
# +:array+ , +:hash+ , +:patricia_trie+ ,
|
192
|
+
# +:double_array_trie+ のいずれかを指定する。
|
193
|
+
# (:key_typeの項も参照)
|
194
|
+
# @option options [Groonga::Context] :context (Groonga::Context.default) The context
|
195
|
+
#
|
196
|
+
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
197
|
+
# @option options :path The path
|
198
|
+
#
|
199
|
+
# テーブルを保存するパスを指定する。
|
200
|
+
# パスを指定すると永続テーブルになる。
|
201
|
+
# @option options :persistent (true) The persistent
|
202
|
+
#
|
203
|
+
# テーブルを永続テーブルとする。 +:path+ を省略した場合は
|
204
|
+
# パス名は自動的に作成される。デフォルトでは永続テーブルとなる。
|
205
|
+
# @option options :value_type (nil) The value_type
|
206
|
+
#
|
207
|
+
# 値の型を指定する。省略すると値のための領域を確保しない。
|
208
|
+
# 値を保存したい場合は必ず指定すること。
|
209
|
+
# @option options :sub_records The sub_records
|
210
|
+
#
|
211
|
+
# +true+ を指定するとGroonga::Table#groupで
|
212
|
+
# グループ化したときに、Groonga::Record#n_sub_recordsでグループに
|
213
|
+
# 含まれるレコードの件数を取得できる。
|
214
|
+
#
|
215
|
+
# @overload create_table(name, options= {:type => :hash}, &block)
|
216
|
+
# @param [::Hash] options The name and value
|
217
|
+
# pairs. Omitted names are initialized as the default value.
|
218
|
+
# @option options :force The force
|
219
|
+
#
|
220
|
+
# +true+ を指定すると既存の同名のテーブルが
|
221
|
+
# 存在していても、強制的にテーブルを作成する。
|
222
|
+
# @option options :type (:array) The type
|
223
|
+
#
|
224
|
+
# テーブルの型を指定する。
|
225
|
+
# +:array+ , +:hash+ , +:patricia_trie+ ,
|
226
|
+
# +:double_array_trie+ のいずれかを指定する。
|
227
|
+
# (:key_typeの項も参照)
|
228
|
+
# @option options [Groonga::Context] :context (Groonga::Context.default) The context
|
229
|
+
#
|
230
|
+
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
231
|
+
# @option options :path The path
|
232
|
+
#
|
233
|
+
# テーブルを保存するパスを指定する。
|
234
|
+
# パスを指定すると永続テーブルになる。
|
235
|
+
# @option options :persistent (true) The persistent
|
236
|
+
#
|
237
|
+
# テーブルを永続テーブルとする。 +:path+ を省略した場合は
|
238
|
+
# パス名は自動的に作成される。デフォルトでは永続テーブルとなる。
|
239
|
+
# @option options :value_type (nil) The value_type
|
240
|
+
#
|
241
|
+
# 値の型を指定する。省略すると値のための領域を確保しない。
|
242
|
+
# 値を保存したい場合は必ず指定すること。
|
243
|
+
# @option options :sub_records The sub_records
|
244
|
+
#
|
245
|
+
# +true+ を指定するとGroonga::Table#groupで
|
246
|
+
# グループ化したときに、Groonga::Record#n_sub_recordsでグループに
|
247
|
+
# 含まれるレコードの件数を取得できる。
|
248
|
+
# @option options :key_type The key_type
|
249
|
+
#
|
250
|
+
# キーの種類を示すオブジェクトを指定する。
|
251
|
+
# キーの種類には型名("Int32"や"ShortText"など)またはGroonga::Type
|
252
|
+
# またはテーブル(Groonga::Array、Groonga::Hash、
|
253
|
+
# Groonga::PatriciaTrie、Groonga::DoubleArrayTrieの
|
254
|
+
# どれか)を指定する。Groonga::Typeを指定した場合は、その型が示す範囲の
|
255
|
+
# 値をキーとして使用する。ただし、キーの最大サイズは4096バイトで
|
256
|
+
# あるため、Groonga::Type::TEXTやGroonga::Type::LONG_TEXTは使用できない
|
257
|
+
# 。テーブルを指定した場合はレコードIDをキーとして使用する。
|
258
|
+
# 指定したテーブルのGroonga::Recordをキーとして使用することもでき、
|
259
|
+
# その場合は自動的にGroonga::RecordからレコードIDを取得する。
|
260
|
+
# 省略した場合は文字列をキーとして使用する。
|
261
|
+
# この場合、4096バイトまで使用可能である。
|
262
|
+
# @option options :default_tokenizer The default_tokenizer
|
263
|
+
#
|
264
|
+
# Groonga::IndexColumnで
|
265
|
+
# 使用するトークナイザを指定する。デフォルトでは
|
266
|
+
# 何も設定されていないので、テーブルに
|
267
|
+
# Groonga::IndexColumnを定義する場合は<tt>"TokenBigram"</tt>
|
268
|
+
# などを指定する必要がある。
|
269
|
+
# @option options :key_normalize The key_normalize
|
270
|
+
#
|
271
|
+
# +true+ を指定するとキーを正規化する。
|
272
|
+
#
|
273
|
+
# @overload create_table(name, options= {:type => :patricia_trie}, &block)
|
274
|
+
# @param [::Hash] options The name and value
|
275
|
+
# pairs. Omitted names are initialized as the default value.
|
276
|
+
# @option options :force The force
|
277
|
+
#
|
278
|
+
# +true+ を指定すると既存の同名のテーブルが
|
279
|
+
# 存在していても、強制的にテーブルを作成する。
|
280
|
+
# @option options :type (:array) The type
|
281
|
+
#
|
282
|
+
# テーブルの型を指定する。
|
283
|
+
# +:array+ , +:hash+ , +:patricia_trie+ ,
|
284
|
+
# +:double_array_trie+ のいずれかを指定する。
|
285
|
+
# (:key_typeの項も参照)
|
286
|
+
# @option options [Groonga::Context] :context (Groonga::Context.default) The context
|
287
|
+
#
|
288
|
+
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
289
|
+
# @option options :path The path
|
290
|
+
#
|
291
|
+
# テーブルを保存するパスを指定する。
|
292
|
+
# パスを指定すると永続テーブルになる。
|
293
|
+
# @option options :persistent (true) The persistent
|
294
|
+
#
|
295
|
+
# テーブルを永続テーブルとする。 +:path+ を省略した場合は
|
296
|
+
# パス名は自動的に作成される。デフォルトでは永続テーブルとなる。
|
297
|
+
# @option options :value_type (nil) The value_type
|
298
|
+
#
|
299
|
+
# 値の型を指定する。省略すると値のための領域を確保しない。
|
300
|
+
# 値を保存したい場合は必ず指定すること。
|
301
|
+
# @option options :sub_records The sub_records
|
302
|
+
#
|
303
|
+
# +true+ を指定するとGroonga::Table#groupで
|
304
|
+
# グループ化したときに、Groonga::Record#n_sub_recordsでグループに
|
305
|
+
# 含まれるレコードの件数を取得できる。
|
306
|
+
# @option options :key_normalize The key_normalize
|
307
|
+
#
|
308
|
+
# +true+ を指定するとキーを正規化する。
|
309
|
+
# @option options :key_with_sis The key_with_sis
|
310
|
+
#
|
311
|
+
# +true+ を指定するとキーの文字列の
|
312
|
+
# 全suffixが自動的に登録される。
|
261
313
|
def create_table(name, options={}, &block)
|
262
314
|
define do |schema|
|
263
315
|
schema.create_table(name, options, &block)
|
264
316
|
end
|
265
317
|
end
|
266
|
-
|
267
|
-
#
|
268
|
-
#
|
269
|
-
#
|
318
|
+
# 名前が _name_ のテーブルを削除する。
|
319
|
+
# @param options [::Hash] The name and value
|
320
|
+
# pairs. Omitted names are initialized as the default value.
|
321
|
+
# @option options :context (Groonga::Context.default)
|
270
322
|
#
|
271
|
-
# [+:context+]
|
272
323
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
273
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
274
324
|
def remove_table(name, options={})
|
275
325
|
define do |schema|
|
276
326
|
schema.remove_table(name, options)
|
277
327
|
end
|
278
328
|
end
|
279
329
|
|
280
|
-
#
|
281
|
-
#
|
282
|
-
#
|
283
|
-
# 名前が_name_のテーブルを変更する。以下の省略形。
|
284
|
-
#
|
330
|
+
# 名前が _name_ のテーブルを変更する。以下の省略形。
|
331
|
+
# <pre>
|
285
332
|
# Groonga::Schema.define do |schema|
|
286
333
|
# schema.change_table(name, options) do |table|
|
287
|
-
#
|
334
|
+
# ==...==
|
288
335
|
# end
|
289
336
|
# end
|
337
|
+
# </pre>
|
290
338
|
#
|
291
339
|
# ブロックにはGroonga::Schema::TableDefinitionオブジェ
|
292
340
|
# クトがわたるので、そのオブジェクトを利用してテーブル
|
293
341
|
# の詳細を定義する。
|
294
342
|
#
|
295
|
-
#
|
343
|
+
# @param options [::Hash] The name and value
|
344
|
+
# pairs. Omitted names are initialized as the default value.
|
345
|
+
# @option options :context (Groonga::Context.default) The context
|
296
346
|
#
|
297
|
-
# [+:context+]
|
298
347
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
299
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
300
348
|
def change_table(name, options={}, &block)
|
301
349
|
define do |schema|
|
302
350
|
schema.change_table(name, options, &block)
|
303
351
|
end
|
304
352
|
end
|
305
353
|
|
306
|
-
#
|
307
|
-
# Groonga::Schema.create_view(name, options={}) {|view| ...}
|
354
|
+
# (See Groonga::Schema#rename_table)
|
308
355
|
#
|
309
|
-
#
|
356
|
+
# This is a syntax sugar the following code:
|
310
357
|
#
|
358
|
+
# <pre>
|
359
|
+
# Groonga::Schema.define do |schema|
|
360
|
+
# schema.rename_table(current_name, new_name, options)
|
361
|
+
# end
|
362
|
+
# </pre>
|
363
|
+
def rename_table(current_name, new_name, options={})
|
364
|
+
define do |schema|
|
365
|
+
schema.rename_table(current_name, new_name, options)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
# 名前が_name_のビューを作成する。以下の省略形。
|
370
|
+
# <pre>
|
311
371
|
# Groonga::Schema.define do |schema|
|
312
372
|
# schema.create_view(name, options) do |view|
|
313
|
-
#
|
373
|
+
# ==...==
|
314
374
|
# end
|
315
375
|
# end
|
316
|
-
#
|
376
|
+
# </pre>
|
317
377
|
# ブロックにはGroonga::Schema::ViewDefinitionオブジェ
|
318
378
|
# クトがわたるので、そのオブジェクトを利用してビュー
|
319
379
|
# の詳細を定義する。
|
320
380
|
#
|
321
|
-
#
|
381
|
+
# @param options [::Hash] The name and value
|
382
|
+
# pairs. Omitted names are initialized as the default value.
|
383
|
+
# @option options :force The force
|
322
384
|
#
|
323
|
-
#
|
324
|
-
#
|
325
|
-
#
|
385
|
+
# +true+ を指定すると既存の同名のビューが
|
386
|
+
# 存在していても、強制的にビューを作成する。
|
387
|
+
# @option options :context (Groonga::Context.default) The context
|
326
388
|
#
|
327
|
-
# [+:context+]
|
328
389
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
329
|
-
#
|
390
|
+
# @option options :path The path
|
330
391
|
#
|
331
|
-
#
|
332
|
-
#
|
333
|
-
#
|
392
|
+
# ビューを保存するパスを指定する。
|
393
|
+
# パスを指定すると永続ビューになる。
|
394
|
+
# @option options :persistent (true) The persistent
|
334
395
|
#
|
335
|
-
#
|
336
|
-
# ビューを永続ビューとする。+:path:+を省略した場
|
396
|
+
# ビューを永続ビューとする。 +:path:+ を省略した場
|
337
397
|
# 合はパス名は自動的に作成される。デフォルトでは永続
|
338
398
|
# ビューとなる。
|
339
399
|
def create_view(name, options={}, &block)
|
@@ -342,48 +402,42 @@ module Groonga
|
|
342
402
|
end
|
343
403
|
end
|
344
404
|
|
345
|
-
# 名前が_name_のテーブルを削除する。
|
346
|
-
#
|
347
|
-
# _options_に指定可能な値は以下の通り。
|
405
|
+
# 名前が _name_ のテーブルを削除する。
|
348
406
|
#
|
349
|
-
# [
|
407
|
+
# @param options [::Hash] The name and value
|
408
|
+
# pairs. Omitted names are initialized as the default value.
|
409
|
+
# @option options :context (Groonga::context.default) The context
|
350
410
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
351
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
352
411
|
def remove_view(name, options={})
|
353
412
|
define do |schema|
|
354
413
|
schema.remove_view(name, options)
|
355
414
|
end
|
356
415
|
end
|
357
416
|
|
358
|
-
# call-seq:
|
359
|
-
# Groonga::Schema.change_view(name, options={}) {|view| ...}
|
360
|
-
#
|
361
417
|
# 名前が_name_のビューを変更する。以下の省略形。
|
362
|
-
#
|
418
|
+
# <pre>
|
363
419
|
# Groonga::Schema.define do |schema|
|
364
420
|
# schema.change_view(name, options) do |view|
|
365
|
-
#
|
421
|
+
# ==...==
|
366
422
|
# end
|
367
423
|
# end
|
424
|
+
# </pre>
|
368
425
|
#
|
369
426
|
# ブロックにはGroonga::Schema::ViewDefinitionオブジェ
|
370
427
|
# クトがわたるので、そのオブジェクトを利用してテーブル
|
371
428
|
# の詳細を定義する。
|
372
429
|
#
|
373
|
-
#
|
430
|
+
# @param options [::Hash] The name and value
|
431
|
+
# pairs. Omitted names are initialized as the default value.
|
432
|
+
# @option options :context (Groonga::Context.default) The context
|
374
433
|
#
|
375
|
-
# [+:context+]
|
376
434
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
377
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
378
435
|
def change_view(name, options={}, &block)
|
379
436
|
define do |schema|
|
380
437
|
schema.change_view(name, options, &block)
|
381
438
|
end
|
382
439
|
end
|
383
440
|
|
384
|
-
# call-seq:
|
385
|
-
# Groonga::Schema.remove_column(table_name, column_name)
|
386
|
-
#
|
387
441
|
# 以下と同様:
|
388
442
|
#
|
389
443
|
# Groonga::Schema.change_table(table_name) do |table|
|
@@ -395,49 +449,54 @@ module Groonga
|
|
395
449
|
end
|
396
450
|
end
|
397
451
|
|
452
|
+
# This is a syntax sugar of the following:
|
453
|
+
#
|
454
|
+
# Groonga::Schema.define do |schema|
|
455
|
+
# schema.rename_column(table_name,
|
456
|
+
# current_column_name, new_column_name)
|
457
|
+
# end
|
458
|
+
def rename_column(table_name, current_column_name, new_column_name)
|
459
|
+
define do |schema|
|
460
|
+
schema.rename_column(table_name, current_column_name, new_column_name)
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
398
464
|
# スキーマの内容を文字列をRubyスクリプト形式またはgrn式
|
399
465
|
# 形式で返す。デフォルトはRubyスクリプト形式である。
|
400
466
|
# Rubyスクリプト形式で返された値は
|
401
467
|
# Groonga::Schema.restoreすることによりスキーマ内に組み
|
402
468
|
# 込むことができる。
|
403
|
-
#
|
404
|
-
# dump.rb:
|
469
|
+
# <pre>
|
470
|
+
# ==dump.rb:
|
405
471
|
# File.open("/tmp/groonga-schema.rb", "w") do |schema|
|
406
472
|
# dumped_text = Groonga::Schema.dump
|
407
473
|
# end
|
408
|
-
#
|
409
474
|
# restore.rb:
|
410
475
|
# dumped_text = Groonga::Schema.dump
|
411
476
|
# Groonga::Database.create(:path => "/tmp/new-db.grn")
|
412
|
-
# Groonga::Schema.restore(dumped_text)
|
413
|
-
#
|
477
|
+
# Groonga::Schema.restore(dumped_text)==
|
478
|
+
# </pre>
|
414
479
|
# grn式形式で返された値はgroongaコマンドで読み込むこと
|
415
480
|
# ができる。
|
416
|
-
#
|
417
|
-
# dump.rb:
|
481
|
+
# <pre>
|
482
|
+
# ==dump.rb:
|
418
483
|
# File.open("/tmp/groonga-schema.grn", "w") do |schema|
|
419
484
|
# dumped_text = Groonga::Schema.dump(:syntax => :command)
|
420
485
|
# end
|
486
|
+
# % groonga db/path < /tmp/groonga-schema.grn==
|
487
|
+
# </pre>
|
488
|
+
# @param options [::Hash] The name and value
|
489
|
+
# pairs. Omitted names are initialized as the default value.
|
490
|
+
# @option options :context (Groonga::Context.default) The context
|
421
491
|
#
|
422
|
-
# % groonga db/path < /tmp/groonga-schema.grn
|
423
|
-
#
|
424
|
-
# _options_に指定可能な値は以下の通り。
|
425
|
-
#
|
426
|
-
# [+:context+]
|
427
492
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
428
|
-
#
|
429
|
-
#
|
430
|
-
# [+:syntax+]
|
431
|
-
# スキーマの文字列の形式を指定する。指定可能な値は以
|
432
|
-
# 下の通り。
|
493
|
+
# @option options :syntax The syntax
|
433
494
|
#
|
434
|
-
#
|
435
|
-
#
|
436
|
-
#
|
437
|
-
#
|
438
|
-
#
|
439
|
-
# groongaコマンド形式。groongaコマンドで読み込むこ
|
440
|
-
# とができる。
|
495
|
+
# スキーマの文字列の形式を指定する。指定可能な値は以下の通り。
|
496
|
+
# +:ruby+ Rubyスクリプト形式。省略した場合、+nil+ の場合も
|
497
|
+
# Rubyスクリプト形式になる。
|
498
|
+
# +:command+ groongaコマンド形式。groongaコマンドで読み込む
|
499
|
+
# ことができる。
|
441
500
|
def dump(options={})
|
442
501
|
schema = new(:context => options[:context],
|
443
502
|
:syntax => options[:syntax])
|
@@ -508,7 +567,8 @@ module Groonga
|
|
508
567
|
"mecab" => "TokenMecab",
|
509
568
|
"token_mecab"=> "TokenMecab",
|
510
569
|
}
|
511
|
-
|
570
|
+
# @private
|
571
|
+
def normalize_type(type, options={})
|
512
572
|
return type if type.nil?
|
513
573
|
return type if type.is_a?(Groonga::Object)
|
514
574
|
type = type.to_s if type.is_a?(Symbol)
|
@@ -519,11 +579,10 @@ module Groonga
|
|
519
579
|
|
520
580
|
# スキーマ定義を開始する。
|
521
581
|
#
|
522
|
-
#
|
523
|
-
#
|
524
|
-
#
|
582
|
+
# @param options [::Hash] The name and value
|
583
|
+
# pairs. Omitted names are initialized as the default value.
|
584
|
+
# @option options :context (Groonga::Context.default) The context
|
525
585
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
526
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
527
586
|
def initialize(options={})
|
528
587
|
@options = (options || {}).dup
|
529
588
|
@options[:context] ||= Groonga::Context.default
|
@@ -556,122 +615,208 @@ module Groonga
|
|
556
615
|
dumper.dump
|
557
616
|
end
|
558
617
|
|
559
|
-
#
|
560
|
-
# schema.create_table(name, options={}) {|table| ...}
|
561
|
-
#
|
562
|
-
# 名前が_name_のテーブルを作成する。
|
618
|
+
# 名前が _name_ のテーブルを作成する。
|
563
619
|
#
|
564
620
|
# テーブルの作成は#defineを呼び出すまでは実行されないこ
|
565
621
|
# とに注意すること。
|
622
|
+
# @overload create_table(name, options= {:type => :array})
|
623
|
+
# :typeにデフォルトの:arrayを使用した場合
|
624
|
+
# @param options [::Hash] The name and value
|
625
|
+
# pairs. Omitted names are initialized as the default value.
|
626
|
+
# @option options :force The force.
|
566
627
|
#
|
567
|
-
#
|
628
|
+
# +true+ を指定すると既存の同名のテーブルが
|
629
|
+
# 存在していても、強制的にテーブルを作成する。
|
630
|
+
# @option options :type (:array) The type
|
568
631
|
#
|
569
|
-
#
|
570
|
-
#
|
571
|
-
#
|
632
|
+
# テーブルの型を指定する。
|
633
|
+
# +:array+ , +:hash+ , +:patricia_trie+ ,
|
634
|
+
# +:double_array_trie+ のいずれかを指定する。
|
635
|
+
# @option options [Groonga::Context] :context The context.
|
572
636
|
#
|
573
|
-
#
|
574
|
-
#
|
575
|
-
#
|
576
|
-
#
|
637
|
+
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
638
|
+
# 省略した場合はGroonga::Schema.newで指定した
|
639
|
+
# Groonga::Contextを使用する。Groonga::Schema.newで指
|
640
|
+
# 定していない場合はGroonga::Context.defaultを使用する。
|
641
|
+
# @option options :path The path
|
577
642
|
#
|
578
|
-
#
|
579
|
-
#
|
580
|
-
#
|
581
|
-
# Groonga::Contextを使用する。Groonga::Schema.newで指
|
582
|
-
# 定していない場合はGroonga::Context.defaultを使用する。
|
643
|
+
# テーブルを保存するパスを指定する。パスを指定すると
|
644
|
+
# 永続テーブルになる。
|
645
|
+
# @option options :persistent (true) The persistent
|
583
646
|
#
|
584
|
-
#
|
585
|
-
#
|
586
|
-
#
|
647
|
+
# テーブルを永続テーブルとする。 +:path:+ を省略した場
|
648
|
+
# 合はパス名は自動的に作成される。デフォルトでは永続
|
649
|
+
# テーブルとなる。
|
650
|
+
# @option options :value_type The value_type
|
651
|
+
#
|
652
|
+
# 値の型を指定する。省略すると値のための領域を確保しない。
|
653
|
+
# 値を保存したい場合は必ず指定すること。
|
654
|
+
# 参考: Groonga::Type.new
|
655
|
+
# @option options :sub_records The sub_records
|
656
|
+
#
|
657
|
+
# +true+ を指定するとGroonga::Table#groupでグループ化
|
658
|
+
# したときに、Groonga::Record#n_sub_recordsでグループに
|
659
|
+
# 含まれるレコードの件数を取得できる。
|
660
|
+
#
|
661
|
+
# @overload create_table(name, options= {:type => :hash})
|
662
|
+
# :typeに:hashを使用した場合
|
663
|
+
# @param options [::Hash] The name and value
|
664
|
+
# pairs. Omitted names are initialized as the default value.
|
665
|
+
# @option options :force The force
|
666
|
+
#
|
667
|
+
# +true+ を指定すると既存の同名のテーブルが
|
668
|
+
# 存在していても、強制的にテーブルを作成する。
|
669
|
+
# @option options :type (:array) The type
|
670
|
+
#
|
671
|
+
# テーブルの型を指定する。
|
672
|
+
# +:array+ , +:hash+ , +:patricia_trie+ ,
|
673
|
+
# +:double_array_trie+ のいずれかを指定する。
|
674
|
+
# @option options [Groonga::Context] :context The context
|
675
|
+
#
|
676
|
+
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
677
|
+
# 省略した場合はGroonga::Schema.newで指定した
|
678
|
+
# Groonga::Contextを使用する。Groonga::Schema.newで指
|
679
|
+
# 定していない場合はGroonga::Context.defaultを使用する。
|
680
|
+
# @option options :path The path
|
681
|
+
#
|
682
|
+
# テーブルを保存するパスを指定する。パスを指定すると
|
683
|
+
# 永続テーブルになる。
|
684
|
+
# @option options :persistent (true) The persistent
|
685
|
+
#
|
686
|
+
# テーブルを永続テーブルとする。 +:path:+ を省略した場
|
687
|
+
# 合はパス名は自動的に作成される。デフォルトでは永続
|
688
|
+
# テーブルとなる。
|
689
|
+
# @option options :value_type The value_type
|
690
|
+
#
|
691
|
+
# 値の型を指定する。省略すると値のための領域を確保しない。
|
692
|
+
# 値を保存したい場合は必ず指定すること。
|
693
|
+
# 参考: Groonga::Type.new
|
694
|
+
# @option options :sub_records The sub_records
|
695
|
+
#
|
696
|
+
# +true+ を指定するとGroonga::Table#groupでグループ化
|
697
|
+
# したときに、Groonga::Record#n_sub_recordsでグループに
|
698
|
+
# 含まれるレコードの件数を取得できる。
|
699
|
+
# @option options :key_type The key_type
|
700
|
+
#
|
701
|
+
# キーの種類を示すオブジェクトを指定する。
|
702
|
+
# キーの種類には型名("Int32"や"ShortText"など)または
|
703
|
+
# Groonga::Typeまたはテーブル(Groonga::Array、
|
704
|
+
# Groonga::Hash、Groonga::PatriciaTrie、
|
705
|
+
# Groonga::DoubleArrayTrieのどれか)を指定する。
|
706
|
+
#
|
707
|
+
# Groonga::Typeを指定した場合は、その型が示す範囲の
|
708
|
+
# 値をキーとして使用する。ただし、キーの最大サイズは
|
709
|
+
# 4096バイトであるため、Groonga::Type::TEXTや
|
710
|
+
# Groonga::Type::LONG_TEXTは使用できない。
|
711
|
+
#
|
712
|
+
# テーブルを指定した場合はレコードIDをキーとして使用
|
713
|
+
# する。指定したテーブルのGroonga::Recordをキーとし
|
714
|
+
# て使用することもでき、その場合は自動的に
|
715
|
+
# Groonga::RecordからレコードIDを取得する。
|
587
716
|
#
|
588
|
-
#
|
589
|
-
#
|
590
|
-
# 合はパス名は自動的に作成される。デフォルトでは永続
|
591
|
-
# テーブルとなる。
|
717
|
+
# 省略した場合は文字列をキーとして使用する。この場合、
|
718
|
+
# 4096バイトまで使用可能である。
|
592
719
|
#
|
593
|
-
#
|
594
|
-
# 値の型を指定する。省略すると値のための領域を確保しな
|
595
|
-
# い。値を保存したい場合は必ず指定すること。
|
720
|
+
# @option options :default_tokenizer The default_tokenizer
|
596
721
|
#
|
597
|
-
#
|
722
|
+
# Groonga::IndexColumnで使用するトークナイザを指定する。
|
723
|
+
# デフォルトでは何も設定されていないので、テーブルに
|
724
|
+
# Groonga::IndexColumnを定義する場合は
|
725
|
+
# <tt>"TokenBigram"</tt>などを指定する必要がある。
|
598
726
|
#
|
599
|
-
#
|
600
|
-
#
|
601
|
-
#
|
602
|
-
#
|
727
|
+
# @overload create_table(name, options= {:type => :double_array_trie})
|
728
|
+
# :typeに:double_array_trieを使用した場合
|
729
|
+
# @param options [::Hash] The name and value
|
730
|
+
# pairs. Omitted names are initialized as the default value.
|
731
|
+
# @option options :force The force
|
603
732
|
#
|
604
|
-
#
|
605
|
-
#
|
733
|
+
# +true+ を指定すると既存の同名のテーブルが
|
734
|
+
# 存在していても、強制的にテーブルを作成する。
|
735
|
+
# @option options [Groonga::Context] :context The context
|
606
736
|
#
|
607
|
-
#
|
608
|
-
#
|
609
|
-
#
|
610
|
-
#
|
611
|
-
#
|
612
|
-
# 定する。
|
737
|
+
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
738
|
+
# 省略した場合はGroonga::Schema.newで指定した
|
739
|
+
# Groonga::Contextを使用する。Groonga::Schema.newで指
|
740
|
+
# 定していない場合はGroonga::Context.defaultを使用する。
|
741
|
+
# @option options :path The path
|
613
742
|
#
|
614
|
-
#
|
615
|
-
#
|
616
|
-
#
|
617
|
-
# Groonga::Type::LONG_TEXTは使用できない。
|
743
|
+
# テーブルを保存するパスを指定する。パスを指定すると
|
744
|
+
# 永続テーブルになる。
|
745
|
+
# @option options :persistent (true) The persistent
|
618
746
|
#
|
619
|
-
#
|
620
|
-
#
|
621
|
-
#
|
622
|
-
#
|
747
|
+
# テーブルを永続テーブルとする。 +:path:+ を省略した場
|
748
|
+
# 合はパス名は自動的に作成される。デフォルトでは永続
|
749
|
+
# テーブルとなる。
|
750
|
+
# @option options :value_type The value_type
|
623
751
|
#
|
624
|
-
#
|
625
|
-
#
|
752
|
+
# 値の型を指定する。省略すると値のための領域を確保しない。
|
753
|
+
# 値を保存したい場合は必ず指定すること。
|
754
|
+
# 参考: Groonga::Type.new
|
755
|
+
# @option options :sub_records The sub_records
|
626
756
|
#
|
627
|
-
#
|
628
|
-
#
|
629
|
-
#
|
630
|
-
#
|
631
|
-
# <tt>"TokenBigram"</tt>などを指定する必要がある。
|
757
|
+
# +true+ を指定するとGroonga::Table#groupでグループ化
|
758
|
+
# したときに、Groonga::Record#n_sub_recordsでグループに
|
759
|
+
# 含まれるレコードの件数を取得できる。
|
760
|
+
# @option options :key_normalize The key_normalize
|
632
761
|
#
|
633
|
-
#
|
762
|
+
# +true+ を指定するとキーを正規化する。
|
763
|
+
# @option options :key_type The key_type
|
634
764
|
#
|
635
|
-
#
|
636
|
-
#
|
765
|
+
# キーの種類を示すオブジェクトを指定する。
|
766
|
+
# キーの種類には型名("Int32"や"ShortText"など)または
|
767
|
+
# Groonga::Typeまたはテーブル(Groonga::Array、
|
768
|
+
# Groonga::Hash、Groonga::PatriciaTrie、
|
769
|
+
# Groonga::DoubleArrayTrieのどれか)を指定する。
|
637
770
|
#
|
638
|
-
#
|
639
|
-
#
|
640
|
-
#
|
771
|
+
# Groonga::Typeを指定した場合は、その型が示す範囲の
|
772
|
+
# 値をキーとして使用する。ただし、キーの最大サイズは
|
773
|
+
# 4096バイトであるため、Groonga::Type::TEXTや
|
774
|
+
# Groonga::Type::LONG_TEXTは使用できない。
|
775
|
+
#
|
776
|
+
# テーブルを指定した場合はレコードIDをキーとして使用
|
777
|
+
# する。指定したテーブルのGroonga::Recordをキーとし
|
778
|
+
# て使用することもでき、その場合は自動的に
|
779
|
+
# Groonga::RecordからレコードIDを取得する。
|
780
|
+
#
|
781
|
+
# 省略した場合は文字列をキーとして使用する。この場合、
|
782
|
+
# 4096バイトまで使用可能である。
|
783
|
+
# @option options :default_tokenizer The default_tokenizer
|
784
|
+
#
|
785
|
+
# Groonga::IndexColumnで使用するトークナイザを指定する。
|
786
|
+
# デフォルトでは何も設定されていないので、テーブルに
|
787
|
+
# Groonga::IndexColumnを定義する場合は
|
788
|
+
# <tt>"TokenBigram"</tt>などを指定する必要がある。
|
641
789
|
def create_table(name, options={})
|
642
790
|
definition = TableDefinition.new(name, @options.merge(options || {}))
|
643
791
|
yield(definition) if block_given?
|
644
792
|
@definitions << definition
|
645
793
|
end
|
646
794
|
|
647
|
-
# 名前が_name_のテーブルを削除する。
|
795
|
+
# 名前が _name_ のテーブルを削除する。
|
648
796
|
#
|
649
797
|
# テーブルの削除は#defineを呼び出すまでは実行されないこ
|
650
798
|
# とに注意すること。
|
651
799
|
#
|
652
|
-
#
|
800
|
+
# @param options [::Hash] The name and value
|
801
|
+
# pairs. Omitted names are initialized as the default value.
|
802
|
+
# @option options :context (Groonga::Context.default) The context
|
653
803
|
#
|
654
|
-
# [+:context+]
|
655
804
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
656
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
657
805
|
def remove_table(name, options={})
|
658
806
|
definition = TableRemoveDefinition.new(name, @options.merge(options || {}))
|
659
807
|
@definitions << definition
|
660
808
|
end
|
661
809
|
|
662
|
-
#
|
663
|
-
# schema.change_table(name, options={}) {|table| ...}
|
810
|
+
# 名前が _name_ のテーブルを変更する。
|
664
811
|
#
|
665
|
-
#
|
666
|
-
#
|
667
|
-
# テーブルの変更は#defineを呼び出すまでは実行されないこ
|
812
|
+
# テーブルの変更は #define を呼び出すまでは実行されないこ
|
668
813
|
# とに注意すること。
|
669
814
|
#
|
670
|
-
#
|
815
|
+
# @param options [::Hash] The name and value
|
816
|
+
# pairs. Omitted names are initialized as the default value.
|
817
|
+
# @option options :context (Groonga::Context.default) The context
|
671
818
|
#
|
672
|
-
# [+:context+]
|
673
819
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
674
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
675
820
|
def change_table(name, options={})
|
676
821
|
options = @options.merge(options || {}).merge(:change => true)
|
677
822
|
definition = TableDefinition.new(name, options)
|
@@ -679,68 +824,77 @@ module Groonga
|
|
679
824
|
@definitions << definition
|
680
825
|
end
|
681
826
|
|
682
|
-
#
|
683
|
-
#
|
827
|
+
# Renames _current_name_ table to _new_name.
|
828
|
+
#
|
829
|
+
# Note that table renaming will will not be performed
|
830
|
+
# until {#define} is called.
|
684
831
|
#
|
685
|
-
#
|
832
|
+
# @param options [::Hash] The name and value
|
833
|
+
# pairs. Omitted names are initialized as the default value.
|
834
|
+
# @option options :context (Groonga::Context.default)
|
835
|
+
# The Groonga::Context to be used in renaming.
|
836
|
+
def rename_table(current_name, new_name, options={})
|
837
|
+
options = @options.merge(options || {})
|
838
|
+
definition = TableRenameDefinition.new(current_name, new_name, options)
|
839
|
+
@definitions << definition
|
840
|
+
end
|
841
|
+
|
842
|
+
# 名前が _name_ のビューを作成する。
|
686
843
|
#
|
687
|
-
#
|
844
|
+
# ビューの作成は #define を呼び出すまでは実行されないこ
|
688
845
|
# とに注意すること。
|
689
846
|
#
|
690
|
-
#
|
847
|
+
# @param options [::Hash] The name and value
|
848
|
+
# pairs. Omitted names are initialized as the default value.
|
849
|
+
# @option options :force The force
|
691
850
|
#
|
692
|
-
#
|
693
|
-
#
|
694
|
-
#
|
851
|
+
# +true+ を指定すると既存の同名の
|
852
|
+
# ビューが存在していても、強制的にビューを作成する。
|
853
|
+
# @option options [Groonga::Context] :context (Groonga::Schema.new) The context
|
695
854
|
#
|
696
|
-
# [+:context+]
|
697
855
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
698
|
-
#
|
699
|
-
# Groonga::Contextを使用する。
|
700
|
-
#
|
856
|
+
# Groonga::Schema.newで指定していない場合は
|
857
|
+
# Groonga::Context.defaultを使用する。
|
858
|
+
# @option options :path The path
|
701
859
|
#
|
702
|
-
# [+:path+]
|
703
860
|
# テーブルを保存するパスを指定する。パスを指定すると
|
704
861
|
# 永続テーブルになる。
|
862
|
+
# @option options :persistent (true) The persistent
|
705
863
|
#
|
706
|
-
#
|
707
|
-
#
|
708
|
-
# 合はパス名は自動的に作成される。デフォルトでは永続
|
709
|
-
# テーブルとなる。
|
864
|
+
# テーブルを永続テーブルとする。 +:path:+ を省略した場合は
|
865
|
+
# パス名は自動的に作成される。デフォルトでは永続テーブルとなる。
|
710
866
|
def create_view(name, options={})
|
711
867
|
definition = ViewDefinition.new(name, @options.merge(options || {}))
|
712
868
|
yield(definition)
|
713
869
|
@definitions << definition
|
714
870
|
end
|
715
871
|
|
716
|
-
# 名前が_name_のビューを削除する。
|
872
|
+
# 名前が _name_ のビューを削除する。
|
717
873
|
#
|
718
|
-
#
|
874
|
+
# ビューの削除は #define を呼び出すまでは実行されないことに
|
719
875
|
# 注意すること。
|
720
876
|
#
|
721
|
-
#
|
877
|
+
# @param options [::Hash] The name and value
|
878
|
+
# pairs. Omitted names are initialized as the default value.
|
879
|
+
# @option options [Groonga::Context] :context (Groonga::Context.default)
|
880
|
+
# The context
|
722
881
|
#
|
723
|
-
# [+:context+]
|
724
882
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
725
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
726
883
|
def remove_view(name, options={})
|
727
884
|
definition = ViewRemoveDefinition.new(name, @options.merge(options || {}))
|
728
885
|
@definitions << definition
|
729
886
|
end
|
730
887
|
|
731
|
-
#
|
732
|
-
# schema.change_view(name, options={}) {|table| ...}
|
888
|
+
# 名前が _name_ のビューを変更する。
|
733
889
|
#
|
734
|
-
#
|
735
|
-
#
|
736
|
-
# ビューの変更は#defineを呼び出すまでは実行されないこ
|
890
|
+
# ビューの変更は #define を呼び出すまでは実行されないこ
|
737
891
|
# とに注意すること。
|
738
892
|
#
|
739
|
-
#
|
893
|
+
# @param options [::Hash] The name and value
|
894
|
+
# pairs. Omitted names are initialized as the default value.
|
895
|
+
# @option options :context (Groonga::Context.default) The context
|
740
896
|
#
|
741
|
-
# [+:context+]
|
742
897
|
# スキーマ定義時に使用するGroonga::Contextを指定する。
|
743
|
-
# 省略した場合はGroonga::Context.defaultを使用する。
|
744
898
|
def change_view(name, options={})
|
745
899
|
options = @options.merge(options || {}).merge(:change => true)
|
746
900
|
definition = ViewDefinition.new(name, options)
|
@@ -748,11 +902,7 @@ module Groonga
|
|
748
902
|
@definitions << definition
|
749
903
|
end
|
750
904
|
|
751
|
-
# call-seq:
|
752
|
-
# schema.remove_column(table_name, column_name)
|
753
|
-
#
|
754
905
|
# 以下と同様:
|
755
|
-
#
|
756
906
|
# schema.change_table(table_name) do |table|
|
757
907
|
# table.remove_column(column_name)
|
758
908
|
# end
|
@@ -762,11 +912,23 @@ module Groonga
|
|
762
912
|
end
|
763
913
|
end
|
764
914
|
|
765
|
-
|
915
|
+
# It is a syntax sugar of the following:
|
916
|
+
# schema.change_table(table_name) do |table|
|
917
|
+
# table.rename_column(current_column_name, new_column_name)
|
918
|
+
# end
|
919
|
+
def rename_column(table_name, current_column_name, new_column_name)
|
920
|
+
change_table(table_name) do |table|
|
921
|
+
table.rename_column(current_column_name, new_column_name)
|
922
|
+
end
|
923
|
+
end
|
924
|
+
|
925
|
+
# @private
|
926
|
+
def context
|
766
927
|
@options[:context] || Groonga::Context.default
|
767
928
|
end
|
768
929
|
|
769
|
-
|
930
|
+
# @private
|
931
|
+
module Path
|
770
932
|
def tables_directory_path(database)
|
771
933
|
"#{database.path}.tables"
|
772
934
|
end
|
@@ -775,12 +937,18 @@ module Groonga
|
|
775
937
|
"#{table.path}.columns"
|
776
938
|
end
|
777
939
|
|
778
|
-
def
|
940
|
+
def rmdir_if_available(dir)
|
779
941
|
begin
|
780
942
|
Dir.rmdir(dir)
|
781
|
-
rescue
|
943
|
+
rescue SystemCallError
|
782
944
|
end
|
783
945
|
end
|
946
|
+
|
947
|
+
private
|
948
|
+
# @private
|
949
|
+
def use_named_path?
|
950
|
+
@options[:named_path]
|
951
|
+
end
|
784
952
|
end
|
785
953
|
|
786
954
|
# スキーマ定義時にGroonga::Schema.create_tableや
|
@@ -792,7 +960,8 @@ module Groonga
|
|
792
960
|
# テーブルの名前
|
793
961
|
attr_reader :name
|
794
962
|
|
795
|
-
|
963
|
+
# @private
|
964
|
+
def initialize(name, options)
|
796
965
|
@name = name
|
797
966
|
@name = @name.to_s if @name.is_a?(Symbol)
|
798
967
|
@definitions = []
|
@@ -801,7 +970,8 @@ module Groonga
|
|
801
970
|
@table_type = table_type
|
802
971
|
end
|
803
972
|
|
804
|
-
|
973
|
+
# @private
|
974
|
+
def define
|
805
975
|
table = context[@name]
|
806
976
|
if @options[:change]
|
807
977
|
raise TableNotExists.new(@name) if table.nil?
|
@@ -825,38 +995,34 @@ module Groonga
|
|
825
995
|
table
|
826
996
|
end
|
827
997
|
|
828
|
-
# 名前が_name_で型が_type_のカラムを作成する。
|
998
|
+
# 名前が _name_ で型が _type_ のカラムを作成する。
|
829
999
|
#
|
830
|
-
#
|
1000
|
+
# @param options [::Hash] The name and value
|
1001
|
+
# pairs. Omitted names are initialized as the default value.
|
1002
|
+
# @option options :force The force
|
831
1003
|
#
|
832
|
-
#
|
833
|
-
#
|
834
|
-
#
|
1004
|
+
# +true+ を指定すると既存の同名のカラムが
|
1005
|
+
# 存在していても、強制的に新しいカラムを作成する。
|
1006
|
+
# @option options :path The path
|
835
1007
|
#
|
836
|
-
# [+:path+]
|
837
1008
|
# カラムを保存するパス。
|
1009
|
+
# @option options :persistent The persistent
|
838
1010
|
#
|
839
|
-
#
|
840
|
-
# +true+を指定すると永続カラムとなる。+:path+を省略
|
1011
|
+
# +true+ を指定すると永続カラムとなる。+:path+ を省略
|
841
1012
|
# した場合は自動的にパスが付加される。
|
1013
|
+
# @option options :type (:scalar) The type
|
842
1014
|
#
|
843
|
-
#
|
844
|
-
#
|
845
|
-
# +:scalar+になる。
|
846
|
-
#
|
847
|
-
# [+:scalar+]
|
1015
|
+
# カラムの値の格納方法について指定する。
|
1016
|
+
# <b>:scalar</b>
|
848
1017
|
# スカラ値(単独の値)を格納する。
|
849
|
-
#
|
850
|
-
# [+:vector+]
|
1018
|
+
# <b>:vector</b>
|
851
1019
|
# 値の配列を格納する。
|
1020
|
+
# @option options :compress The compress
|
852
1021
|
#
|
853
|
-
# [+:compress+]
|
854
1022
|
# 値の圧縮方法を指定する。省略した場合は、圧縮しない。
|
855
|
-
#
|
856
|
-
# [+:zlib+]
|
1023
|
+
# <b>:zlib</b>
|
857
1024
|
# 値をzlib圧縮して格納する。
|
858
|
-
#
|
859
|
-
# [+:lzo+]
|
1025
|
+
# <b>:lzo</b>
|
860
1026
|
# 値をlzo圧縮して格納する。
|
861
1027
|
def column(name, type, options={})
|
862
1028
|
definition = self[name, ColumnDefinition]
|
@@ -869,9 +1035,9 @@ module Groonga
|
|
869
1035
|
self
|
870
1036
|
end
|
871
1037
|
|
872
|
-
# 名前が_name_のカラムを削除します。
|
1038
|
+
# 名前が _name_ のカラムを削除します。
|
873
1039
|
#
|
874
|
-
# _options_に指定可能な値はありません(TODO _options_は不要?)。
|
1040
|
+
# _options_ に指定可能な値はありません(TODO _options_ は不要?)。
|
875
1041
|
#
|
876
1042
|
def remove_column(name, options={})
|
877
1043
|
definition = self[name, ColumnRemoveDefinition]
|
@@ -883,52 +1049,66 @@ module Groonga
|
|
883
1049
|
self
|
884
1050
|
end
|
885
1051
|
|
886
|
-
#
|
887
|
-
# table.index(target_column_full_name, options={})
|
888
|
-
# table.index(target_table, target_column, options={})
|
889
|
-
# table.index(target_table, target_column1, target_column2, ..., options={})
|
1052
|
+
# Renames _current_name_ column to _new_name_ column.
|
890
1053
|
#
|
891
|
-
#
|
1054
|
+
# @param [::Hash] options The name and value
|
1055
|
+
# pairs. Omitted names are initialized as the default
|
1056
|
+
# value.
|
1057
|
+
# @option options [Groonga:Context] :context (Groonga::Context.default)
|
1058
|
+
# The context to be used in renaming.
|
1059
|
+
def rename_column(current_name, new_name, options={})
|
1060
|
+
definition = self[name, ColumnRenameDefinition]
|
1061
|
+
if definition.nil?
|
1062
|
+
definition = ColumnRenameDefinition.new(current_name, new_name,
|
1063
|
+
options)
|
1064
|
+
update_definition(name, ColumnRenameDefinition, definition)
|
1065
|
+
end
|
1066
|
+
definition.options.merge!(options)
|
1067
|
+
self
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
# _target_table_ の _target_column_ を対象とするインデック
|
892
1071
|
# スカラムを作成します。複数のカラムを指定することもで
|
893
1072
|
# きます。
|
894
1073
|
#
|
895
|
-
# _target_column_full_name_で指定するときはテーブル名
|
1074
|
+
# _target_column_full_name_ で指定するときはテーブル名
|
896
1075
|
# とカラム名を"."でつなげます。例えば、「Users」テーブ
|
897
1076
|
# ルの「name」カラムのインデックスカラムを指定する場合
|
898
1077
|
# はこうなります。
|
899
1078
|
#
|
900
1079
|
# table.index("Users.name")
|
901
1080
|
#
|
902
|
-
#
|
1081
|
+
# @param options [::Hash] The name and value
|
1082
|
+
# pairs. Omitted names are initialized as the default value.
|
1083
|
+
# @option options :name The name
|
903
1084
|
#
|
904
|
-
# [+:name+]
|
905
1085
|
# インデックスカラムのカラム名を任意に指定する。
|
1086
|
+
# @option options :force The force
|
906
1087
|
#
|
907
|
-
#
|
908
|
-
#
|
909
|
-
#
|
1088
|
+
# +true+ を指定すると既存の同名のカラムが
|
1089
|
+
# 存在していても、強制的に新しいカラムを作成する。
|
1090
|
+
# @option options :path The path
|
910
1091
|
#
|
911
|
-
# [+:path+]
|
912
1092
|
# カラムを保存するパス。
|
1093
|
+
# @option options :persistent The persistent
|
913
1094
|
#
|
914
|
-
#
|
915
|
-
# +
|
916
|
-
#
|
1095
|
+
# +true+ を指定すると永続カラムとなる。
|
1096
|
+
# +:path+ を省略した場合は自動的にパスが付加される。
|
1097
|
+
# @option options :with_section The with_section
|
917
1098
|
#
|
918
|
-
#
|
919
|
-
# +
|
920
|
-
# わせて格納する。未指定または+nil+を指定した場合、
|
1099
|
+
# +true+ を指定すると転置索引にsection(段落情報)を
|
1100
|
+
# 合わせて格納する。未指定または +nil+ を指定した場合、
|
921
1101
|
# 複数のカラムを指定すると自動的に有効になる。
|
1102
|
+
# @option options :with_weight The with_weight
|
922
1103
|
#
|
923
|
-
#
|
924
|
-
#
|
925
|
-
#
|
1104
|
+
# +true+ を指定すると転置索引にweight情報を合わせて
|
1105
|
+
# 格納する。
|
1106
|
+
# @option options :with_position
|
926
1107
|
#
|
927
|
-
#
|
928
|
-
# +
|
929
|
-
#
|
930
|
-
#
|
931
|
-
# 動的に有効になる。
|
1108
|
+
# +true+ を指定すると転置索引に出現位置情報を合わせて
|
1109
|
+
# 格納する。未指定または +nil+ を指定した場合、テーブル
|
1110
|
+
# がN-gram系のトークナイザーを利用している場合は
|
1111
|
+
# 自動的に有効になる。
|
932
1112
|
def index(target_table_or_target_column_full_name, *args)
|
933
1113
|
key, target_table, target_columns, options =
|
934
1114
|
parse_index_argument(target_table_or_target_column_full_name, *args)
|
@@ -945,24 +1125,19 @@ module Groonga
|
|
945
1125
|
self
|
946
1126
|
end
|
947
1127
|
|
948
|
-
#
|
949
|
-
# table.remove_index(target_column_full_name, options={})
|
950
|
-
# table.remove_index(target_table, target_column, options={})
|
951
|
-
# table.remove_index(target_table, target_column1, target_column2, ..., options={})
|
952
|
-
#
|
953
|
-
# _target_table_の_target_column_を対象とするインデッ
|
1128
|
+
# _target_table_ の _target_column_ を対象とするインデッ
|
954
1129
|
# クスカラムを削除します。
|
955
1130
|
#
|
956
|
-
# _target_column_full_name_で指定するときはテーブル名
|
1131
|
+
# _target_column_full_name_ で指定するときはテーブル名
|
957
1132
|
# とカラム名を"."でつなげます。例えば、「Users」テーブ
|
958
1133
|
# ルの「name」カラムのインデックスカラムを削除する場合
|
959
1134
|
# はこうなります。
|
960
1135
|
#
|
961
1136
|
# table.remove_index("Users.name")
|
962
1137
|
#
|
963
|
-
#
|
964
|
-
#
|
965
|
-
#
|
1138
|
+
# @param options [::Hash] The name and value
|
1139
|
+
# pairs. Omitted names are initialized as the default value.
|
1140
|
+
# @option options :name The name
|
966
1141
|
# インデックスカラムのカラム名を任意に指定する。
|
967
1142
|
def remove_index(target_table_or_target_column_full_name, *args)
|
968
1143
|
key, target_table, target_columns, options =
|
@@ -983,58 +1158,58 @@ module Groonga
|
|
983
1158
|
self
|
984
1159
|
end
|
985
1160
|
|
986
|
-
# 名前が_name_の32bit符号付き整数のカラムを作成する。
|
1161
|
+
# 名前が _name_ の32bit符号付き整数のカラムを作成する。
|
987
1162
|
#
|
988
|
-
# _options_に指定可能な値は
|
989
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1163
|
+
# _options_ に指定可能な値は
|
1164
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
990
1165
|
def integer32(name, options={})
|
991
1166
|
column(name, "Int32", options)
|
992
1167
|
end
|
993
1168
|
alias_method :integer, :integer32
|
994
1169
|
alias_method :int32, :integer32
|
995
1170
|
|
996
|
-
# 名前が_name_の64bit符号付き整数のカラムを作成する。
|
1171
|
+
# 名前が _name_ の64bit符号付き整数のカラムを作成する。
|
997
1172
|
#
|
998
|
-
# _options_に指定可能な値は
|
999
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1173
|
+
# _options_ に指定可能な値は
|
1174
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1000
1175
|
def integer64(name, options={})
|
1001
1176
|
column(name, "Int64", options)
|
1002
1177
|
end
|
1003
1178
|
alias_method :int64, :integer64
|
1004
1179
|
|
1005
|
-
# 名前が_name_の32bit符号なし整数のカラムを作成する。
|
1180
|
+
# 名前が _name_ の32bit符号なし整数のカラムを作成する。
|
1006
1181
|
#
|
1007
|
-
# _options_に指定可能な値は
|
1008
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1182
|
+
# _options_ に指定可能な値は
|
1183
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1009
1184
|
def unsigned_integer32(name, options={})
|
1010
1185
|
column(name, "UInt32", options)
|
1011
1186
|
end
|
1012
1187
|
alias_method :unsigned_integer, :unsigned_integer32
|
1013
1188
|
alias_method :uint32, :unsigned_integer32
|
1014
1189
|
|
1015
|
-
# 名前が_name_の64bit符号なし整数のカラムを作成する。
|
1190
|
+
# 名前が _name_ の64bit符号なし整数のカラムを作成する。
|
1016
1191
|
#
|
1017
|
-
# _options_に指定可能な値は
|
1018
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1192
|
+
# _options_ に指定可能な値は
|
1193
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1019
1194
|
def unsigned_integer64(name, options={})
|
1020
1195
|
column(name, "UInt64", options)
|
1021
1196
|
end
|
1022
1197
|
alias_method :uint64, :unsigned_integer64
|
1023
1198
|
|
1024
|
-
# 名前が_name_のieee754形式の64bit浮動小数点数のカラム
|
1199
|
+
# 名前が _name_ のieee754形式の64bit浮動小数点数のカラム
|
1025
1200
|
# を作成する。
|
1026
1201
|
#
|
1027
|
-
# _options_に指定可能な値は
|
1028
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1202
|
+
# _options_ に指定可能な値は
|
1203
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1029
1204
|
def float(name, options={})
|
1030
1205
|
column(name, "Float", options)
|
1031
1206
|
end
|
1032
1207
|
|
1033
|
-
# 名前が_name_の64bit符号付き整数で1970年1月1日0時0分
|
1208
|
+
# 名前が _name_ の64bit符号付き整数で1970年1月1日0時0分
|
1034
1209
|
# 0秒からの経過マイクロ秒数を格納するカラムを作成する。
|
1035
1210
|
#
|
1036
|
-
# _options_に指定可能な値は
|
1037
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1211
|
+
# _options_ に指定可能な値は
|
1212
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1038
1213
|
def time(name, options={})
|
1039
1214
|
column(name, "Time", options)
|
1040
1215
|
end
|
@@ -1047,69 +1222,72 @@ module Groonga
|
|
1047
1222
|
time("updated_at", options)
|
1048
1223
|
end
|
1049
1224
|
|
1050
|
-
# 名前が_name_の4Kbyte以下の文字列を格納できるカラムを
|
1225
|
+
# 名前が _name_ の4Kbyte以下の文字列を格納できるカラムを
|
1051
1226
|
# 作成する。
|
1052
1227
|
#
|
1053
|
-
# _options_に指定可能な値は
|
1054
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1228
|
+
# _options_ に指定可能な値は
|
1229
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1055
1230
|
def short_text(name, options={})
|
1056
1231
|
column(name, "ShortText", options)
|
1057
1232
|
end
|
1058
1233
|
alias_method :string, :short_text
|
1059
1234
|
|
1060
|
-
# 名前が_name_の64Kbyte以下の文字列を格納できるカラムを
|
1235
|
+
# 名前が _name_ の64Kbyte以下の文字列を格納できるカラムを
|
1061
1236
|
# 作成する。
|
1062
1237
|
#
|
1063
|
-
# _options_に指定可能な値は
|
1064
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1238
|
+
# _options_ に指定可能な値は
|
1239
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1065
1240
|
def text(name, options={})
|
1066
1241
|
column(name, "Text", options)
|
1067
1242
|
end
|
1068
1243
|
|
1069
|
-
# 名前が_name_の2Gbyte以下の文字列を格納できるカラムを
|
1244
|
+
# 名前が _name_ の2Gbyte以下の文字列を格納できるカラムを
|
1070
1245
|
# 作成する。
|
1071
1246
|
#
|
1072
|
-
# _options_に指定可能な値は
|
1073
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1247
|
+
# _options_ に指定可能な値は
|
1248
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1074
1249
|
def long_text(name, options={})
|
1075
1250
|
column(name, "LongText", options)
|
1076
1251
|
end
|
1077
1252
|
|
1078
|
-
# 名前が_name_で_table_のレコードIDを格納する参照カラ
|
1253
|
+
# 名前が _name_ で _table_ のレコードIDを格納する参照カラ
|
1079
1254
|
# ムを作成する。
|
1080
1255
|
#
|
1081
|
-
# _table_が省略された場合は_name_の複数形が使われる。
|
1082
|
-
# 例えば、_name_が"user"な場合は_table_は"users"になる。
|
1256
|
+
# _table_ が省略された場合は _name_ の複数形が使われる。
|
1257
|
+
# 例えば、 _name_ が"user"な場合は _table_ は"users"になる。
|
1083
1258
|
#
|
1084
|
-
# _options_に指定可能な値は
|
1085
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1259
|
+
# _options_ に指定可能な値は
|
1260
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1086
1261
|
def reference(name, table=nil, options={})
|
1087
1262
|
table ||= lambda {|context| guess_table_name(context, name)}
|
1088
1263
|
column(name, table, options)
|
1089
1264
|
end
|
1090
1265
|
|
1091
|
-
# 名前が_name_の真偽値を格納できるカラムを作成する。
|
1266
|
+
# 名前が _name_ の真偽値を格納できるカラムを作成する。
|
1092
1267
|
#
|
1093
|
-
# _options_に指定可能な値は
|
1094
|
-
# Groonga::Schema::TableDefinition#columnを参照。
|
1268
|
+
# _options_ に指定可能な値は
|
1269
|
+
# {Groonga::Schema::TableDefinition#column} を参照。
|
1095
1270
|
def boolean(name, options={})
|
1096
1271
|
column(name, "Bool", options)
|
1097
1272
|
end
|
1098
1273
|
alias_method :bool, :boolean
|
1099
1274
|
|
1100
|
-
|
1275
|
+
# @private
|
1276
|
+
def [](name, definition_class=nil)
|
1101
1277
|
@definitions.find do |definition|
|
1102
1278
|
definition.name.to_s == name.to_s and
|
1103
1279
|
(definition_class.nil? or definition.is_a?(definition_class))
|
1104
1280
|
end
|
1105
1281
|
end
|
1106
1282
|
|
1107
|
-
|
1283
|
+
# @private
|
1284
|
+
def context
|
1108
1285
|
@options[:context] || Groonga::Context.default
|
1109
1286
|
end
|
1110
1287
|
|
1111
1288
|
private
|
1112
|
-
|
1289
|
+
# @private
|
1290
|
+
def update_definition(key, definition_class, definition)
|
1113
1291
|
old_definition = self[key, definition_class]
|
1114
1292
|
if old_definition
|
1115
1293
|
index = @definitions.index(old_definition)
|
@@ -1119,12 +1297,15 @@ module Groonga
|
|
1119
1297
|
end
|
1120
1298
|
end
|
1121
1299
|
|
1300
|
+
# @private
|
1122
1301
|
AVAILABLE_OPTION_KEYS = [:context, :change, :force,
|
1123
1302
|
:type, :path, :persistent,
|
1124
1303
|
:key_type, :value_type, :sub_records,
|
1125
1304
|
:default_tokenizer,
|
1126
|
-
:key_normalize, :key_with_sis
|
1127
|
-
|
1305
|
+
:key_normalize, :key_with_sis,
|
1306
|
+
:named_path]
|
1307
|
+
# @private
|
1308
|
+
def validate_options(options)
|
1128
1309
|
return if options.nil?
|
1129
1310
|
unknown_keys = options.keys - AVAILABLE_OPTION_KEYS
|
1130
1311
|
unless unknown_keys.empty?
|
@@ -1132,7 +1313,8 @@ module Groonga
|
|
1132
1313
|
end
|
1133
1314
|
end
|
1134
1315
|
|
1135
|
-
|
1316
|
+
# @private
|
1317
|
+
def table_type
|
1136
1318
|
type = @options[:type]
|
1137
1319
|
case type
|
1138
1320
|
when :array, nil
|
@@ -1141,12 +1323,17 @@ module Groonga
|
|
1141
1323
|
Groonga::Hash
|
1142
1324
|
when :patricia_trie
|
1143
1325
|
Groonga::PatriciaTrie
|
1326
|
+
when :double_array_trie
|
1327
|
+
Groonga::DoubleArrayTrie
|
1144
1328
|
else
|
1145
|
-
|
1329
|
+
supported_types = [nil, :array, :hash, :patricia_trie,
|
1330
|
+
:double_array_trie]
|
1331
|
+
raise UnknownTableType.new(type, supported_types)
|
1146
1332
|
end
|
1147
1333
|
end
|
1148
1334
|
|
1149
|
-
|
1335
|
+
# @private
|
1336
|
+
def create_options
|
1150
1337
|
common = {
|
1151
1338
|
:name => @name,
|
1152
1339
|
:path => path,
|
@@ -1170,22 +1357,27 @@ module Groonga
|
|
1170
1357
|
:key_with_sis => @options[:key_with_sis],
|
1171
1358
|
}
|
1172
1359
|
common.merge(key_support_table_common).merge(options)
|
1360
|
+
elsif @table_type == Groonga::DoubleArrayTrie
|
1361
|
+
common.merge(key_support_table_common)
|
1173
1362
|
end
|
1174
1363
|
end
|
1175
1364
|
|
1176
1365
|
def path
|
1177
1366
|
user_path = @options[:path]
|
1178
1367
|
return user_path if user_path
|
1368
|
+
return nil unless use_named_path?
|
1179
1369
|
tables_dir = tables_directory_path(context.database)
|
1180
1370
|
FileUtils.mkdir_p(tables_dir)
|
1181
1371
|
File.join(tables_dir, @name)
|
1182
1372
|
end
|
1183
1373
|
|
1184
|
-
|
1185
|
-
|
1374
|
+
# @private
|
1375
|
+
def column_options
|
1376
|
+
{:persistent => persistent?, :named_path => use_named_path?}
|
1186
1377
|
end
|
1187
1378
|
|
1188
|
-
|
1379
|
+
# @private
|
1380
|
+
def persistent?
|
1189
1381
|
@options[:persistent].nil? ? true : @options[:persistent]
|
1190
1382
|
end
|
1191
1383
|
|
@@ -1221,7 +1413,7 @@ module Groonga
|
|
1221
1413
|
case table
|
1222
1414
|
when Groonga::Array
|
1223
1415
|
true
|
1224
|
-
when Groonga::Hash, Groonga::PatriciaTrie
|
1416
|
+
when Groonga::Hash, Groonga::PatriciaTrie, Groonga::DoubleArrayTrie
|
1225
1417
|
key_type = normalize_key_type(options[:key_type])
|
1226
1418
|
return false unless table.domain == resolve_name(key_type)
|
1227
1419
|
default_tokenizer = normalize_type(options[:default_tokenizer])
|
@@ -1281,7 +1473,8 @@ module Groonga
|
|
1281
1473
|
end
|
1282
1474
|
end
|
1283
1475
|
|
1284
|
-
|
1476
|
+
# @private
|
1477
|
+
class TableRemoveDefinition
|
1285
1478
|
include Path
|
1286
1479
|
|
1287
1480
|
def initialize(name, options={})
|
@@ -1291,21 +1484,53 @@ module Groonga
|
|
1291
1484
|
|
1292
1485
|
def define
|
1293
1486
|
table = removed_table
|
1294
|
-
|
1487
|
+
tables_dir = tables_directory_path(context.database)
|
1488
|
+
columns_dir = columns_directory_path(table)
|
1295
1489
|
result = table.remove
|
1296
|
-
|
1490
|
+
rmdir_if_available(columns_dir)
|
1491
|
+
rmdir_if_available(tables_dir)
|
1297
1492
|
result
|
1298
1493
|
end
|
1299
1494
|
|
1300
1495
|
private
|
1496
|
+
def context
|
1497
|
+
@options[:context]
|
1498
|
+
end
|
1499
|
+
|
1301
1500
|
def removed_table
|
1302
|
-
context = @options[:context]
|
1303
1501
|
table = context[@name]
|
1304
1502
|
raise TableNotExists.new(@name) if table.nil?
|
1305
1503
|
table
|
1306
1504
|
end
|
1307
1505
|
end
|
1308
1506
|
|
1507
|
+
# @private
|
1508
|
+
class TableRenameDefinition
|
1509
|
+
include Path
|
1510
|
+
|
1511
|
+
def initialize(current_name, new_name, options={})
|
1512
|
+
@current_name = current_name
|
1513
|
+
@new_name = new_name
|
1514
|
+
@options = options
|
1515
|
+
end
|
1516
|
+
|
1517
|
+
def define
|
1518
|
+
table = current_table
|
1519
|
+
table.rename(@new_name)
|
1520
|
+
end
|
1521
|
+
|
1522
|
+
private
|
1523
|
+
def context
|
1524
|
+
@options[:context]
|
1525
|
+
end
|
1526
|
+
|
1527
|
+
def current_table
|
1528
|
+
table = context[@current_name]
|
1529
|
+
raise TableNotExists.new(@current_name) if table.nil?
|
1530
|
+
table
|
1531
|
+
end
|
1532
|
+
end
|
1533
|
+
|
1309
1534
|
# スキーマ定義時にGroonga::Schema.create_viewや
|
1310
1535
|
# Groonga::Schema#create_viewからブロックに渡されてくる
|
1311
1536
|
# オブジェクト
|
@@ -1313,7 +1538,8 @@ module Groonga
|
|
1313
1538
|
# ビューの名前
|
1314
1539
|
attr_reader :name
|
1315
1540
|
|
1316
|
-
|
1541
|
+
# @private
|
1542
|
+
def initialize(name, options)
|
1317
1543
|
@name = name
|
1318
1544
|
@name = @name.to_s if @name.is_a?(Symbol)
|
1319
1545
|
@tables = []
|
@@ -1321,7 +1547,8 @@ module Groonga
|
|
1321
1547
|
@options = options
|
1322
1548
|
end
|
1323
1549
|
|
1324
|
-
|
1550
|
+
# @private
|
1551
|
+
def define
|
1325
1552
|
view = context[@name]
|
1326
1553
|
if @options[:change]
|
1327
1554
|
raise TableNotExists.new(@name) if view.nil?
|
@@ -1332,7 +1559,6 @@ module Groonga
|
|
1332
1559
|
end
|
1333
1560
|
view ||= Groonga::View.create(create_options)
|
1334
1561
|
end
|
1335
|
-
_context = context
|
1336
1562
|
@tables.each do |table|
|
1337
1563
|
unless table.is_a?(Groonga::Table)
|
1338
1564
|
table_name = table
|
@@ -1351,14 +1577,17 @@ module Groonga
|
|
1351
1577
|
self
|
1352
1578
|
end
|
1353
1579
|
|
1354
|
-
|
1580
|
+
# @private
|
1581
|
+
def context
|
1355
1582
|
@options[:context] || Groonga::Context.default
|
1356
1583
|
end
|
1357
1584
|
|
1358
1585
|
private
|
1586
|
+
# @private
|
1359
1587
|
AVAILABLE_OPTION_KEYS = [:context, :change, :force,
|
1360
|
-
:path, :persistent
|
1361
|
-
|
1588
|
+
:path, :persistent, :named_path]
|
1589
|
+
# @private
|
1590
|
+
def validate_options(options)
|
1362
1591
|
return if options.nil?
|
1363
1592
|
unknown_keys = options.keys - AVAILABLE_OPTION_KEYS
|
1364
1593
|
unless unknown_keys.empty?
|
@@ -1366,7 +1595,8 @@ module Groonga
|
|
1366
1595
|
end
|
1367
1596
|
end
|
1368
1597
|
|
1369
|
-
|
1598
|
+
# @private
|
1599
|
+
def create_options
|
1370
1600
|
{
|
1371
1601
|
:name => @name,
|
1372
1602
|
:path => @options[:path],
|
@@ -1375,12 +1605,14 @@ module Groonga
|
|
1375
1605
|
}
|
1376
1606
|
end
|
1377
1607
|
|
1378
|
-
|
1608
|
+
# @private
|
1609
|
+
def persistent?
|
1379
1610
|
@options[:persistent].nil? ? true : @options[:persistent]
|
1380
1611
|
end
|
1381
1612
|
end
|
1382
1613
|
|
1383
|
-
|
1614
|
+
# @private
|
1615
|
+
class ViewRemoveDefinition
|
1384
1616
|
def initialize(name, options={})
|
1385
1617
|
@name = name
|
1386
1618
|
@options = options
|
@@ -1392,7 +1624,8 @@ module Groonga
|
|
1392
1624
|
end
|
1393
1625
|
end
|
1394
1626
|
|
1395
|
-
|
1627
|
+
# @private
|
1628
|
+
class ColumnDefinition
|
1396
1629
|
include Path
|
1397
1630
|
|
1398
1631
|
attr_accessor :name, :type
|
@@ -1448,13 +1681,17 @@ module Groonga
|
|
1448
1681
|
def path(context, table)
|
1449
1682
|
user_path = @options[:path]
|
1450
1683
|
return user_path if user_path
|
1684
|
+
return nil unless use_named_path?
|
1451
1685
|
columns_dir = columns_directory_path(table)
|
1452
1686
|
FileUtils.mkdir_p(columns_dir)
|
1453
1687
|
File.join(columns_dir, @name)
|
1454
1688
|
end
|
1455
1689
|
end
|
1456
1690
|
|
1457
|
-
|
1691
|
+
# @private
|
1692
|
+
class ColumnRemoveDefinition
|
1693
|
+
include Path
|
1694
|
+
|
1458
1695
|
attr_accessor :name
|
1459
1696
|
attr_reader :options
|
1460
1697
|
|
@@ -1476,11 +1713,46 @@ module Groonga
|
|
1476
1713
|
raise ColumnNotExists.new(name)
|
1477
1714
|
end
|
1478
1715
|
|
1479
|
-
column.remove
|
1716
|
+
result = column.remove
|
1717
|
+
columns_dir = columns_directory_path(table)
|
1718
|
+
rmdir_if_available(columns_dir)
|
1719
|
+
result
|
1720
|
+
end
|
1721
|
+
end
|
1722
|
+
|
1723
|
+
# @private
|
1724
|
+
class ColumnRenameDefinition
|
1725
|
+
include Path
|
1726
|
+
|
1727
|
+
attr_accessor :current_name, :new_name
|
1728
|
+
attr_reader :options
|
1729
|
+
|
1730
|
+
def initialize(current_name, new_name, options={})
|
1731
|
+
@current_name = current_name
|
1732
|
+
@current_name = @current_name.to_s if @current_name.is_a?(Symbol)
|
1733
|
+
@new_name = new_name
|
1734
|
+
@new_name = @new_name.to_s if @new_name.is_a?(Symbol)
|
1735
|
+
@options = (options || {}).dup
|
1736
|
+
end
|
1737
|
+
|
1738
|
+
def define(table_definition, table)
|
1739
|
+
if @current_name.respond_to?(:call)
|
1740
|
+
current_name = @current_name.call(table_definition.context)
|
1741
|
+
else
|
1742
|
+
current_name = @current_name
|
1743
|
+
end
|
1744
|
+
column = table.column(current_name)
|
1745
|
+
|
1746
|
+
if column.nil?
|
1747
|
+
raise ColumnNotExists.new(name)
|
1748
|
+
end
|
1749
|
+
|
1750
|
+
column.rename(@new_name)
|
1480
1751
|
end
|
1481
1752
|
end
|
1482
1753
|
|
1483
|
-
|
1754
|
+
# @private
|
1755
|
+
class IndexColumnDefinition
|
1484
1756
|
include Path
|
1485
1757
|
|
1486
1758
|
class << self
|
@@ -1581,6 +1853,7 @@ module Groonga
|
|
1581
1853
|
def path(context, table, name)
|
1582
1854
|
user_path = @options[:path]
|
1583
1855
|
return user_path if user_path
|
1856
|
+
return nil unless use_named_path?
|
1584
1857
|
columns_dir = "#{table.path}.columns"
|
1585
1858
|
FileUtils.mkdir_p(columns_dir)
|
1586
1859
|
File.join(columns_dir, name)
|