rroonga 1.2.9 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,4 +1,4 @@
|
|
1
|
-
/* -*- c-file-style: "ruby" -*- */
|
1
|
+
/* -*- coding: utf-8; c-file-style: "ruby" -*- */
|
2
2
|
/*
|
3
3
|
Copyright (C) 2010-2011 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
|
@@ -31,7 +31,7 @@ static VALUE cGrnContext;
|
|
31
31
|
*
|
32
32
|
* デフォルトで使用されるコンテキストは
|
33
33
|
* Groonga::Context#defaultでアクセスできる。コンテキストを
|
34
|
-
*
|
34
|
+
* 指定できる箇所でコンテキストの指定を省略したり +nil+ を指定
|
35
35
|
* した場合はGroonga::Context.defaultが利用される。
|
36
36
|
*
|
37
37
|
* また、デフォルトのコンテキストは必要になると暗黙のうちに
|
@@ -263,8 +263,8 @@ rb_grn_context_get_default (void)
|
|
263
263
|
* call-seq:
|
264
264
|
* Groonga::Context.default=(context)
|
265
265
|
*
|
266
|
-
*
|
267
|
-
*
|
266
|
+
* デフォルトのコンテキストを設定する。 +nil+ を指定すると、
|
267
|
+
* デフォルトのコンテキストをリセットする。リセットすると、次
|
268
268
|
* 回Groonga::Context.defaultを呼び出したときに新しくコンテ
|
269
269
|
* キストが作成される。
|
270
270
|
*/
|
@@ -307,10 +307,12 @@ rb_grn_context_s_set_default_options (VALUE self, VALUE options)
|
|
307
307
|
* call-seq:
|
308
308
|
* Groonga::Context.new(options=nil)
|
309
309
|
*
|
310
|
-
* コンテキストを作成する。_options_に指定可能な値は以下の通
|
310
|
+
* コンテキストを作成する。 _options_ に指定可能な値は以下の通
|
311
311
|
* り。
|
312
|
+
* @param [::Hash] options The name and value
|
313
|
+
* pairs. Omitted names are initialized as the default value.
|
314
|
+
* @option options :encoding The encoding
|
312
315
|
*
|
313
|
-
* [+:encoding+]
|
314
316
|
* エンコーディングを指定する。エンコーディングの指定方法
|
315
317
|
* はGroonga::Encodingを参照。
|
316
318
|
*/
|
@@ -510,8 +512,8 @@ rb_grn_context_set_match_escalation_threshold (VALUE self, VALUE threshold)
|
|
510
512
|
* call-seq:
|
511
513
|
* context.support_zlib?
|
512
514
|
*
|
513
|
-
* groongaがZlib
|
514
|
-
*
|
515
|
+
* groongaがZlibサポート付きでビルドされていれば +true+ 、そう
|
516
|
+
* でなければ +false+ を返す。
|
515
517
|
*/
|
516
518
|
static VALUE
|
517
519
|
rb_grn_context_support_zlib_p (VALUE self)
|
@@ -533,8 +535,8 @@ rb_grn_context_support_zlib_p (VALUE self)
|
|
533
535
|
* call-seq:
|
534
536
|
* context.support_lzo?
|
535
537
|
*
|
536
|
-
* groongaがLZO
|
537
|
-
*
|
538
|
+
* groongaがLZOサポート付きでビルドされていれば +true+ 、そう
|
539
|
+
* でなければ +false+ を返す。
|
538
540
|
*/
|
539
541
|
static VALUE
|
540
542
|
rb_grn_context_support_lzo_p (VALUE self)
|
@@ -571,14 +573,16 @@ rb_grn_context_get_database (VALUE self)
|
|
571
573
|
* call-seq:
|
572
574
|
* context.connect(options=nil)
|
573
575
|
*
|
574
|
-
* groongaサーバに接続する。_options_に指定可能な値は以下の通
|
576
|
+
* groongaサーバに接続する。 _options_ に指定可能な値は以下の通
|
575
577
|
* り。
|
578
|
+
* @param [::Hash] options The name and value
|
579
|
+
* pairs. Omitted names are initialized as the default value.
|
580
|
+
* @option options :host (localhost) The groonga server host name
|
576
581
|
*
|
577
|
-
* [+:host+]
|
578
582
|
* groongaサーバのホスト名。またはIPアドレス。省略すると
|
579
583
|
* "localhost"に接続する。
|
584
|
+
* @option options :port (10041) The port number
|
580
585
|
*
|
581
|
-
* [+:port+]
|
582
586
|
* groongaサーバのポート番号。省略すると10041番ポートに接
|
583
587
|
* 続する。
|
584
588
|
*/
|
@@ -749,10 +753,10 @@ rb_grn_context_get_backward_compatibility (grn_ctx *context,
|
|
749
753
|
*
|
750
754
|
* コンテキスト管理下にあるオブジェクトを返す。
|
751
755
|
*
|
752
|
-
* _name_として文字列を指定した場合はオブジェクト名でオブジェ
|
756
|
+
* _name_ として文字列を指定した場合はオブジェクト名でオブジェ
|
753
757
|
* クトを検索する。
|
754
758
|
*
|
755
|
-
* _id_として数値を指定した場合はオブジェクトIDでオブジェク
|
759
|
+
* _id_ として数値を指定した場合はオブジェクトIDでオブジェク
|
756
760
|
* トを検索する。
|
757
761
|
*/
|
758
762
|
static VALUE
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* -*- c-file-style: "ruby" -*- */
|
1
|
+
/* -*- coding: utf-8; c-file-style: "ruby" -*- */
|
2
2
|
/*
|
3
3
|
Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
|
@@ -125,7 +125,7 @@ rb_grn_database_deconstruct (RbGrnObject *rb_grn_database,
|
|
125
125
|
* call-seq:
|
126
126
|
* database.close
|
127
127
|
*
|
128
|
-
* _database_が使用しているリソースを開放する。これ以降_database_を
|
128
|
+
* _database_ が使用しているリソースを開放する。これ以降 _database_ を
|
129
129
|
* 使うことはできない。
|
130
130
|
*/
|
131
131
|
static VALUE
|
@@ -146,23 +146,24 @@ rb_grn_database_close (VALUE self)
|
|
146
146
|
*
|
147
147
|
* 新しくデータベースを作成する。
|
148
148
|
*
|
149
|
-
* _options_にはハッシュでオプションを指定する。指定できるオ
|
149
|
+
* _options_ にはハッシュでオプションを指定する。指定できるオ
|
150
150
|
* プションは以下の通り。
|
151
|
+
* @param option [::Hash] options The name and value
|
152
|
+
* pairs. Omitted names are initialized as the default value.
|
153
|
+
* @option options :path The path
|
151
154
|
*
|
152
|
-
* [+:path+]
|
153
155
|
* データベースを保存するパス。省略すると一時データベース
|
154
156
|
* となる。
|
157
|
+
* @option options :context (Groonga::Context.default) The context
|
155
158
|
*
|
156
|
-
* [+:context+]
|
157
159
|
* データベースを結びつけるコンテキスト。省略すると
|
158
160
|
* Groonga::Context.defaultを利用する。
|
159
161
|
*
|
160
|
-
*
|
161
|
-
*
|
162
|
-
* 一時データベースを作成:
|
162
|
+
* @example
|
163
|
+
* 一時データベースを作成:
|
163
164
|
* Groonga::Database.create
|
164
165
|
*
|
165
|
-
*
|
166
|
+
* 永続データベースを作成:
|
166
167
|
* Groonga::Database.create(:path => "/tmp/db.groonga")
|
167
168
|
*/
|
168
169
|
static VALUE
|
@@ -219,10 +220,12 @@ rb_grn_database_s_create (int argc, VALUE *argv, VALUE klass)
|
|
219
220
|
* クに開いたデータベースを渡し、ブロックを抜けるときに閉じ
|
220
221
|
* る。
|
221
222
|
*
|
222
|
-
* _options_にはハッシュでオプションを指定する。指定できるオ
|
223
|
+
* _options_ にはハッシュでオプションを指定する。指定できるオ
|
223
224
|
* プションは以下の通り。
|
225
|
+
* @param options [::Hash] The name and value
|
226
|
+
* pairs. Omitted names are initialized as the default value.
|
227
|
+
* @option options :context (Groonga::Context.default) The context
|
224
228
|
*
|
225
|
-
* [+:context+]
|
226
229
|
* データベースを結びつけるコンテキスト。省略すると
|
227
230
|
* Groonga::Context.defaultを利用する。
|
228
231
|
*/
|
@@ -266,12 +269,13 @@ rb_grn_database_initialize (int argc, VALUE *argv, VALUE self)
|
|
266
269
|
* クに開いたデータベースを渡し、ブロックを抜けるときに閉じ
|
267
270
|
* る。
|
268
271
|
*
|
269
|
-
* _options_にはハッシュでオプションを指定する。指定できるオ
|
272
|
+
* _options_ にはハッシュでオプションを指定する。指定できるオ
|
270
273
|
* プションは以下の通り。
|
274
|
+
* @param options [::Hash] The name and value
|
275
|
+
* pairs. Omitted names are initialized as the default value.
|
276
|
+
* @option options :context (Groonga::Context.default) The context
|
271
277
|
*
|
272
|
-
*
|
273
|
-
* データベースを結びつけるコンテキスト。省略すると
|
274
|
-
* Groonga::Context.defaultを利用する。
|
278
|
+
* データベースを結びつけるコンテキスト。
|
275
279
|
*/
|
276
280
|
static VALUE
|
277
281
|
rb_grn_database_s_open (int argc, VALUE *argv, VALUE klass)
|
@@ -293,36 +297,35 @@ rb_grn_database_s_open (int argc, VALUE *argv, VALUE klass)
|
|
293
297
|
*
|
294
298
|
* データベース内のオブジェクトを順番にブロックに渡す。
|
295
299
|
*
|
296
|
-
*
|
297
|
-
* プションは以下の通り。
|
298
|
-
*
|
299
|
-
* [+:order+]
|
300
|
-
* +:asc+または+:ascending+を指定すると昇順にレコードを取
|
301
|
-
* り出す。(デフォルト)
|
302
|
-
*
|
303
|
-
* +:desc+または+:descending+を指定すると降順にレコードを
|
304
|
-
* 取り出す。
|
305
|
-
*
|
306
|
-
* [+:order_by+]
|
307
|
-
* +:id+を指定するとID順にレコードを取り出す。
|
308
|
-
*
|
309
|
-
* +:key+指定するとキー順にレコードを取り出す。(デフォル
|
310
|
-
* ト)
|
311
|
-
*
|
312
|
-
* すべてのオブジェクトの名前を表示する:
|
300
|
+
* @example すべてのオブジェクトの名前を表示する:
|
313
301
|
* database.each do |object|
|
314
302
|
* p object.name
|
315
303
|
* end
|
316
304
|
*
|
317
|
-
* すべてのオブジェクトの名前をID順で表示する:
|
305
|
+
* @example すべてのオブジェクトの名前をID順で表示する:
|
318
306
|
* database.each(:order_by => :id) do |object|
|
319
307
|
* p object.name
|
320
308
|
* end
|
321
309
|
*
|
322
|
-
* すべてのオブジェクトの名前をキー名の降順で表示する:
|
310
|
+
* @example すべてのオブジェクトの名前をキー名の降順で表示する:
|
323
311
|
* database.each(:order_by => :key, :order => :desc) do |object|
|
324
312
|
* p object.name
|
325
313
|
* end
|
314
|
+
*
|
315
|
+
* @param options [::Hash]
|
316
|
+
* @option options :order The order
|
317
|
+
* +:asc+ または +:ascending+ を指定すると昇順にレコードを取
|
318
|
+
* り出す。(デフォルト)
|
319
|
+
*
|
320
|
+
* +:desc+ または +:descending+ を指定すると降順にレコードを
|
321
|
+
* 取り出す。
|
322
|
+
*
|
323
|
+
* @option options :order_by (:key) The ordef by
|
324
|
+
* +:id+ を指定するとID順にレコードを取り出す。
|
325
|
+
*
|
326
|
+
* +:key+ 指定するとキー順にレコードを取り出す。(デフォル
|
327
|
+
* ト)
|
328
|
+
*
|
326
329
|
*/
|
327
330
|
static VALUE
|
328
331
|
rb_grn_database_each (int argc, VALUE *argv, VALUE self)
|
@@ -373,7 +376,7 @@ rb_grn_database_each (int argc, VALUE *argv, VALUE self)
|
|
373
376
|
* call-seq:
|
374
377
|
* database.unlock
|
375
378
|
*
|
376
|
-
* _database_のロックを解除する。
|
379
|
+
* _database_ のロックを解除する。
|
377
380
|
*/
|
378
381
|
static VALUE
|
379
382
|
rb_grn_database_unlock (VALUE self)
|
@@ -399,16 +402,18 @@ rb_grn_database_unlock (VALUE self)
|
|
399
402
|
* database.lock(options={})
|
400
403
|
* database.lock(options={}) {...}
|
401
404
|
*
|
402
|
-
* _database_をロックする。ロックに失敗した場合は
|
405
|
+
* _database_ をロックする。ロックに失敗した場合は
|
403
406
|
* Groonga::ResourceDeadlockAvoided例外が発生する。
|
404
407
|
*
|
405
408
|
* ブロックを指定した場合はブロックを抜けたときにunlockする。
|
406
409
|
*
|
407
410
|
* 利用可能なオプションは以下の通り。
|
411
|
+
* @param [::Hash] options The name and value
|
412
|
+
* pairs. Omitted names are initialized as the default value
|
413
|
+
* @option options :timeout The timeout
|
408
414
|
*
|
409
|
-
*
|
410
|
-
*
|
411
|
-
* 得を試みる。_:timeout_秒以内にロックを獲得できなかった
|
415
|
+
* ロックを獲得できなかった場合は _:timeout_ 秒間ロックの獲
|
416
|
+
* 得を試みる。 _:timeout_ 秒以内にロックを獲得できなかった
|
412
417
|
* 場合は例外が発生する。
|
413
418
|
*/
|
414
419
|
static VALUE
|
@@ -449,7 +454,7 @@ rb_grn_database_lock (int argc, VALUE *argv, VALUE self)
|
|
449
454
|
* call-seq:
|
450
455
|
* database.clear_lock
|
451
456
|
*
|
452
|
-
* _database_のロックを強制的に解除する。
|
457
|
+
* _database_ のロックを強制的に解除する。
|
453
458
|
*/
|
454
459
|
static VALUE
|
455
460
|
rb_grn_database_clear_lock (VALUE self)
|
@@ -471,7 +476,7 @@ rb_grn_database_clear_lock (VALUE self)
|
|
471
476
|
* call-seq:
|
472
477
|
* database.locked?
|
473
478
|
*
|
474
|
-
* _database_
|
479
|
+
* _database_ がロックされていれば +true+ を返す。
|
475
480
|
*/
|
476
481
|
static VALUE
|
477
482
|
rb_grn_database_is_locked (VALUE self)
|
@@ -491,7 +496,7 @@ rb_grn_database_is_locked (VALUE self)
|
|
491
496
|
* call-seq:
|
492
497
|
* database.touch
|
493
498
|
*
|
494
|
-
* _database_の最終更新時刻を現在時刻にする。
|
499
|
+
* _database_ の最終更新時刻を現在時刻にする。
|
495
500
|
*/
|
496
501
|
static VALUE
|
497
502
|
rb_grn_database_touch (VALUE self)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/* -*- coding: utf-8; c-file-style: "ruby" -*- */
|
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
|
+
|
19
|
+
#include "rb-grn.h"
|
20
|
+
|
21
|
+
VALUE rb_cGrnDoubleArrayTrieCursor;
|
22
|
+
|
23
|
+
/*
|
24
|
+
* Document-class: Groonga::DoubleArrayCursor < Groonga::TableCursor
|
25
|
+
*
|
26
|
+
* Groonga::DoubleArrayに登録されているレコードを順番に取り
|
27
|
+
* 出すためのオブジェクト。利用できるメソッドは
|
28
|
+
* Groonga::TableCursorとGroonga::TableCursor::KeySupportを
|
29
|
+
* 参照。
|
30
|
+
*/
|
31
|
+
|
32
|
+
void
|
33
|
+
rb_grn_init_double_array_trie_cursor (VALUE mGrn)
|
34
|
+
{
|
35
|
+
rb_cGrnDoubleArrayTrieCursor =
|
36
|
+
rb_define_class_under(mGrn, "DoubleArrayTrieCursor", rb_cGrnTableCursor);
|
37
|
+
|
38
|
+
rb_include_module(rb_cGrnDoubleArrayTrieCursor,
|
39
|
+
rb_mGrnTableCursorKeySupport);
|
40
|
+
}
|
@@ -0,0 +1,530 @@
|
|
1
|
+
/* -*- coding: utf-8; c-file-style: "ruby" -*- */
|
2
|
+
/* vim: set sts=4 sw=4 ts=8 noet: */
|
3
|
+
/*
|
4
|
+
Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License version 2.1 as published by the Free Software Foundation.
|
9
|
+
|
10
|
+
This library is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public
|
16
|
+
License along with this library; if not, write to the Free Software
|
17
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
*/
|
19
|
+
|
20
|
+
#include "rb-grn.h"
|
21
|
+
|
22
|
+
#define SELF(object) ((RbGrnTableKeySupport *)DATA_PTR(object))
|
23
|
+
|
24
|
+
VALUE rb_cGrnDoubleArrayTrie;
|
25
|
+
|
26
|
+
/*
|
27
|
+
* Document-class: Groonga::DoubleArrayTrie < Groonga::Table
|
28
|
+
*
|
29
|
+
* It's a table that manages records by double array
|
30
|
+
* trie. It can change key without ID change. This feature
|
31
|
+
* is supported by only Groonga::DoubleArrayTrie. But it
|
32
|
+
* requires large spaces rather than other tables. It is
|
33
|
+
* used by Groonga::Database for key management
|
34
|
+
* internally. It's reasonable choice because number of
|
35
|
+
* tables and columns in Groonga::Database (number of their
|
36
|
+
* names equals to number of keys to be managed by
|
37
|
+
* Groonga::DoubleArrayTrie) will be less than number of
|
38
|
+
* records of user defined tables.
|
39
|
+
*
|
40
|
+
* Groonga::DoubleArrayTrie supports exact match search,
|
41
|
+
* predictive search and common prefix search like
|
42
|
+
* Groonga::PatriciaTrie. It also supports cursor API.
|
43
|
+
*/
|
44
|
+
|
45
|
+
/*
|
46
|
+
* call-seq:
|
47
|
+
* Groonga::DoubleArrayTrie.create(options={}) -> Groonga::DoubleArrayTrie
|
48
|
+
* Groonga::DoubleArrayTrie.create(options={}) {|table| ... }
|
49
|
+
*
|
50
|
+
* It creates a table that manages records by double array trie.
|
51
|
+
* ブロックを指定すると、そのブロックに生成したテーブルが渡さ
|
52
|
+
* れ、ブロックを抜けると自動的にテーブルが破棄される。
|
53
|
+
*
|
54
|
+
* _options_ に指定可能な値は以下の通り。
|
55
|
+
* @param options [::Hash] The name and value
|
56
|
+
* pairs. Omitted names are initialized as the default value.
|
57
|
+
* @option options [Groonga::Context] :context (Groonga::Context.default)
|
58
|
+
*
|
59
|
+
* テーブルが利用するGroonga::Context。
|
60
|
+
*
|
61
|
+
* @option options :name The table name
|
62
|
+
*
|
63
|
+
* テーブルの名前。名前をつけると、Groonga::Context#[]に名
|
64
|
+
* 前を指定してテーブルを取得することができる。省略すると
|
65
|
+
* 無名テーブルになり、テーブルIDでのみ取得できる。
|
66
|
+
*
|
67
|
+
* @option options :path The path
|
68
|
+
*
|
69
|
+
* テーブルを保存するパス。パスを指定すると永続テーブルとな
|
70
|
+
* り、プロセス終了後もレコードは保持される。次回起動時に
|
71
|
+
* Groonga::Context#[]で保存されたレコードを利用する
|
72
|
+
* ことができる。省略すると一時テーブルになり、プロセスが終
|
73
|
+
* 了するとレコードは破棄される。
|
74
|
+
*
|
75
|
+
* @option options :persistent The persistent
|
76
|
+
*
|
77
|
+
* +true+ を指定すると永続テーブルとなる。 +path+ を省略した
|
78
|
+
* 場合は自動的にパスが付加される。 +:context+ で指定した
|
79
|
+
* Groonga::Contextに結びついているデータベースが一時デー
|
80
|
+
* タベースの場合は例外が発生する。
|
81
|
+
*
|
82
|
+
* @option options :key_normalize The key_normalize
|
83
|
+
*
|
84
|
+
* +true+ を指定するとキーを正規化する。
|
85
|
+
*
|
86
|
+
* @option options :key_with_sis The key_with_sis
|
87
|
+
*
|
88
|
+
* +true+ を指定するとキーの文字列の全suffixが自動的に登
|
89
|
+
* 録される。
|
90
|
+
*
|
91
|
+
* @option options :key_type The key_type
|
92
|
+
*
|
93
|
+
* キーの種類を示すオブジェクトを指定する。キーの種類には型
|
94
|
+
* 名("Int32"や"ShortText"など)またはGroonga::Typeまたは
|
95
|
+
* テーブル(Groonga::Array、Groonga::Hash、
|
96
|
+
* Groonga::DoubleArrayTrieのどれか)を指定する。
|
97
|
+
*
|
98
|
+
* Groonga::Typeを指定した場合は、その型が示す範囲の値をキー
|
99
|
+
* として使用する。ただし、キーの最大サイズは4096バイトで
|
100
|
+
* あるため、Groonga::Type::TEXTやGroonga::Type::LONG_TEXT
|
101
|
+
* は使用できない。
|
102
|
+
*
|
103
|
+
* テーブルを指定した場合はレコードIDをキーとして使用する。
|
104
|
+
* 指定したテーブルのGroonga::Recordをキーとして使用するこ
|
105
|
+
* ともでき、その場合は自動的にGroonga::Recordからレコード
|
106
|
+
* IDを取得する。
|
107
|
+
*
|
108
|
+
* 省略した場合はShortText型をキーとして使用する。この場合、
|
109
|
+
* 4096バイトまで使用可能である。
|
110
|
+
*
|
111
|
+
* @option options :value_type The value_type
|
112
|
+
*
|
113
|
+
* 値の型を指定する。省略すると値のための領域を確保しない。
|
114
|
+
* 値を保存したい場合は必ず指定すること。
|
115
|
+
*
|
116
|
+
* 参考: Groonga::Type.new
|
117
|
+
*
|
118
|
+
* @option options :default_tokenizer The default_tokenizer
|
119
|
+
*
|
120
|
+
* Groonga::IndexColumnで使用するトークナイザを指定する。
|
121
|
+
* デフォルトでは何も設定されていないので、テーブルに
|
122
|
+
* Groonga::IndexColumnを定義する場合は
|
123
|
+
* <tt>"TokenBigram"</tt>などを指定する必要がある。
|
124
|
+
*
|
125
|
+
* @option options :sub_records The sub_records
|
126
|
+
*
|
127
|
+
* +true+ を指定すると#groupでグループ化したときに、
|
128
|
+
* Groonga::Record#n_sub_recordsでグループに含まれるレコー
|
129
|
+
* ドの件数を取得できる。
|
130
|
+
*
|
131
|
+
* @example
|
132
|
+
* #無名一時テーブルを生成する。
|
133
|
+
* Groonga::DoubleArrayTrie.create
|
134
|
+
*
|
135
|
+
* #無名永続テーブルを生成する。
|
136
|
+
* Groonga::DoubleArrayTrie.create(:path => "/tmp/hash.grn")
|
137
|
+
*
|
138
|
+
* #名前付き永続テーブルを生成する。ただし、ファイル名は気に
|
139
|
+
* #しない。
|
140
|
+
* Groonga::DoubleArrayTrie.create(:name => "Bookmarks",
|
141
|
+
* :persistent => true)
|
142
|
+
*
|
143
|
+
* #それぞれのレコードに512バイトの値を格納できる無名一時テー
|
144
|
+
* #ブルを生成する。
|
145
|
+
* Groonga::DoubleArrayTrie.create(:value => 512)
|
146
|
+
*
|
147
|
+
* #キーとして文字列を使用する無名一時テーブルを生成する。
|
148
|
+
* Groonga::DoubleArrayTrie.create(:key_type => Groonga::Type::SHORT_TEXT)
|
149
|
+
*
|
150
|
+
* #キーとして文字列を使用する無名一時テーブルを生成する。
|
151
|
+
* #(キーの種類を表すオブジェクトは文字列で指定。)
|
152
|
+
* Groonga::DoubleArrayTrie.create(:key_type => "ShortText")
|
153
|
+
*
|
154
|
+
* #キーとして<tt>Bookmarks</tt>テーブルのレコードを使用す
|
155
|
+
* #る無名一時テーブルを生成する。
|
156
|
+
* bookmarks = Groonga::DoubleArrayTrie.create(:name => "Bookmarks")
|
157
|
+
* Groonga::DoubleArrayTrie.create(:key_type => bookmarks)
|
158
|
+
*
|
159
|
+
* #キーとして<tt>Bookmarks</tt>テーブルのレコードを使用す
|
160
|
+
* #る無名一時テーブルを生成する。
|
161
|
+
* #(テーブルは文字列で指定。)
|
162
|
+
* Groonga::DoubleArrayTrie.create(:name => "Bookmarks")
|
163
|
+
* Groonga::DoubleArrayTrie.create(:key_type => "Bookmarks")
|
164
|
+
*
|
165
|
+
* #全文検索用のトークンをバイグラムで切り出す無名一時テーブ
|
166
|
+
* #ルを生成する。
|
167
|
+
* bookmarks = Groonga::DoubleArrayTrie.create(:name => "Bookmarks")
|
168
|
+
* bookmarks.define_column("comment", "Text")
|
169
|
+
* terms = Groonga::DoubleArrayTrie.create(:name => "Terms",
|
170
|
+
* :default_tokenizer => "TokenBigram")
|
171
|
+
* terms.define_index_column("content", bookmarks,
|
172
|
+
* :source => "Bookmarks.comment")
|
173
|
+
*/
|
174
|
+
static VALUE
|
175
|
+
rb_grn_double_array_trie_s_create (int argc, VALUE *argv, VALUE klass)
|
176
|
+
{
|
177
|
+
grn_ctx *context;
|
178
|
+
grn_obj *key_type = NULL, *value_type = NULL, *table;
|
179
|
+
const char *name = NULL, *path = NULL;
|
180
|
+
unsigned name_size = 0;
|
181
|
+
grn_obj_flags flags = GRN_OBJ_TABLE_DAT_KEY;
|
182
|
+
VALUE rb_table;
|
183
|
+
VALUE options, rb_context, rb_name, rb_path, rb_persistent;
|
184
|
+
VALUE rb_key_normalize, rb_key_with_sis, rb_key_type;
|
185
|
+
VALUE rb_value_type;
|
186
|
+
VALUE rb_default_tokenizer, rb_sub_records;
|
187
|
+
|
188
|
+
rb_scan_args(argc, argv, "01", &options);
|
189
|
+
|
190
|
+
rb_grn_scan_options(options,
|
191
|
+
"context", &rb_context,
|
192
|
+
"name", &rb_name,
|
193
|
+
"path", &rb_path,
|
194
|
+
"persistent", &rb_persistent,
|
195
|
+
"key_normalize", &rb_key_normalize,
|
196
|
+
"key_with_sis", &rb_key_with_sis,
|
197
|
+
"key_type", &rb_key_type,
|
198
|
+
"value_type", &rb_value_type,
|
199
|
+
"default_tokenizer", &rb_default_tokenizer,
|
200
|
+
"sub_records", &rb_sub_records,
|
201
|
+
NULL);
|
202
|
+
|
203
|
+
context = rb_grn_context_ensure(&rb_context);
|
204
|
+
|
205
|
+
if (!NIL_P(rb_name)) {
|
206
|
+
name = StringValuePtr(rb_name);
|
207
|
+
name_size = RSTRING_LEN(rb_name);
|
208
|
+
flags |= GRN_OBJ_PERSISTENT;
|
209
|
+
}
|
210
|
+
|
211
|
+
if (!NIL_P(rb_path)) {
|
212
|
+
path = StringValueCStr(rb_path);
|
213
|
+
flags |= GRN_OBJ_PERSISTENT;
|
214
|
+
}
|
215
|
+
|
216
|
+
if (RVAL2CBOOL(rb_persistent))
|
217
|
+
flags |= GRN_OBJ_PERSISTENT;
|
218
|
+
|
219
|
+
if (RVAL2CBOOL(rb_key_normalize))
|
220
|
+
flags |= GRN_OBJ_KEY_NORMALIZE;
|
221
|
+
|
222
|
+
if (RVAL2CBOOL(rb_key_with_sis))
|
223
|
+
flags |= GRN_OBJ_KEY_WITH_SIS;
|
224
|
+
|
225
|
+
if (NIL_P(rb_key_type)) {
|
226
|
+
key_type = grn_ctx_at(context, GRN_DB_SHORT_TEXT);
|
227
|
+
} else {
|
228
|
+
key_type = RVAL2GRNOBJECT(rb_key_type, &context);
|
229
|
+
}
|
230
|
+
|
231
|
+
if (!NIL_P(rb_value_type))
|
232
|
+
value_type = RVAL2GRNOBJECT(rb_value_type, &context);
|
233
|
+
|
234
|
+
if (RVAL2CBOOL(rb_sub_records))
|
235
|
+
flags |= GRN_OBJ_WITH_SUBREC;
|
236
|
+
|
237
|
+
table = grn_table_create(context, name, name_size, path,
|
238
|
+
flags, key_type, value_type);
|
239
|
+
if (!table)
|
240
|
+
rb_grn_context_check(context, rb_ary_new4(argc, argv));
|
241
|
+
rb_table = GRNOBJECT2RVAL(klass, context, table, GRN_TRUE);
|
242
|
+
|
243
|
+
if (!NIL_P(rb_default_tokenizer))
|
244
|
+
rb_funcall(rb_table, rb_intern("default_tokenizer="), 1,
|
245
|
+
rb_default_tokenizer);
|
246
|
+
|
247
|
+
if (rb_block_given_p())
|
248
|
+
return rb_ensure(rb_yield, rb_table, rb_grn_object_close, rb_table);
|
249
|
+
else
|
250
|
+
return rb_table;
|
251
|
+
}
|
252
|
+
|
253
|
+
/*
|
254
|
+
* call-seq:
|
255
|
+
* double_array_trie.search(key, options=nil) -> Groonga::Hash
|
256
|
+
*
|
257
|
+
* _key_ にマッチするレコードのIDがキーに入っている
|
258
|
+
* Groonga::Hashを返す。マッチするレコードがない場合は空の
|
259
|
+
* Groonga::Hashが返る。
|
260
|
+
*
|
261
|
+
* _options_ で +:result+ を指定することにより、そのテーブルにマッ
|
262
|
+
* チしたレコードIDがキーのレコードを追加することができる。
|
263
|
+
* +:result+ にテーブルを指定した場合は、そのテーブルが返る。
|
264
|
+
*
|
265
|
+
* _options_ に指定可能な値は以下の通り。
|
266
|
+
* @param options [::Hash] The name and value
|
267
|
+
* pairs. Omitted names are initialized as the default value.
|
268
|
+
* @option options :result The result
|
269
|
+
*
|
270
|
+
* 結果を格納するテーブル。
|
271
|
+
* @option options :operator (Groonga::Operator::OR)
|
272
|
+
*
|
273
|
+
* マッチしたレコードをどのように扱うか。指定可能な値は以
|
274
|
+
* 下の通り。
|
275
|
+
*
|
276
|
+
* [Groonga::Operator::OR]
|
277
|
+
* マッチしたレコードを追加。すでにレコードが追加され
|
278
|
+
* ている場合は何もしない。
|
279
|
+
* [Groonga::Operator::AND]
|
280
|
+
* マッチしたレコードのスコアを増加。マッチしなかった
|
281
|
+
* レコードを削除。
|
282
|
+
* [Groonga::Operator::BUT]
|
283
|
+
* マッチしたレコードを削除。
|
284
|
+
* [Groonga::Operator::ADJUST]
|
285
|
+
* マッチしたレコードのスコアを増加。
|
286
|
+
*
|
287
|
+
* [+:type+]
|
288
|
+
* ?????
|
289
|
+
*
|
290
|
+
* 複数のキーで検索し、結果を1つのテーブルに集める。
|
291
|
+
* result = nil
|
292
|
+
* keys = ["morita", "gunyara-kun", "yu"]
|
293
|
+
* keys.each do |key|
|
294
|
+
* result = users.search(key, :result => result)
|
295
|
+
* end
|
296
|
+
* result.each do |record|
|
297
|
+
* user = record.key
|
298
|
+
* p user.key # -> "morita"または"gunyara-kun"または"yu"
|
299
|
+
* end
|
300
|
+
*/
|
301
|
+
static VALUE
|
302
|
+
rb_grn_double_array_trie_search (int argc, VALUE *argv, VALUE self)
|
303
|
+
{
|
304
|
+
grn_rc rc;
|
305
|
+
grn_ctx *context;
|
306
|
+
grn_obj *table;
|
307
|
+
grn_id domain_id;
|
308
|
+
grn_obj *key, *domain, *result;
|
309
|
+
grn_operator operator;
|
310
|
+
grn_search_optarg search_options;
|
311
|
+
grn_bool search_options_is_set = GRN_FALSE;
|
312
|
+
VALUE rb_key, options, rb_result, rb_operator, rb_type;
|
313
|
+
|
314
|
+
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
315
|
+
&key, &domain_id, &domain,
|
316
|
+
NULL, NULL, NULL,
|
317
|
+
NULL);
|
318
|
+
|
319
|
+
rb_scan_args(argc, argv, "11", &rb_key, &options);
|
320
|
+
|
321
|
+
RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self);
|
322
|
+
|
323
|
+
rb_grn_scan_options(options,
|
324
|
+
"result", &rb_result,
|
325
|
+
"operator", &rb_operator,
|
326
|
+
"type", &rb_type,
|
327
|
+
NULL);
|
328
|
+
|
329
|
+
if (NIL_P(rb_result)) {
|
330
|
+
result = grn_table_create(context, NULL, 0, NULL,
|
331
|
+
GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
|
332
|
+
table, 0);
|
333
|
+
rb_grn_context_check(context, self);
|
334
|
+
rb_result = GRNOBJECT2RVAL(Qnil, context, result, GRN_TRUE);
|
335
|
+
} else {
|
336
|
+
result = RVAL2GRNOBJECT(rb_result, &context);
|
337
|
+
}
|
338
|
+
|
339
|
+
operator = RVAL2GRNOPERATOR(rb_operator);
|
340
|
+
|
341
|
+
rc = grn_obj_search(context, table, key,
|
342
|
+
result, operator,
|
343
|
+
search_options_is_set ? &search_options : NULL);
|
344
|
+
rb_grn_rc_check(rc, self);
|
345
|
+
|
346
|
+
return rb_result;
|
347
|
+
}
|
348
|
+
|
349
|
+
static grn_table_cursor *
|
350
|
+
rb_grn_double_array_trie_open_grn_prefix_cursor (int argc, VALUE *argv,
|
351
|
+
VALUE self, grn_ctx **context)
|
352
|
+
{
|
353
|
+
grn_obj *table;
|
354
|
+
grn_table_cursor *cursor;
|
355
|
+
void *prefix = NULL;
|
356
|
+
unsigned prefix_size = 0;
|
357
|
+
int offset = 0, limit = -1;
|
358
|
+
int flags = GRN_CURSOR_PREFIX;
|
359
|
+
VALUE options, rb_prefix, rb_key_bytes, rb_key_bits;
|
360
|
+
VALUE rb_order, rb_order_by;
|
361
|
+
VALUE rb_greater_than, rb_less_than, rb_offset, rb_limit;
|
362
|
+
|
363
|
+
rb_grn_table_deconstruct((RbGrnTable *)SELF(self), &table, context,
|
364
|
+
NULL, NULL,
|
365
|
+
NULL, NULL, NULL,
|
366
|
+
NULL);
|
367
|
+
|
368
|
+
rb_scan_args(argc, argv, "11", &rb_prefix, &options);
|
369
|
+
|
370
|
+
rb_grn_scan_options(options,
|
371
|
+
"key_bytes", &rb_key_bytes,
|
372
|
+
"key_bites", &rb_key_bits,
|
373
|
+
"offset", &rb_offset,
|
374
|
+
"limit", &rb_limit,
|
375
|
+
"order", &rb_order,
|
376
|
+
"order_by", &rb_order_by,
|
377
|
+
"greater_than", &rb_greater_than,
|
378
|
+
"less_than", &rb_less_than,
|
379
|
+
NULL);
|
380
|
+
|
381
|
+
prefix = StringValuePtr(rb_prefix);
|
382
|
+
if (!NIL_P(rb_key_bytes) && !NIL_P(rb_key_bits)) {
|
383
|
+
rb_raise(rb_eArgError,
|
384
|
+
"should not specify both :key_bytes and :key_bits once: %s",
|
385
|
+
rb_grn_inspect(rb_ary_new4(argc, argv)));
|
386
|
+
} else if (!NIL_P(rb_key_bytes)) {
|
387
|
+
prefix_size = NUM2UINT(rb_key_bytes);
|
388
|
+
} else if (!NIL_P(rb_key_bits)) {
|
389
|
+
prefix_size = NUM2UINT(rb_key_bits);
|
390
|
+
flags |= GRN_CURSOR_SIZE_BY_BIT;
|
391
|
+
} else {
|
392
|
+
prefix_size = RSTRING_LEN(rb_prefix);
|
393
|
+
}
|
394
|
+
if (!NIL_P(rb_offset))
|
395
|
+
offset = NUM2INT(rb_offset);
|
396
|
+
if (!NIL_P(rb_limit))
|
397
|
+
limit = NUM2INT(rb_limit);
|
398
|
+
|
399
|
+
if (NIL_P(rb_order)) {
|
400
|
+
} else if (rb_grn_equal_option(rb_order, "asc") ||
|
401
|
+
rb_grn_equal_option(rb_order, "ascending")) {
|
402
|
+
flags |= GRN_CURSOR_ASCENDING;
|
403
|
+
} else if (rb_grn_equal_option(rb_order, "desc") ||
|
404
|
+
rb_grn_equal_option(rb_order, "descending")) {
|
405
|
+
flags |= GRN_CURSOR_DESCENDING;
|
406
|
+
} else {
|
407
|
+
rb_raise(rb_eArgError,
|
408
|
+
"order should be one of "
|
409
|
+
"[:asc, :ascending, :desc, :descending]: %s",
|
410
|
+
rb_grn_inspect(rb_order));
|
411
|
+
}
|
412
|
+
if (NIL_P(rb_order_by)) {
|
413
|
+
} else if (rb_grn_equal_option(rb_order_by, "id")) {
|
414
|
+
flags |= GRN_CURSOR_BY_ID;
|
415
|
+
} else if (rb_grn_equal_option(rb_order_by, "key")) {
|
416
|
+
if (table->header.type != GRN_TABLE_PAT_KEY) {
|
417
|
+
rb_raise(rb_eArgError,
|
418
|
+
"order_by => :key is available "
|
419
|
+
"only for Groonga::DoubleArrayTrie: %s",
|
420
|
+
rb_grn_inspect(self));
|
421
|
+
}
|
422
|
+
flags |= GRN_CURSOR_BY_KEY;
|
423
|
+
} else {
|
424
|
+
rb_raise(rb_eArgError,
|
425
|
+
"order_by should be one of [:id%s]: %s",
|
426
|
+
table->header.type == GRN_TABLE_PAT_KEY ? ", :key" : "",
|
427
|
+
rb_grn_inspect(rb_order_by));
|
428
|
+
}
|
429
|
+
|
430
|
+
if (RVAL2CBOOL(rb_greater_than))
|
431
|
+
flags |= GRN_CURSOR_GT;
|
432
|
+
if (RVAL2CBOOL(rb_less_than))
|
433
|
+
flags |= GRN_CURSOR_LT;
|
434
|
+
|
435
|
+
cursor = grn_table_cursor_open(*context, table,
|
436
|
+
prefix, prefix_size,
|
437
|
+
NULL, 0,
|
438
|
+
offset, limit, flags);
|
439
|
+
rb_grn_context_check(*context, self);
|
440
|
+
|
441
|
+
return cursor;
|
442
|
+
}
|
443
|
+
|
444
|
+
|
445
|
+
/*
|
446
|
+
* call-seq:
|
447
|
+
* table.open_prefix_cursor(prefix, options={}) -> Groonga::DoubleArrayTrieCursor
|
448
|
+
* table.open_prefix_cursor(prefix, options={}) {|cursor| ... }
|
449
|
+
*
|
450
|
+
* _prefix_ に前方一致検索をするカーソルを生成して返す。ブロッ
|
451
|
+
* クを指定すると、そのブロックに生成したカーソルが渡され、ブ
|
452
|
+
* ロックを抜けると自動的にカーソルが破棄される。
|
453
|
+
*
|
454
|
+
* _options_ に指定可能な値は以下の通り。
|
455
|
+
* @param options [::Hash] The name and value
|
456
|
+
* pairs. Omitted names are initialized as the default value.
|
457
|
+
* @option options :key_bytes The key_bytes
|
458
|
+
*
|
459
|
+
* _prefix_ のサイズ(byte)
|
460
|
+
*
|
461
|
+
* @option options :key_bits The key_bits
|
462
|
+
*
|
463
|
+
* _prefix_ のサイズ(bit)
|
464
|
+
*
|
465
|
+
* @option options :offset The offset
|
466
|
+
*
|
467
|
+
* 該当する範囲のレコードのうち、(0ベースで) _:offset_ 番目
|
468
|
+
* からレコードを取り出す。
|
469
|
+
*
|
470
|
+
* @option options :limit The limit
|
471
|
+
*
|
472
|
+
* 該当する範囲のレコードのうち、 _:limit_ 件のみを取り出す。
|
473
|
+
* 省略された場合または-1が指定された場合は、全件が指定され
|
474
|
+
* たものとみなす。
|
475
|
+
*
|
476
|
+
* @option options :order The order
|
477
|
+
*
|
478
|
+
* +:asc+ または +:ascending+ を指定すると昇順にレコードを取
|
479
|
+
* り出す。
|
480
|
+
* +:desc+ または +:descending+ を指定すると降順にレコードを
|
481
|
+
* 取り出す。
|
482
|
+
*
|
483
|
+
* @option options :order_by (:id) The order_by
|
484
|
+
*
|
485
|
+
* +:id+ を指定するとID順にレコードを取り出す。(デフォルト)
|
486
|
+
* +:key+指定するとキー順にレコードを取り出す。
|
487
|
+
*
|
488
|
+
* @option options :greater_than The greater_than
|
489
|
+
*
|
490
|
+
* +true+ を指定すると _prefix_ で指定した値に一致した [ +key+ ] を
|
491
|
+
* 範囲に含まない。
|
492
|
+
*
|
493
|
+
* @option options :less_than The less_than
|
494
|
+
*
|
495
|
+
* +true+ を指定すると _prefix_ で指定した値に一致した [ +key+ ] を
|
496
|
+
* 範囲に含まない。
|
497
|
+
*/
|
498
|
+
static VALUE
|
499
|
+
rb_grn_double_array_trie_open_prefix_cursor (int argc, VALUE *argv, VALUE self)
|
500
|
+
{
|
501
|
+
grn_ctx *context = NULL;
|
502
|
+
grn_table_cursor *cursor;
|
503
|
+
VALUE rb_cursor;
|
504
|
+
|
505
|
+
cursor = rb_grn_double_array_trie_open_grn_prefix_cursor(argc, argv,
|
506
|
+
self, &context);
|
507
|
+
rb_cursor = GRNTABLECURSOR2RVAL(Qnil, context, cursor);
|
508
|
+
rb_iv_set(rb_cursor, "@table", self); /* FIXME: cursor should mark table */
|
509
|
+
if (rb_block_given_p())
|
510
|
+
return rb_ensure(rb_yield, rb_cursor, rb_grn_object_close, rb_cursor);
|
511
|
+
else
|
512
|
+
return rb_cursor;
|
513
|
+
}
|
514
|
+
|
515
|
+
void
|
516
|
+
rb_grn_init_double_array_trie (VALUE mGrn)
|
517
|
+
{
|
518
|
+
rb_cGrnDoubleArrayTrie =
|
519
|
+
rb_define_class_under(mGrn, "DoubleArrayTrie", rb_cGrnTable);
|
520
|
+
|
521
|
+
rb_include_module(rb_cGrnDoubleArrayTrie, rb_mGrnTableKeySupport);
|
522
|
+
rb_define_singleton_method(rb_cGrnDoubleArrayTrie, "create",
|
523
|
+
rb_grn_double_array_trie_s_create, -1);
|
524
|
+
|
525
|
+
rb_define_method(rb_cGrnDoubleArrayTrie, "search",
|
526
|
+
rb_grn_double_array_trie_search, -1);
|
527
|
+
|
528
|
+
rb_define_method(rb_cGrnDoubleArrayTrie, "open_prefix_cursor",
|
529
|
+
rb_grn_double_array_trie_open_prefix_cursor, -1);
|
530
|
+
}
|