groonga 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- metadata +38 -227
- data/AUTHORS +0 -5
- data/NEWS.ja.rdoc +0 -114
- data/NEWS.rdoc +0 -116
- data/README.ja.rdoc +0 -63
- data/README.rdoc +0 -64
- data/Rakefile +0 -216
- data/benchmark/common.rb +0 -49
- data/benchmark/read-write-many-small-items.rb +0 -144
- data/benchmark/write-many-small-items.rb +0 -135
- data/example/bookmark.rb +0 -161
- data/example/index-html.rb +0 -89
- data/example/search/config.ru +0 -211
- data/example/search/public/css/groonga.css +0 -122
- data/ext/.gitignore +0 -2
- data/ext/rb-grn-accessor.c +0 -52
- data/ext/rb-grn-array-cursor.c +0 -36
- data/ext/rb-grn-array.c +0 -210
- data/ext/rb-grn-column.c +0 -570
- data/ext/rb-grn-context.c +0 -655
- data/ext/rb-grn-database.c +0 -415
- data/ext/rb-grn-encoding-support.c +0 -64
- data/ext/rb-grn-encoding.c +0 -257
- data/ext/rb-grn-exception.c +0 -1110
- data/ext/rb-grn-expression-builder.c +0 -75
- data/ext/rb-grn-expression.c +0 -732
- data/ext/rb-grn-fix-size-column.c +0 -166
- data/ext/rb-grn-hash-cursor.c +0 -38
- data/ext/rb-grn-hash.c +0 -294
- data/ext/rb-grn-index-column.c +0 -488
- data/ext/rb-grn-logger.c +0 -325
- data/ext/rb-grn-object.c +0 -1335
- data/ext/rb-grn-operation.c +0 -198
- data/ext/rb-grn-patricia-trie-cursor.c +0 -39
- data/ext/rb-grn-patricia-trie.c +0 -488
- data/ext/rb-grn-procedure.c +0 -52
- data/ext/rb-grn-query.c +0 -260
- data/ext/rb-grn-record.c +0 -40
- data/ext/rb-grn-snippet.c +0 -328
- data/ext/rb-grn-table-cursor-key-support.c +0 -69
- data/ext/rb-grn-table-cursor.c +0 -246
- data/ext/rb-grn-table-key-support.c +0 -731
- data/ext/rb-grn-table.c +0 -2038
- data/ext/rb-grn-type.c +0 -181
- data/ext/rb-grn-utils.c +0 -769
- data/ext/rb-grn-variable-size-column.c +0 -36
- data/ext/rb-grn-variable.c +0 -108
- data/ext/rb-grn.h +0 -684
- data/ext/rb-groonga.c +0 -113
- data/extconf.rb +0 -216
- data/html/bar.svg +0 -153
- data/html/developer.html +0 -121
- data/html/developer.svg +0 -469
- data/html/download.svg +0 -253
- data/html/favicon.ico +0 -0
- data/html/favicon.xcf +0 -0
- data/html/footer.html.erb +0 -28
- data/html/head.html.erb +0 -4
- data/html/header.html.erb +0 -17
- data/html/index.html +0 -147
- data/html/install.svg +0 -636
- data/html/logo.xcf +0 -0
- data/html/ranguba.css +0 -248
- data/html/tutorial.svg +0 -559
- data/lib/groonga.rb +0 -83
- data/lib/groonga/expression-builder.rb +0 -285
- data/lib/groonga/patricia-trie.rb +0 -53
- data/lib/groonga/record.rb +0 -276
- data/lib/groonga/schema.rb +0 -916
- data/license/GPL +0 -340
- data/license/LGPL +0 -504
- data/license/RUBY +0 -59
- data/misc/grnop2ruby.rb +0 -49
- data/pkg-config.rb +0 -333
- data/src/rb-grn-table-cursor.c +0 -296
- data/test-unit/Rakefile +0 -40
- data/test-unit/TODO +0 -5
- data/test-unit/bin/testrb +0 -5
- data/test-unit/html/classic.html +0 -15
- data/test-unit/html/index.html +0 -25
- data/test-unit/html/index.html.ja +0 -27
- data/test-unit/lib/test/unit.rb +0 -323
- data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
- data/test-unit/lib/test/unit/assertions.rb +0 -1230
- data/test-unit/lib/test/unit/attribute.rb +0 -125
- data/test-unit/lib/test/unit/autorunner.rb +0 -353
- data/test-unit/lib/test/unit/collector.rb +0 -36
- data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
- data/test-unit/lib/test/unit/collector/dir.rb +0 -108
- data/test-unit/lib/test/unit/collector/load.rb +0 -136
- data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
- data/test-unit/lib/test/unit/color-scheme.rb +0 -102
- data/test-unit/lib/test/unit/color.rb +0 -96
- data/test-unit/lib/test/unit/diff.rb +0 -724
- data/test-unit/lib/test/unit/error.rb +0 -130
- data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
- data/test-unit/lib/test/unit/failure.rb +0 -136
- data/test-unit/lib/test/unit/fixture.rb +0 -176
- data/test-unit/lib/test/unit/notification.rb +0 -129
- data/test-unit/lib/test/unit/omission.rb +0 -191
- data/test-unit/lib/test/unit/pending.rb +0 -150
- data/test-unit/lib/test/unit/priority.rb +0 -181
- data/test-unit/lib/test/unit/runner/console.rb +0 -52
- data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
- data/test-unit/lib/test/unit/runner/tap.rb +0 -8
- data/test-unit/lib/test/unit/testcase.rb +0 -476
- data/test-unit/lib/test/unit/testresult.rb +0 -89
- data/test-unit/lib/test/unit/testsuite.rb +0 -110
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -464
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
- data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -92
- data/test-unit/lib/test/unit/ui/testrunner.rb +0 -28
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
- data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
- data/test-unit/lib/test/unit/util/observable.rb +0 -90
- data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
- data/test-unit/lib/test/unit/version.rb +0 -7
- data/test-unit/sample/adder.rb +0 -13
- data/test-unit/sample/subtracter.rb +0 -12
- data/test-unit/sample/test_adder.rb +0 -20
- data/test-unit/sample/test_subtracter.rb +0 -20
- data/test-unit/sample/test_user.rb +0 -23
- data/test-unit/test/collector/test-descendant.rb +0 -133
- data/test-unit/test/collector/test-load.rb +0 -329
- data/test-unit/test/collector/test_dir.rb +0 -406
- data/test-unit/test/collector/test_objectspace.rb +0 -100
- data/test-unit/test/run-test.rb +0 -15
- data/test-unit/test/test-attribute.rb +0 -86
- data/test-unit/test/test-color-scheme.rb +0 -67
- data/test-unit/test/test-color.rb +0 -47
- data/test-unit/test/test-diff.rb +0 -518
- data/test-unit/test/test-emacs-runner.rb +0 -60
- data/test-unit/test/test-fixture.rb +0 -287
- data/test-unit/test/test-notification.rb +0 -33
- data/test-unit/test/test-omission.rb +0 -81
- data/test-unit/test/test-pending.rb +0 -70
- data/test-unit/test/test-priority.rb +0 -119
- data/test-unit/test/test-testcase.rb +0 -554
- data/test-unit/test/test_assertions.rb +0 -1151
- data/test-unit/test/test_error.rb +0 -26
- data/test-unit/test/test_failure.rb +0 -33
- data/test-unit/test/test_testresult.rb +0 -113
- data/test-unit/test/test_testsuite.rb +0 -129
- data/test-unit/test/testunit-test-util.rb +0 -14
- data/test-unit/test/ui/test_testrunmediator.rb +0 -20
- data/test-unit/test/util/test-method-owner-finder.rb +0 -38
- data/test-unit/test/util/test_backtracefilter.rb +0 -41
- data/test-unit/test/util/test_observable.rb +0 -102
- data/test-unit/test/util/test_procwrapper.rb +0 -36
- data/test/.gitignore +0 -1
- data/test/groonga-test-utils.rb +0 -106
- data/test/run-test.rb +0 -58
- data/test/test-array.rb +0 -97
- data/test/test-column.rb +0 -298
- data/test/test-context.rb +0 -73
- data/test/test-database.rb +0 -113
- data/test/test-encoding.rb +0 -33
- data/test/test-exception.rb +0 -93
- data/test/test-expression-builder.rb +0 -156
- data/test/test-expression.rb +0 -133
- data/test/test-fix-size-column.rb +0 -65
- data/test/test-gqtp.rb +0 -70
- data/test/test-hash.rb +0 -312
- data/test/test-index-column.rb +0 -81
- data/test/test-patricia-trie.rb +0 -189
- data/test/test-procedure.rb +0 -37
- data/test/test-query.rb +0 -22
- data/test/test-record.rb +0 -268
- data/test/test-remote.rb +0 -53
- data/test/test-schema.rb +0 -416
- data/test/test-snippet.rb +0 -121
- data/test/test-table-cursor.rb +0 -153
- data/test/test-table-offset-and-limit.rb +0 -102
- data/test/test-table-select-normalize.rb +0 -48
- data/test/test-table-select.rb +0 -145
- data/test/test-table.rb +0 -642
- data/test/test-type.rb +0 -61
- data/test/test-variable-size-column.rb +0 -98
- data/test/test-variable.rb +0 -28
- data/test/test-vector-column.rb +0 -76
- data/test/test-version.rb +0 -31
- data/text/TUTORIAL.ja.rdoc +0 -392
- data/text/expression.rdoc +0 -284
@@ -1,69 +0,0 @@
|
|
1
|
-
/* -*- c-file-style: "ruby" -*- */
|
2
|
-
/*
|
3
|
-
Copyright (C) 2009 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
|
-
#define SELF(object) ((RbGrnTableCursor *)DATA_PTR(object))
|
22
|
-
|
23
|
-
VALUE rb_mGrnTableCursorKeySupport;
|
24
|
-
|
25
|
-
/*
|
26
|
-
* Document-module: Groonga::TableCursor::KeySupport
|
27
|
-
*
|
28
|
-
* 主キーを持つテーブル用のカーソルであるGroonga::HashCursor
|
29
|
-
* とGroonga::PatriciaTrieCursorに主キーの機能を提供するモジ
|
30
|
-
* ュール。
|
31
|
-
*/
|
32
|
-
|
33
|
-
/*
|
34
|
-
* call-seq:
|
35
|
-
* cursor.key -> 主キー
|
36
|
-
*
|
37
|
-
* カレントレコードの主キーを返す。
|
38
|
-
*/
|
39
|
-
static VALUE
|
40
|
-
rb_grn_table_cursor_get_key (VALUE self)
|
41
|
-
{
|
42
|
-
VALUE rb_key = Qnil;
|
43
|
-
grn_ctx *context;
|
44
|
-
grn_table_cursor *cursor;
|
45
|
-
|
46
|
-
rb_grn_table_cursor_deconstruct(SELF(self), &cursor, &context,
|
47
|
-
NULL, NULL, NULL, NULL);
|
48
|
-
if (context && cursor) {
|
49
|
-
void *key;
|
50
|
-
int key_size;
|
51
|
-
grn_obj *table;
|
52
|
-
|
53
|
-
table = grn_table_cursor_table(context, cursor);
|
54
|
-
key_size = grn_table_cursor_get_key(context, cursor, &key);
|
55
|
-
rb_key = GRNKEY2RVAL(context, key, key_size, table, self);
|
56
|
-
}
|
57
|
-
|
58
|
-
return rb_key;
|
59
|
-
}
|
60
|
-
|
61
|
-
void
|
62
|
-
rb_grn_init_table_cursor_key_support (VALUE mGrn)
|
63
|
-
{
|
64
|
-
rb_mGrnTableCursorKeySupport =
|
65
|
-
rb_define_module_under(rb_cGrnTableCursor, "KeySupport");
|
66
|
-
|
67
|
-
rb_define_method(rb_mGrnTableCursorKeySupport, "key",
|
68
|
-
rb_grn_table_cursor_get_key, 0);
|
69
|
-
}
|
data/ext/rb-grn-table-cursor.c
DELETED
@@ -1,246 +0,0 @@
|
|
1
|
-
/* -*- c-file-style: "ruby" -*- */
|
2
|
-
/*
|
3
|
-
Copyright (C) 2009 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
|
-
#define SELF(object) ((RbGrnTableCursor *)DATA_PTR(object))
|
22
|
-
|
23
|
-
VALUE rb_cGrnTableCursor;
|
24
|
-
|
25
|
-
/*
|
26
|
-
* Document-class: Groonga::TableCursor
|
27
|
-
*
|
28
|
-
* テーブルに登録されているレコードを順番に取り出すための
|
29
|
-
* オブジェクト。Groonga::Table#open_cursorで生成できる。
|
30
|
-
*/
|
31
|
-
|
32
|
-
grn_table_cursor *
|
33
|
-
rb_grn_table_cursor_from_ruby_object (VALUE object, grn_ctx **context)
|
34
|
-
{
|
35
|
-
if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnTableCursor))) {
|
36
|
-
rb_raise(rb_eTypeError, "not a groonga table cursor");
|
37
|
-
}
|
38
|
-
|
39
|
-
return RVAL2GRNOBJECT(object, context);
|
40
|
-
}
|
41
|
-
|
42
|
-
VALUE
|
43
|
-
rb_grn_table_cursor_to_ruby_object (VALUE klass, grn_ctx *context,
|
44
|
-
grn_table_cursor *cursor,
|
45
|
-
rb_grn_boolean owner)
|
46
|
-
{
|
47
|
-
return GRNOBJECT2RVAL(klass, context, cursor, owner);
|
48
|
-
}
|
49
|
-
|
50
|
-
void
|
51
|
-
rb_grn_table_cursor_deconstruct (RbGrnTableCursor *rb_grn_table_cursor,
|
52
|
-
grn_table_cursor **cursor,
|
53
|
-
grn_ctx **context,
|
54
|
-
grn_id *domain_id,
|
55
|
-
grn_obj **domain,
|
56
|
-
grn_id *range_id,
|
57
|
-
grn_obj **range)
|
58
|
-
{
|
59
|
-
RbGrnObject *rb_grn_object;
|
60
|
-
|
61
|
-
rb_grn_object = RB_GRN_OBJECT(rb_grn_table_cursor);
|
62
|
-
rb_grn_object_deconstruct(rb_grn_object, cursor, context,
|
63
|
-
domain_id, domain,
|
64
|
-
range_id, range);
|
65
|
-
}
|
66
|
-
|
67
|
-
/*
|
68
|
-
* call-seq:
|
69
|
-
* cursor.value -> 値
|
70
|
-
*
|
71
|
-
* カレントレコードの値を返す。
|
72
|
-
*/
|
73
|
-
static VALUE
|
74
|
-
rb_grn_table_cursor_get_value (VALUE self)
|
75
|
-
{
|
76
|
-
grn_ctx *context;
|
77
|
-
grn_table_cursor *cursor;
|
78
|
-
VALUE rb_value = Qnil;
|
79
|
-
|
80
|
-
rb_grn_table_cursor_deconstruct(SELF(self), &cursor, &context,
|
81
|
-
NULL, NULL, NULL, NULL);
|
82
|
-
if (context && cursor) {
|
83
|
-
int n;
|
84
|
-
void *value;
|
85
|
-
|
86
|
-
n = grn_table_cursor_get_value(context, cursor, &value);
|
87
|
-
rb_value = rb_str_new(value, n);
|
88
|
-
}
|
89
|
-
|
90
|
-
return rb_value;
|
91
|
-
}
|
92
|
-
|
93
|
-
/*
|
94
|
-
* call-seq:
|
95
|
-
* cursor.value = 値
|
96
|
-
*
|
97
|
-
* カレントレコードの値を設定する。既存の値は上書きされる。
|
98
|
-
*/
|
99
|
-
static VALUE
|
100
|
-
rb_grn_table_cursor_set_value (VALUE self, VALUE value)
|
101
|
-
{
|
102
|
-
grn_ctx *context;
|
103
|
-
grn_table_cursor *cursor;
|
104
|
-
|
105
|
-
rb_grn_table_cursor_deconstruct(SELF(self), &cursor, &context,
|
106
|
-
NULL, NULL, NULL, NULL);
|
107
|
-
if (context && cursor) {
|
108
|
-
grn_rc rc;
|
109
|
-
|
110
|
-
rc = grn_table_cursor_set_value(context,
|
111
|
-
cursor,
|
112
|
-
StringValuePtr(value),
|
113
|
-
GRN_OBJ_SET);
|
114
|
-
rb_grn_rc_check(rc, self);
|
115
|
-
}
|
116
|
-
|
117
|
-
return Qnil;
|
118
|
-
}
|
119
|
-
|
120
|
-
/*
|
121
|
-
* call-seq:
|
122
|
-
* table_cursor.delete
|
123
|
-
*
|
124
|
-
* カレントレコードを削除する。
|
125
|
-
*/
|
126
|
-
static VALUE
|
127
|
-
rb_grn_table_cursor_delete (VALUE self)
|
128
|
-
{
|
129
|
-
grn_ctx *context;
|
130
|
-
grn_table_cursor *cursor;
|
131
|
-
|
132
|
-
rb_grn_table_cursor_deconstruct(SELF(self), &cursor, &context,
|
133
|
-
NULL, NULL, NULL, NULL);
|
134
|
-
if (context && cursor) {
|
135
|
-
grn_rc rc;
|
136
|
-
|
137
|
-
rc = grn_table_cursor_delete(context, cursor);
|
138
|
-
rb_grn_rc_check(rc, self);
|
139
|
-
}
|
140
|
-
|
141
|
-
return Qnil;
|
142
|
-
}
|
143
|
-
|
144
|
-
/*
|
145
|
-
* call-seq:
|
146
|
-
* table_cursor.next -> Groonga::Record
|
147
|
-
*
|
148
|
-
* カレントレコードを一件進めてそのレコードを返す。
|
149
|
-
*/
|
150
|
-
static VALUE
|
151
|
-
rb_grn_table_cursor_next (VALUE self)
|
152
|
-
{
|
153
|
-
VALUE rb_record = Qnil;
|
154
|
-
grn_ctx *context;
|
155
|
-
grn_table_cursor *cursor;
|
156
|
-
|
157
|
-
rb_grn_table_cursor_deconstruct(SELF(self), &cursor, &context,
|
158
|
-
NULL, NULL, NULL, NULL);
|
159
|
-
if (context && cursor) {
|
160
|
-
grn_id record_id;
|
161
|
-
|
162
|
-
record_id = grn_table_cursor_next(context, cursor);
|
163
|
-
if (record_id != GRN_ID_NIL) /* FIXME: use grn_table_cursor_table */
|
164
|
-
rb_record = rb_grn_record_new(rb_iv_get(self, "@table"),
|
165
|
-
record_id, Qnil);
|
166
|
-
}
|
167
|
-
|
168
|
-
return rb_record;
|
169
|
-
}
|
170
|
-
|
171
|
-
/*
|
172
|
-
* call-seq:
|
173
|
-
* table_cursor.each {|record| ...}
|
174
|
-
*
|
175
|
-
* カーソルの範囲内にあるレコードを順番にブロックに渡す。
|
176
|
-
*/
|
177
|
-
static VALUE
|
178
|
-
rb_grn_table_cursor_each (VALUE self)
|
179
|
-
{
|
180
|
-
grn_id record_id;
|
181
|
-
grn_ctx *context;
|
182
|
-
grn_table_cursor *cursor;
|
183
|
-
|
184
|
-
rb_grn_table_cursor_deconstruct(SELF(self), &cursor, &context,
|
185
|
-
NULL, NULL, NULL, NULL);
|
186
|
-
|
187
|
-
if (context && cursor) {
|
188
|
-
while ((record_id = grn_table_cursor_next(context, cursor))) {
|
189
|
-
rb_yield(rb_grn_record_new(rb_iv_get(self, "@table"),
|
190
|
-
record_id, Qnil));
|
191
|
-
}
|
192
|
-
}
|
193
|
-
|
194
|
-
return Qnil;
|
195
|
-
}
|
196
|
-
|
197
|
-
/*
|
198
|
-
* Document-method: close
|
199
|
-
*
|
200
|
-
* call-seq:
|
201
|
-
* cursor.close
|
202
|
-
*
|
203
|
-
* カーソルが使用しているリソースを開放する。これ以降カーソルを
|
204
|
-
* 使うことはできない。
|
205
|
-
*/
|
206
|
-
|
207
|
-
/*
|
208
|
-
* Document-method: closed?
|
209
|
-
*
|
210
|
-
* call-seq:
|
211
|
-
* cursor.closed? -> true/false
|
212
|
-
*
|
213
|
-
* カーソルが開放済みの場合は+true+を返し、そうでない場合は
|
214
|
-
* +false+を返す。
|
215
|
-
*/
|
216
|
-
|
217
|
-
void
|
218
|
-
rb_grn_init_table_cursor (VALUE mGrn)
|
219
|
-
{
|
220
|
-
rb_cGrnTableCursor = rb_define_class_under(mGrn, "TableCursor", rb_cObject);
|
221
|
-
rb_define_alloc_func(rb_cGrnTableCursor, rb_grn_object_alloc);
|
222
|
-
|
223
|
-
rb_include_module(rb_cGrnTableCursor, rb_mEnumerable);
|
224
|
-
|
225
|
-
rb_define_method(rb_cGrnTableCursor, "close",
|
226
|
-
rb_grn_object_close, 0);
|
227
|
-
rb_define_method(rb_cGrnTableCursor, "closed?",
|
228
|
-
rb_grn_object_closed_p, 0);
|
229
|
-
|
230
|
-
rb_define_method(rb_cGrnTableCursor, "value",
|
231
|
-
rb_grn_table_cursor_get_value, 0);
|
232
|
-
rb_define_method(rb_cGrnTableCursor, "value=",
|
233
|
-
rb_grn_table_cursor_set_value, 1);
|
234
|
-
rb_define_method(rb_cGrnTableCursor, "delete",
|
235
|
-
rb_grn_table_cursor_delete, 0);
|
236
|
-
rb_define_method(rb_cGrnTableCursor, "next",
|
237
|
-
rb_grn_table_cursor_next, 0);
|
238
|
-
|
239
|
-
rb_define_method(rb_cGrnTableCursor, "each",
|
240
|
-
rb_grn_table_cursor_each, 0);
|
241
|
-
|
242
|
-
rb_grn_init_table_cursor_key_support(mGrn);
|
243
|
-
rb_grn_init_array_cursor(mGrn);
|
244
|
-
rb_grn_init_hash_cursor(mGrn);
|
245
|
-
rb_grn_init_patricia_trie_cursor(mGrn);
|
246
|
-
}
|
@@ -1,731 +0,0 @@
|
|
1
|
-
/* -*- c-file-style: "ruby" -*- */
|
2
|
-
/*
|
3
|
-
Copyright (C) 2009-2010 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
|
-
#define SELF(object) ((RbGrnTableKeySupport *)DATA_PTR(object))
|
22
|
-
|
23
|
-
VALUE rb_mGrnTableKeySupport;
|
24
|
-
|
25
|
-
/*
|
26
|
-
* Document-module: Groonga::Table::KeySupport
|
27
|
-
*
|
28
|
-
* 主キーを持つテーブルであるGroonga::Hashと
|
29
|
-
* Groonga::PatriciaTrieに主キーの機能を提供するモジュール。
|
30
|
-
*/
|
31
|
-
|
32
|
-
void
|
33
|
-
rb_grn_table_key_support_deconstruct (RbGrnTableKeySupport *rb_grn_table_key_support,
|
34
|
-
grn_obj **table_key_support,
|
35
|
-
grn_ctx **context,
|
36
|
-
grn_obj **key,
|
37
|
-
grn_id *domain_id,
|
38
|
-
grn_obj **domain,
|
39
|
-
grn_obj **value,
|
40
|
-
grn_id *range_id,
|
41
|
-
grn_obj **range,
|
42
|
-
VALUE *columns)
|
43
|
-
{
|
44
|
-
RbGrnTable *rb_grn_table;
|
45
|
-
|
46
|
-
rb_grn_table = RB_GRN_TABLE(rb_grn_table_key_support);
|
47
|
-
|
48
|
-
rb_grn_table_deconstruct(rb_grn_table, table_key_support, context,
|
49
|
-
domain_id, domain,
|
50
|
-
value, range_id, range,
|
51
|
-
columns);
|
52
|
-
|
53
|
-
if (key)
|
54
|
-
*key = rb_grn_table_key_support->key;
|
55
|
-
}
|
56
|
-
|
57
|
-
void
|
58
|
-
rb_grn_table_key_support_finalizer (grn_ctx *context,
|
59
|
-
grn_obj *grn_object,
|
60
|
-
RbGrnTableKeySupport *rb_grn_table_key_support)
|
61
|
-
{
|
62
|
-
if (!context)
|
63
|
-
return;
|
64
|
-
|
65
|
-
if (rb_grn_table_key_support->key)
|
66
|
-
grn_obj_close(context, rb_grn_table_key_support->key);
|
67
|
-
rb_grn_table_key_support->key = NULL;
|
68
|
-
|
69
|
-
rb_grn_table_finalizer(context, grn_object,
|
70
|
-
RB_GRN_TABLE(rb_grn_table_key_support));
|
71
|
-
}
|
72
|
-
|
73
|
-
void
|
74
|
-
rb_grn_table_key_support_bind (RbGrnTableKeySupport *rb_grn_table_key_support,
|
75
|
-
grn_ctx *context,
|
76
|
-
grn_obj *table_key_support)
|
77
|
-
{
|
78
|
-
RbGrnObject *rb_grn_object;
|
79
|
-
RbGrnTable *rb_grn_table;
|
80
|
-
|
81
|
-
rb_grn_object = RB_GRN_OBJECT(rb_grn_table_key_support);
|
82
|
-
|
83
|
-
rb_grn_table = RB_GRN_TABLE(rb_grn_table_key_support);
|
84
|
-
rb_grn_table_bind(rb_grn_table, context, table_key_support);
|
85
|
-
|
86
|
-
rb_grn_table_key_support->key =
|
87
|
-
grn_obj_open(context, GRN_BULK, 0, rb_grn_object->domain_id);
|
88
|
-
}
|
89
|
-
|
90
|
-
static VALUE
|
91
|
-
rb_grn_table_key_support_initialize (int argc, VALUE *argv, VALUE self)
|
92
|
-
{
|
93
|
-
grn_ctx *context = NULL;
|
94
|
-
grn_obj *table;
|
95
|
-
VALUE rb_context;
|
96
|
-
|
97
|
-
table = rb_grn_table_open_raw(argc, argv, &context, &rb_context);
|
98
|
-
rb_grn_context_check(context, self);
|
99
|
-
rb_grn_object_assign(Qnil, self, rb_context, context, table);
|
100
|
-
|
101
|
-
return Qnil;
|
102
|
-
}
|
103
|
-
|
104
|
-
static grn_id
|
105
|
-
rb_grn_table_key_support_add_raw (VALUE self, VALUE rb_key)
|
106
|
-
{
|
107
|
-
grn_ctx *context;
|
108
|
-
grn_obj *table;
|
109
|
-
grn_id id, domain_id;
|
110
|
-
grn_obj *key, *domain;
|
111
|
-
|
112
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
113
|
-
&key, &domain_id, &domain,
|
114
|
-
NULL, NULL, NULL,
|
115
|
-
NULL);
|
116
|
-
|
117
|
-
GRN_BULK_REWIND(key);
|
118
|
-
RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self);
|
119
|
-
id = grn_table_add(context, table,
|
120
|
-
GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key), NULL);
|
121
|
-
rb_grn_context_check(context, self);
|
122
|
-
|
123
|
-
return id;
|
124
|
-
}
|
125
|
-
|
126
|
-
/*
|
127
|
-
* call-seq:
|
128
|
-
* table.add(key, values=nil) -> Groonga::Recordまたはnil
|
129
|
-
*
|
130
|
-
* 主キーが_key_のレコード追加し、追加したレコードを返す。レ
|
131
|
-
* コードの追加に失敗した場合は+nil+を返す。
|
132
|
-
*
|
133
|
-
* _values_にはレコードのカラムに設定する値を指定する。省略
|
134
|
-
* した場合または+nil+を指定した場合はカラムは設定しない。カ
|
135
|
-
* ラムの値は<tt>{:カラム名1 => 値1, :カラム名2 => 値2,
|
136
|
-
* ...}</tt>と指定する。
|
137
|
-
*/
|
138
|
-
static VALUE
|
139
|
-
rb_grn_table_key_support_add (int argc, VALUE *argv, VALUE self)
|
140
|
-
{
|
141
|
-
grn_id id;
|
142
|
-
VALUE key, values;
|
143
|
-
|
144
|
-
rb_scan_args(argc, argv, "11", &key, &values);
|
145
|
-
id = rb_grn_table_key_support_add_raw(self, key);
|
146
|
-
if (GRN_ID_NIL == id)
|
147
|
-
return Qnil;
|
148
|
-
else
|
149
|
-
return rb_grn_record_new(self, id, values);
|
150
|
-
}
|
151
|
-
|
152
|
-
grn_id
|
153
|
-
rb_grn_table_key_support_get (VALUE self, VALUE rb_key)
|
154
|
-
{
|
155
|
-
grn_ctx *context;
|
156
|
-
grn_obj *table, *key, *domain;
|
157
|
-
grn_id id, domain_id;
|
158
|
-
|
159
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
160
|
-
&key, &domain_id, &domain,
|
161
|
-
NULL, NULL, NULL,
|
162
|
-
NULL);
|
163
|
-
|
164
|
-
GRN_BULK_REWIND(key);
|
165
|
-
RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self);
|
166
|
-
id = grn_table_get(context, table,
|
167
|
-
GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key));
|
168
|
-
rb_grn_context_check(context, self);
|
169
|
-
|
170
|
-
return id;
|
171
|
-
}
|
172
|
-
|
173
|
-
/*
|
174
|
-
* call-seq:
|
175
|
-
* table.id -> テーブルID
|
176
|
-
* table.id(key) -> レコードID
|
177
|
-
*
|
178
|
-
* _key_を指定しない場合はテーブルのIDを返す。
|
179
|
-
*
|
180
|
-
* _key_を指定した場合はテーブルの_key_に対応するレコードの
|
181
|
-
* IDを返す。
|
182
|
-
*/
|
183
|
-
static VALUE
|
184
|
-
rb_grn_table_key_support_get_id (int argc, VALUE *argv, VALUE self)
|
185
|
-
{
|
186
|
-
VALUE rb_key;
|
187
|
-
|
188
|
-
rb_scan_args(argc, argv, "01", &rb_key);
|
189
|
-
if (NIL_P(rb_key)) {
|
190
|
-
return rb_grn_object_get_id(self);
|
191
|
-
} else {
|
192
|
-
grn_id id;
|
193
|
-
|
194
|
-
id = rb_grn_table_key_support_get(self, rb_key);
|
195
|
-
if (id == GRN_ID_NIL) {
|
196
|
-
return Qnil;
|
197
|
-
} else {
|
198
|
-
return UINT2NUM(id);
|
199
|
-
}
|
200
|
-
}
|
201
|
-
}
|
202
|
-
|
203
|
-
/*
|
204
|
-
* call-seq:
|
205
|
-
* table.key(id) -> 主キー
|
206
|
-
*
|
207
|
-
* テーブルの_id_に対応する主キーを返す。
|
208
|
-
*/
|
209
|
-
static VALUE
|
210
|
-
rb_grn_table_key_support_get_key (VALUE self, VALUE rb_id)
|
211
|
-
{
|
212
|
-
grn_ctx *context;
|
213
|
-
grn_obj *table, *key;
|
214
|
-
grn_id id;
|
215
|
-
int key_size;
|
216
|
-
VALUE rb_key;
|
217
|
-
|
218
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
219
|
-
&key, NULL, NULL,
|
220
|
-
NULL, NULL, NULL,
|
221
|
-
NULL);
|
222
|
-
|
223
|
-
id = NUM2UINT(rb_id);
|
224
|
-
GRN_BULK_REWIND(key);
|
225
|
-
key_size = grn_table_get_key(context, table, id,
|
226
|
-
GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key));
|
227
|
-
if (key_size == 0)
|
228
|
-
return Qnil;
|
229
|
-
|
230
|
-
if (GRN_BULK_VSIZE(key) < key_size) {
|
231
|
-
grn_bulk_reserve(context, key, key_size);
|
232
|
-
grn_table_get_key(context, table, id, GRN_BULK_HEAD(key), key_size);
|
233
|
-
}
|
234
|
-
|
235
|
-
rb_key = GRNKEY2RVAL(context, GRN_BULK_HEAD(key), key_size, table, self);
|
236
|
-
return rb_key;
|
237
|
-
}
|
238
|
-
|
239
|
-
/*
|
240
|
-
* call-seq:
|
241
|
-
* table.has_key?(key) -> true/false
|
242
|
-
*
|
243
|
-
* テーブルに主キーが_key_のレコードがあるならtrueを返す。
|
244
|
-
*/
|
245
|
-
static VALUE
|
246
|
-
rb_grn_table_key_support_has_key (VALUE self, VALUE rb_key)
|
247
|
-
{
|
248
|
-
grn_ctx *context;
|
249
|
-
grn_obj *table, *key, *domain;
|
250
|
-
grn_id id, domain_id;
|
251
|
-
|
252
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
253
|
-
&key, &domain_id, &domain,
|
254
|
-
NULL, NULL, NULL,
|
255
|
-
NULL);
|
256
|
-
|
257
|
-
GRN_BULK_REWIND(key);
|
258
|
-
RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self);
|
259
|
-
id = grn_table_get(context, table, GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key));
|
260
|
-
|
261
|
-
return id == GRN_ID_NIL ? Qfalse : Qtrue;
|
262
|
-
}
|
263
|
-
|
264
|
-
static VALUE
|
265
|
-
rb_grn_table_key_support_delete_by_key (VALUE self, VALUE rb_key)
|
266
|
-
{
|
267
|
-
grn_ctx *context;
|
268
|
-
grn_obj *table;
|
269
|
-
grn_id domain_id;
|
270
|
-
grn_obj *key, *domain;
|
271
|
-
grn_rc rc;
|
272
|
-
|
273
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
274
|
-
&key, &domain_id, &domain,
|
275
|
-
NULL, NULL, NULL,
|
276
|
-
NULL);
|
277
|
-
|
278
|
-
GRN_BULK_REWIND(key);
|
279
|
-
RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self);
|
280
|
-
rc = grn_table_delete(context, table,
|
281
|
-
GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key));
|
282
|
-
rb_grn_context_check(context, self);
|
283
|
-
rb_grn_rc_check(rc, self);
|
284
|
-
|
285
|
-
return Qnil;
|
286
|
-
}
|
287
|
-
|
288
|
-
/*
|
289
|
-
* call-seq:
|
290
|
-
* table.delete(id)
|
291
|
-
* table.delete(key)
|
292
|
-
*
|
293
|
-
* テーブルの_id_または_key_に対応するレコードを削除する。
|
294
|
-
*/
|
295
|
-
static VALUE
|
296
|
-
rb_grn_table_key_support_delete (VALUE self, VALUE rb_id_or_key)
|
297
|
-
{
|
298
|
-
if (FIXNUM_P(rb_id_or_key)) {
|
299
|
-
return rb_grn_table_delete(self, rb_id_or_key);
|
300
|
-
} else {
|
301
|
-
return rb_grn_table_key_support_delete_by_key(self, rb_id_or_key);
|
302
|
-
}
|
303
|
-
}
|
304
|
-
|
305
|
-
/*
|
306
|
-
* Document-method: []
|
307
|
-
*
|
308
|
-
* call-seq:
|
309
|
-
* table[key] -> Groonga::Record
|
310
|
-
*
|
311
|
-
* _table_の_key_に対応するGroonga::Recordを返す。
|
312
|
-
*
|
313
|
-
* 0.9.0から値ではなくGroonga::Recordを返すようになった。
|
314
|
-
*/
|
315
|
-
static VALUE
|
316
|
-
rb_grn_table_key_support_array_reference (VALUE self, VALUE rb_key)
|
317
|
-
{
|
318
|
-
grn_id id;
|
319
|
-
|
320
|
-
id = rb_grn_table_key_support_get(self, rb_key);
|
321
|
-
if (id == GRN_ID_NIL) {
|
322
|
-
return Qnil;
|
323
|
-
} else {
|
324
|
-
return rb_grn_record_new(self, id, Qnil);
|
325
|
-
}
|
326
|
-
}
|
327
|
-
|
328
|
-
typedef struct _SetValueData
|
329
|
-
{
|
330
|
-
VALUE self;
|
331
|
-
grn_id id;
|
332
|
-
grn_obj *table;
|
333
|
-
RbGrnObject rb_grn_object;
|
334
|
-
} SetValueData;
|
335
|
-
|
336
|
-
static VALUE
|
337
|
-
set_value (VALUE args, SetValueData *data)
|
338
|
-
{
|
339
|
-
VALUE rb_name, rb_value, rb_column;
|
340
|
-
RbGrnObject *rb_grn_object;
|
341
|
-
|
342
|
-
rb_name = rb_ary_entry(args, 0);
|
343
|
-
rb_value = rb_ary_entry(args, 1);
|
344
|
-
|
345
|
-
rb_column = rb_grn_table_get_column(data->self, rb_name);
|
346
|
-
if (NIL_P(rb_column)) {
|
347
|
-
rb_raise(rb_eGrnNoSuchColumn,
|
348
|
-
"no such column: <%s>: <%s>",
|
349
|
-
rb_grn_inspect(rb_name), rb_grn_inspect(data->self));
|
350
|
-
}
|
351
|
-
|
352
|
-
rb_grn_object = RB_GRN_OBJECT(DATA_PTR(rb_column));
|
353
|
-
return rb_grn_object_set_raw(rb_grn_object,
|
354
|
-
data->id, rb_value, GRN_OBJ_SET, data->self);
|
355
|
-
}
|
356
|
-
|
357
|
-
/*
|
358
|
-
* Document-method: []=
|
359
|
-
*
|
360
|
-
* call-seq:
|
361
|
-
* table[key] = {:column_name => value, ...}
|
362
|
-
*
|
363
|
-
* _table_の_key_に対応するカラム_column_name_の値を設定する。
|
364
|
-
* _key_に対応するレコードがない場合は新しく作成される。
|
365
|
-
*
|
366
|
-
* 0.9.0から値ではなくカラムの値を設定するようになった。
|
367
|
-
*/
|
368
|
-
static VALUE
|
369
|
-
rb_grn_table_key_support_array_set (VALUE self, VALUE rb_key, VALUE rb_values)
|
370
|
-
{
|
371
|
-
grn_id id;
|
372
|
-
SetValueData data;
|
373
|
-
grn_ctx *context;
|
374
|
-
grn_obj *table;
|
375
|
-
|
376
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
377
|
-
NULL, NULL, NULL,
|
378
|
-
NULL, NULL, NULL,
|
379
|
-
NULL);
|
380
|
-
|
381
|
-
id = rb_grn_table_key_support_add_raw(self, rb_key);
|
382
|
-
|
383
|
-
if (id == GRN_ID_NIL) {
|
384
|
-
rb_raise(rb_eGrnError,
|
385
|
-
"failed to add record: %s",
|
386
|
-
rb_grn_inspect(rb_ary_new3(3, self, rb_key, rb_values)));
|
387
|
-
}
|
388
|
-
|
389
|
-
data.self = self;
|
390
|
-
data.id = id;
|
391
|
-
data.table = table;
|
392
|
-
data.rb_grn_object.context = context;
|
393
|
-
rb_iterate(rb_each, rb_values, set_value, (VALUE)&data);
|
394
|
-
|
395
|
-
return Qnil;
|
396
|
-
}
|
397
|
-
|
398
|
-
/*
|
399
|
-
* call-seq:
|
400
|
-
* table.set_column_value(key, name, value)
|
401
|
-
* table.set_column_value(id, name, value, :id => true)
|
402
|
-
*
|
403
|
-
* _table_の_key_に対応するカラム_name_の値を設定する。
|
404
|
-
* _key_に対応するレコードがない場合は新しく作成される。
|
405
|
-
*/
|
406
|
-
static VALUE
|
407
|
-
rb_grn_table_key_support_set_column_value (int argc, VALUE *argv, VALUE self)
|
408
|
-
{
|
409
|
-
grn_id id;
|
410
|
-
VALUE rb_key, rb_id_or_key, rb_name, rb_value, rb_options;
|
411
|
-
|
412
|
-
rb_scan_args(argc, argv, "31",
|
413
|
-
&rb_id_or_key, &rb_name, &rb_value, &rb_options);
|
414
|
-
if (!NIL_P(rb_options)) {
|
415
|
-
VALUE rb_option_id;
|
416
|
-
rb_grn_scan_options(rb_options,
|
417
|
-
"id", &rb_option_id,
|
418
|
-
NULL);
|
419
|
-
if (RVAL2CBOOL(rb_option_id)) {
|
420
|
-
VALUE rb_id = rb_id_or_key;
|
421
|
-
return rb_grn_table_set_column_value(self, rb_id, rb_name, rb_value);
|
422
|
-
}
|
423
|
-
}
|
424
|
-
|
425
|
-
rb_key = rb_id_or_key;
|
426
|
-
id = rb_grn_table_key_support_add_raw(self, rb_key);
|
427
|
-
if (id == GRN_ID_NIL) {
|
428
|
-
rb_raise(rb_eGrnError,
|
429
|
-
"failed to add record: %s",
|
430
|
-
rb_grn_inspect(rb_ary_new3(4,
|
431
|
-
self, rb_key,
|
432
|
-
rb_name, rb_value)));
|
433
|
-
}
|
434
|
-
|
435
|
-
return rb_grn_table_set_column_value_raw(self, id, rb_name, rb_value);
|
436
|
-
}
|
437
|
-
|
438
|
-
/*
|
439
|
-
* call-seq:
|
440
|
-
* table.column_value(key, name)
|
441
|
-
* table.column_value(id, name, :id => true)
|
442
|
-
*
|
443
|
-
* _table_の_key_に対応するカラム_name_の値を設定する。
|
444
|
-
*
|
445
|
-
* TODO: _key_に対応するレコードがない場合は例外?
|
446
|
-
*/
|
447
|
-
static VALUE
|
448
|
-
rb_grn_table_key_support_get_column_value (int argc, VALUE *argv, VALUE self)
|
449
|
-
{
|
450
|
-
grn_id id;
|
451
|
-
VALUE rb_key, rb_id_or_key, rb_name, rb_options;
|
452
|
-
|
453
|
-
rb_scan_args(argc, argv, "21", &rb_id_or_key, &rb_name, &rb_options);
|
454
|
-
if (!NIL_P(rb_options)) {
|
455
|
-
VALUE rb_option_id;
|
456
|
-
rb_grn_scan_options(rb_options,
|
457
|
-
"id", &rb_option_id,
|
458
|
-
NULL);
|
459
|
-
if (RVAL2CBOOL(rb_option_id)) {
|
460
|
-
VALUE rb_id = rb_id_or_key;
|
461
|
-
return rb_grn_table_get_column_value(self, rb_id, rb_name);
|
462
|
-
}
|
463
|
-
}
|
464
|
-
|
465
|
-
rb_key = rb_id_or_key;
|
466
|
-
id = rb_grn_table_key_support_get(self, rb_key);
|
467
|
-
if (id == GRN_ID_NIL) {
|
468
|
-
return Qnil;
|
469
|
-
}
|
470
|
-
|
471
|
-
return rb_grn_table_get_column_value_raw(self, id, rb_name);
|
472
|
-
}
|
473
|
-
|
474
|
-
/*
|
475
|
-
* call-seq:
|
476
|
-
* table.find(key) -> Groonga::Record
|
477
|
-
*
|
478
|
-
* テーブルの_key_に対応するレコードを返す。
|
479
|
-
*
|
480
|
-
* 0.9.0から非推奨。代わりにtable[key]を使うこと。
|
481
|
-
*/
|
482
|
-
static VALUE
|
483
|
-
rb_grn_table_key_support_find (VALUE self, VALUE rb_key)
|
484
|
-
{
|
485
|
-
rb_warn("#find is deprecated. Use #[] instead: %s",
|
486
|
-
rb_grn_inspect(self));
|
487
|
-
|
488
|
-
return rb_grn_table_key_support_array_reference(self, rb_key);
|
489
|
-
}
|
490
|
-
|
491
|
-
static VALUE
|
492
|
-
rb_grn_table_key_support_get_value_by_key (VALUE self, VALUE rb_key)
|
493
|
-
{
|
494
|
-
grn_ctx *context;
|
495
|
-
grn_obj *table, *value, *range;
|
496
|
-
grn_id id;
|
497
|
-
|
498
|
-
id = rb_grn_table_key_support_get(self, rb_key);
|
499
|
-
|
500
|
-
if (id == GRN_ID_NIL)
|
501
|
-
return Qnil;
|
502
|
-
|
503
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
504
|
-
NULL, NULL, NULL,
|
505
|
-
&value, NULL, &range,
|
506
|
-
NULL);
|
507
|
-
GRN_BULK_REWIND(value);
|
508
|
-
grn_obj_get_value(context, table, id, value);
|
509
|
-
rb_grn_context_check(context, self);
|
510
|
-
|
511
|
-
return GRNBULK2RVAL(context, value, range, self);
|
512
|
-
}
|
513
|
-
|
514
|
-
/*
|
515
|
-
* call-seq:
|
516
|
-
* table.value(id, :id => true) -> 値
|
517
|
-
* table.value(key) -> 値
|
518
|
-
*
|
519
|
-
* _table_の_id_または_key_に対応する値を返す。
|
520
|
-
*/
|
521
|
-
static VALUE
|
522
|
-
rb_grn_table_key_support_get_value (int argc, VALUE *argv, VALUE self)
|
523
|
-
{
|
524
|
-
VALUE rb_id_or_key, rb_options;
|
525
|
-
rb_grn_boolean use_key;
|
526
|
-
|
527
|
-
rb_scan_args(argc, argv, "11", &rb_id_or_key, &rb_options);
|
528
|
-
|
529
|
-
if (NIL_P(rb_options)) {
|
530
|
-
use_key = RB_GRN_TRUE;
|
531
|
-
} else {
|
532
|
-
VALUE rb_option_id;
|
533
|
-
|
534
|
-
rb_grn_scan_options(rb_options,
|
535
|
-
"id", &rb_option_id,
|
536
|
-
NULL);
|
537
|
-
use_key = !RVAL2CBOOL(rb_option_id);
|
538
|
-
}
|
539
|
-
|
540
|
-
if (use_key) {
|
541
|
-
return rb_grn_table_key_support_get_value_by_key(self, rb_id_or_key);
|
542
|
-
} else {
|
543
|
-
return rb_grn_table_get_value(self, rb_id_or_key);
|
544
|
-
}
|
545
|
-
}
|
546
|
-
|
547
|
-
static VALUE
|
548
|
-
rb_grn_table_key_support_set_value_by_key (VALUE self,
|
549
|
-
VALUE rb_key, VALUE rb_value)
|
550
|
-
{
|
551
|
-
grn_ctx *context;
|
552
|
-
grn_obj *table;
|
553
|
-
grn_id id;
|
554
|
-
grn_obj *value;
|
555
|
-
grn_rc rc;
|
556
|
-
|
557
|
-
if (NIL_P(rb_key)) {
|
558
|
-
rb_raise(rb_eArgError, "key should not be nil: <%s>",
|
559
|
-
rb_grn_inspect(self));
|
560
|
-
}
|
561
|
-
|
562
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
563
|
-
NULL, NULL, NULL,
|
564
|
-
&value, NULL, NULL,
|
565
|
-
NULL);
|
566
|
-
|
567
|
-
id = rb_grn_table_key_support_add_raw(self, rb_key);
|
568
|
-
if (GRN_ID_NIL == id) {
|
569
|
-
rb_raise(rb_eGrnError,
|
570
|
-
"failed to add new record with key: <%s>: <%s>",
|
571
|
-
rb_grn_inspect(rb_key),
|
572
|
-
rb_grn_inspect(self));
|
573
|
-
}
|
574
|
-
|
575
|
-
GRN_BULK_REWIND(value);
|
576
|
-
RVAL2GRNBULK(rb_value, context, value);
|
577
|
-
rc = grn_obj_set_value(context, table, id, value, GRN_OBJ_SET);
|
578
|
-
rb_grn_context_check(context, self);
|
579
|
-
rb_grn_rc_check(rc, self);
|
580
|
-
|
581
|
-
return rb_value;
|
582
|
-
}
|
583
|
-
|
584
|
-
/*
|
585
|
-
* call-seq:
|
586
|
-
* table.set_value(id, value, :id => true)
|
587
|
-
* table.set_value(key, value)
|
588
|
-
*
|
589
|
-
* _table_の_id_または_key_に対応する値を_value_に設定する。
|
590
|
-
* 既存の値は上書きされる。
|
591
|
-
*/
|
592
|
-
static VALUE
|
593
|
-
rb_grn_table_key_support_set_value (int argc, VALUE *argv, VALUE self)
|
594
|
-
{
|
595
|
-
VALUE rb_id_or_key, rb_value, rb_options;
|
596
|
-
rb_grn_boolean use_key;
|
597
|
-
|
598
|
-
rb_scan_args(argc, argv, "21", &rb_id_or_key, &rb_value, &rb_options);
|
599
|
-
|
600
|
-
if (NIL_P(rb_options)) {
|
601
|
-
use_key = RB_GRN_TRUE;
|
602
|
-
} else {
|
603
|
-
VALUE rb_option_id;
|
604
|
-
|
605
|
-
rb_grn_scan_options(rb_options,
|
606
|
-
"id", &rb_option_id,
|
607
|
-
NULL);
|
608
|
-
use_key = !RVAL2CBOOL(rb_option_id);
|
609
|
-
}
|
610
|
-
|
611
|
-
if (use_key) {
|
612
|
-
return rb_grn_table_key_support_set_value_by_key(self,
|
613
|
-
rb_id_or_key,
|
614
|
-
rb_value);
|
615
|
-
} else {
|
616
|
-
return rb_grn_table_set_value(self, rb_id_or_key, rb_value);
|
617
|
-
}
|
618
|
-
}
|
619
|
-
|
620
|
-
/*
|
621
|
-
* call-seq:
|
622
|
-
* table.default_tokenizer -> nilまたはGroonga::Procedure
|
623
|
-
*
|
624
|
-
* Groonga::IndexColumnで使用するトークナイザを返す。
|
625
|
-
*/
|
626
|
-
static VALUE
|
627
|
-
rb_grn_table_key_support_get_default_tokenizer (VALUE self)
|
628
|
-
{
|
629
|
-
grn_ctx *context = NULL;
|
630
|
-
grn_obj *table;
|
631
|
-
grn_obj *tokenizer = NULL;
|
632
|
-
|
633
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
634
|
-
NULL, NULL, NULL,
|
635
|
-
NULL, NULL, NULL,
|
636
|
-
NULL);
|
637
|
-
|
638
|
-
tokenizer = grn_obj_get_info(context, table, GRN_INFO_DEFAULT_TOKENIZER,
|
639
|
-
NULL);
|
640
|
-
rb_grn_context_check(context, self);
|
641
|
-
|
642
|
-
return GRNOBJECT2RVAL(Qnil, context, tokenizer, RB_GRN_FALSE);
|
643
|
-
}
|
644
|
-
|
645
|
-
/*
|
646
|
-
* call-seq:
|
647
|
-
* table.default_tokenizer = トークナイザ
|
648
|
-
*
|
649
|
-
* Groonga::IndexColumnで使用するトークナイザを設定する。
|
650
|
-
*
|
651
|
-
* 例:
|
652
|
-
* # 2-gramを使用。
|
653
|
-
* table.default_tokenizer = "TokenBigram"
|
654
|
-
* # オブジェクトで指定
|
655
|
-
* table.default_tokenizer = Groonga::Context.default["TokenBigram"]
|
656
|
-
* # オブジェクトIDで指定
|
657
|
-
* table.default_tokenizer = Groonga::Type::BIGRAM
|
658
|
-
* # N-gram用のトークナイザを使うときはGroonga::IndexColumn
|
659
|
-
* # には自動的に:with_section => trueが指定される。
|
660
|
-
* index = table.define_index_column("blog_content", "Blogs",
|
661
|
-
* :source => "content")
|
662
|
-
* p index # -> #<Groonga::IndexColumn ... flags: <WITH_POSITION|...>>
|
663
|
-
*
|
664
|
-
* # MeCabを使用
|
665
|
-
* table.default_tokenizer = "TokenMecab"
|
666
|
-
*/
|
667
|
-
static VALUE
|
668
|
-
rb_grn_table_key_support_set_default_tokenizer (VALUE self, VALUE rb_tokenizer)
|
669
|
-
{
|
670
|
-
grn_ctx *context;
|
671
|
-
grn_obj *table;
|
672
|
-
grn_obj *tokenizer;
|
673
|
-
grn_rc rc;
|
674
|
-
|
675
|
-
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
676
|
-
NULL, NULL, NULL,
|
677
|
-
NULL, NULL, NULL,
|
678
|
-
NULL);
|
679
|
-
|
680
|
-
tokenizer = RVAL2GRNOBJECT(rb_tokenizer, &context);
|
681
|
-
rc = grn_obj_set_info(context, table,
|
682
|
-
GRN_INFO_DEFAULT_TOKENIZER, tokenizer);
|
683
|
-
rb_grn_context_check(context, self);
|
684
|
-
rb_grn_rc_check(rc, self);
|
685
|
-
|
686
|
-
return Qnil;
|
687
|
-
}
|
688
|
-
|
689
|
-
void
|
690
|
-
rb_grn_init_table_key_support (VALUE mGrn)
|
691
|
-
{
|
692
|
-
rb_mGrnTableKeySupport = rb_define_module_under(rb_cGrnTable, "KeySupport");
|
693
|
-
rb_include_module(rb_mGrnTableKeySupport, rb_mGrnEncodingSupport);
|
694
|
-
|
695
|
-
rb_define_method(rb_mGrnTableKeySupport, "initialize",
|
696
|
-
rb_grn_table_key_support_initialize, -1);
|
697
|
-
|
698
|
-
rb_define_method(rb_mGrnTableKeySupport, "add",
|
699
|
-
rb_grn_table_key_support_add, -1);
|
700
|
-
rb_define_method(rb_mGrnTableKeySupport, "id",
|
701
|
-
rb_grn_table_key_support_get_id, -1);
|
702
|
-
rb_define_method(rb_mGrnTableKeySupport, "key",
|
703
|
-
rb_grn_table_key_support_get_key, 1);
|
704
|
-
rb_define_method(rb_mGrnTableKeySupport, "has_key?",
|
705
|
-
rb_grn_table_key_support_has_key, 1);
|
706
|
-
|
707
|
-
rb_define_method(rb_mGrnTableKeySupport, "delete",
|
708
|
-
rb_grn_table_key_support_delete, 1);
|
709
|
-
|
710
|
-
rb_define_method(rb_mGrnTableKeySupport, "find",
|
711
|
-
rb_grn_table_key_support_find, 1);
|
712
|
-
rb_define_method(rb_mGrnTableKeySupport, "[]",
|
713
|
-
rb_grn_table_key_support_array_reference, 1);
|
714
|
-
rb_define_method(rb_mGrnTableKeySupport, "[]=",
|
715
|
-
rb_grn_table_key_support_array_set, 2);
|
716
|
-
|
717
|
-
rb_define_method(rb_mGrnTableKeySupport, "column_value",
|
718
|
-
rb_grn_table_key_support_get_column_value, -1);
|
719
|
-
rb_define_method(rb_mGrnTableKeySupport, "set_column_value",
|
720
|
-
rb_grn_table_key_support_set_column_value, -1);
|
721
|
-
|
722
|
-
rb_define_method(rb_mGrnTableKeySupport, "value",
|
723
|
-
rb_grn_table_key_support_get_value, -1);
|
724
|
-
rb_define_method(rb_mGrnTableKeySupport, "set_value",
|
725
|
-
rb_grn_table_key_support_set_value, -1);
|
726
|
-
|
727
|
-
rb_define_method(rb_mGrnTableKeySupport, "default_tokenizer",
|
728
|
-
rb_grn_table_key_support_get_default_tokenizer, 0);
|
729
|
-
rb_define_method(rb_mGrnTableKeySupport, "default_tokenizer=",
|
730
|
-
rb_grn_table_key_support_set_default_tokenizer, 1);
|
731
|
-
}
|