groonga 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/NEWS.ja.rdoc +5 -0
- data/NEWS.rdoc +5 -0
- data/README.ja.rdoc +53 -0
- data/README.rdoc +54 -0
- data/Rakefile +209 -0
- data/TUTORIAL.ja.rdoc +160 -0
- data/benchmark/small-many-items.rb +175 -0
- data/example/bookmark.rb +38 -0
- data/ext/.gitignore +2 -0
- data/ext/rb-grn-accessor.c +52 -0
- data/ext/rb-grn-array-cursor.c +28 -0
- data/ext/rb-grn-array.c +168 -0
- data/ext/rb-grn-column.c +273 -0
- data/ext/rb-grn-context.c +333 -0
- data/ext/rb-grn-database.c +128 -0
- data/ext/rb-grn-encoding.c +163 -0
- data/ext/rb-grn-exception.c +1014 -0
- data/ext/rb-grn-hash-cursor.c +30 -0
- data/ext/rb-grn-hash.c +40 -0
- data/ext/rb-grn-logger.c +277 -0
- data/ext/rb-grn-object.c +985 -0
- data/ext/rb-grn-patricia-trie-cursor.c +30 -0
- data/ext/rb-grn-patricia-trie.c +40 -0
- data/ext/rb-grn-procedure.c +52 -0
- data/ext/rb-grn-query.c +207 -0
- data/ext/rb-grn-record.c +33 -0
- data/ext/rb-grn-snippet.c +274 -0
- data/ext/rb-grn-table-cursor-key-support.c +55 -0
- data/ext/rb-grn-table-cursor.c +294 -0
- data/ext/rb-grn-table-key-support.c +299 -0
- data/ext/rb-grn-table.c +706 -0
- data/ext/rb-grn-type.c +114 -0
- data/ext/rb-grn-utils.c +578 -0
- data/ext/rb-grn.h +346 -0
- data/ext/rb-groonga.c +98 -0
- data/extconf.rb +171 -0
- data/html/bar.svg +153 -0
- data/html/developer.html +121 -0
- data/html/developer.svg +469 -0
- data/html/download.svg +253 -0
- data/html/footer.html.erb +28 -0
- data/html/head.html.erb +4 -0
- data/html/header.html.erb +17 -0
- data/html/index.html +153 -0
- data/html/install.svg +636 -0
- data/html/logo.xcf +0 -0
- data/html/ranguba.css +248 -0
- data/html/tutorial.svg +559 -0
- data/lib/groonga.rb +50 -0
- data/lib/groonga/record.rb +98 -0
- data/license/GPL +340 -0
- data/license/LGPL +504 -0
- data/license/RUBY +59 -0
- data/pkg-config.rb +328 -0
- data/test-unit/Rakefile +35 -0
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/html/classic.html +15 -0
- data/test-unit/html/index.html +25 -0
- data/test-unit/html/index.html.ja +27 -0
- data/test-unit/lib/test/unit.rb +342 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +1149 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +306 -0
- data/test-unit/lib/test/unit/collector.rb +43 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +86 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +538 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +125 -0
- data/test-unit/lib/test/unit/omission.rb +143 -0
- data/test-unit/lib/test/unit/pending.rb +146 -0
- data/test-unit/lib/test/unit/priority.rb +161 -0
- data/test-unit/lib/test/unit/runner/console.rb +52 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +360 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +220 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/test_user.rb +22 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test-descendant.rb +135 -0
- data/test-unit/test/collector/test-load.rb +333 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +56 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +477 -0
- data/test-unit/test/test-emacs-runner.rb +60 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/test-notification.rb +33 -0
- data/test-unit/test/test-omission.rb +81 -0
- data/test-unit/test/test-pending.rb +70 -0
- data/test-unit/test/test-priority.rb +119 -0
- data/test-unit/test/test_assertions.rb +1082 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_testcase.rb +478 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit-test-util.rb +14 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/.gitignore +1 -0
- data/test/groonga-test-utils.rb +90 -0
- data/test/run-test.rb +54 -0
- data/test/test-column.rb +190 -0
- data/test/test-context.rb +90 -0
- data/test/test-database.rb +62 -0
- data/test/test-encoding.rb +33 -0
- data/test/test-exception.rb +85 -0
- data/test/test-procedure.rb +35 -0
- data/test/test-query.rb +22 -0
- data/test/test-record.rb +188 -0
- data/test/test-snippet.rb +121 -0
- data/test/test-table-cursor.rb +51 -0
- data/test/test-table.rb +447 -0
- data/test/test-type.rb +52 -0
- data/test/test-version.rb +31 -0
- metadata +213 -0
@@ -0,0 +1,55 @@
|
|
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) (RVAL2GRNTABLECURSOR(object))
|
22
|
+
|
23
|
+
VALUE rb_mGrnTableCursorKeySupport;
|
24
|
+
|
25
|
+
static VALUE
|
26
|
+
rb_grn_table_cursor_get_key (VALUE self)
|
27
|
+
{
|
28
|
+
VALUE rb_key = Qnil;
|
29
|
+
grn_ctx *context;
|
30
|
+
grn_table_cursor *cursor;
|
31
|
+
|
32
|
+
context = rb_grn_table_cursor_ensure_context(self, Qnil);
|
33
|
+
cursor = SELF(self);
|
34
|
+
if (context && cursor) {
|
35
|
+
void *key;
|
36
|
+
int key_size;
|
37
|
+
grn_obj *table;
|
38
|
+
|
39
|
+
table = grn_table_cursor_table(context, cursor);
|
40
|
+
key_size = grn_table_cursor_get_key(context, cursor, &key);
|
41
|
+
rb_key = GRNKEY2RVAL(context, key, key_size, table, self);
|
42
|
+
}
|
43
|
+
|
44
|
+
return rb_key;
|
45
|
+
}
|
46
|
+
|
47
|
+
void
|
48
|
+
rb_grn_init_table_cursor_key_support (VALUE mGrn)
|
49
|
+
{
|
50
|
+
rb_mGrnTableCursorKeySupport =
|
51
|
+
rb_define_module_under(rb_cGrnTableCursor, "KeySupport");
|
52
|
+
|
53
|
+
rb_define_method(rb_cGrnTableCursor, "key",
|
54
|
+
rb_grn_table_cursor_get_key, 0);
|
55
|
+
}
|
@@ -0,0 +1,294 @@
|
|
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) (rb_rb_grn_table_cursor_from_ruby_object(object))
|
22
|
+
|
23
|
+
typedef struct _RbGrnTableCursor RbGrnTableCursor;
|
24
|
+
struct _RbGrnTableCursor
|
25
|
+
{
|
26
|
+
grn_ctx *context;
|
27
|
+
grn_table_cursor *cursor;
|
28
|
+
rb_grn_boolean owner;
|
29
|
+
};
|
30
|
+
|
31
|
+
VALUE rb_cGrnTableCursor;
|
32
|
+
|
33
|
+
static RbGrnTableCursor *
|
34
|
+
rb_rb_grn_table_cursor_from_ruby_object (VALUE object)
|
35
|
+
{
|
36
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
37
|
+
|
38
|
+
if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnTableCursor))) {
|
39
|
+
rb_raise(rb_eTypeError, "not a groonga table cursor");
|
40
|
+
}
|
41
|
+
|
42
|
+
Data_Get_Struct(object, RbGrnTableCursor, rb_grn_table_cursor);
|
43
|
+
if (!rb_grn_table_cursor)
|
44
|
+
rb_raise(rb_eGrnError, "groonga table cursor is NULL");
|
45
|
+
|
46
|
+
return rb_grn_table_cursor;
|
47
|
+
}
|
48
|
+
|
49
|
+
grn_table_cursor *
|
50
|
+
rb_grn_table_cursor_from_ruby_object (VALUE object)
|
51
|
+
{
|
52
|
+
if (NIL_P(object))
|
53
|
+
return NULL;
|
54
|
+
|
55
|
+
return SELF(object)->cursor;
|
56
|
+
}
|
57
|
+
|
58
|
+
static void
|
59
|
+
rb_rb_grn_table_cursor_free (void *object)
|
60
|
+
{
|
61
|
+
RbGrnTableCursor *rb_grn_table_cursor = object;
|
62
|
+
|
63
|
+
if (rb_grn_table_cursor->context && rb_grn_table_cursor->cursor &&
|
64
|
+
rb_grn_table_cursor->owner)
|
65
|
+
grn_table_cursor_close(rb_grn_table_cursor->context,
|
66
|
+
rb_grn_table_cursor->cursor);
|
67
|
+
xfree(object);
|
68
|
+
}
|
69
|
+
|
70
|
+
VALUE
|
71
|
+
rb_grn_table_cursor_to_ruby_class (grn_obj *object)
|
72
|
+
{
|
73
|
+
VALUE klass = Qnil;
|
74
|
+
|
75
|
+
switch (object->header.type) {
|
76
|
+
case GRN_CURSOR_TABLE_HASH_KEY:
|
77
|
+
klass = rb_cGrnHashCursor;
|
78
|
+
break;
|
79
|
+
case GRN_CURSOR_TABLE_PAT_KEY:
|
80
|
+
klass = rb_cGrnPatriciaTrieCursor;
|
81
|
+
break;
|
82
|
+
case GRN_CURSOR_TABLE_NO_KEY:
|
83
|
+
klass = rb_cGrnArrayCursor;
|
84
|
+
break;
|
85
|
+
default:
|
86
|
+
rb_raise(rb_eTypeError,
|
87
|
+
"unsupported groonga object type: %d",
|
88
|
+
object->header.type);
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
|
92
|
+
return klass;
|
93
|
+
}
|
94
|
+
|
95
|
+
VALUE
|
96
|
+
rb_grn_table_cursor_to_ruby_object (VALUE klass, grn_ctx *context,
|
97
|
+
grn_table_cursor *cursor)
|
98
|
+
{
|
99
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
100
|
+
|
101
|
+
if (!cursor)
|
102
|
+
return Qnil;
|
103
|
+
|
104
|
+
rb_grn_table_cursor = ALLOC(RbGrnTableCursor);
|
105
|
+
rb_grn_table_cursor->context = context;
|
106
|
+
rb_grn_table_cursor->cursor = cursor;
|
107
|
+
rb_grn_table_cursor->owner = RB_GRN_TRUE; /* FIXME */
|
108
|
+
|
109
|
+
if (NIL_P(klass))
|
110
|
+
klass = GRNTABLECURSOR2RCLASS(cursor);
|
111
|
+
|
112
|
+
return Data_Wrap_Struct(klass, NULL,
|
113
|
+
rb_rb_grn_table_cursor_free, rb_grn_table_cursor);
|
114
|
+
}
|
115
|
+
|
116
|
+
static VALUE
|
117
|
+
rb_grn_table_cursor_alloc (VALUE klass)
|
118
|
+
{
|
119
|
+
return Data_Wrap_Struct(klass, NULL, rb_rb_grn_table_cursor_free, NULL);
|
120
|
+
}
|
121
|
+
|
122
|
+
grn_ctx *
|
123
|
+
rb_grn_table_cursor_ensure_context (VALUE cursor, VALUE rb_context)
|
124
|
+
{
|
125
|
+
if (NIL_P(rb_context)) {
|
126
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
127
|
+
|
128
|
+
rb_grn_table_cursor = SELF(cursor);
|
129
|
+
if (rb_grn_table_cursor && rb_grn_table_cursor->context)
|
130
|
+
return rb_grn_table_cursor->context;
|
131
|
+
}
|
132
|
+
|
133
|
+
return rb_grn_context_ensure(rb_context);
|
134
|
+
}
|
135
|
+
|
136
|
+
VALUE
|
137
|
+
rb_grn_table_cursor_close (VALUE self)
|
138
|
+
{
|
139
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
140
|
+
|
141
|
+
rb_grn_table_cursor = SELF(self);
|
142
|
+
if (rb_grn_table_cursor->context && rb_grn_table_cursor->cursor) {
|
143
|
+
grn_rc rc = GRN_SUCCESS;
|
144
|
+
|
145
|
+
if (rb_grn_table_cursor->owner)
|
146
|
+
rc = grn_table_cursor_close(rb_grn_table_cursor->context,
|
147
|
+
rb_grn_table_cursor->cursor);
|
148
|
+
rb_grn_table_cursor->context = NULL;
|
149
|
+
rb_grn_table_cursor->cursor = NULL;
|
150
|
+
rb_grn_table_cursor->owner = RB_GRN_FALSE;
|
151
|
+
rb_grn_rc_check(rc, self);
|
152
|
+
}
|
153
|
+
return Qnil;
|
154
|
+
}
|
155
|
+
|
156
|
+
static VALUE
|
157
|
+
rb_grn_table_cursor_closed_p (VALUE self)
|
158
|
+
{
|
159
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
160
|
+
|
161
|
+
rb_grn_table_cursor = SELF(self);
|
162
|
+
if (rb_grn_table_cursor->context && rb_grn_table_cursor->cursor)
|
163
|
+
return Qfalse;
|
164
|
+
else
|
165
|
+
return Qtrue;
|
166
|
+
}
|
167
|
+
|
168
|
+
static VALUE
|
169
|
+
rb_grn_table_cursor_get_value (VALUE self)
|
170
|
+
{
|
171
|
+
VALUE rb_value = Qnil;
|
172
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
173
|
+
|
174
|
+
rb_grn_table_cursor = SELF(self);
|
175
|
+
if (rb_grn_table_cursor->context && rb_grn_table_cursor->cursor) {
|
176
|
+
int n;
|
177
|
+
void *value;
|
178
|
+
|
179
|
+
n = grn_table_cursor_get_value(rb_grn_table_cursor->context,
|
180
|
+
rb_grn_table_cursor->cursor,
|
181
|
+
&value);
|
182
|
+
rb_value = rb_str_new(value, n);
|
183
|
+
}
|
184
|
+
|
185
|
+
return rb_value;
|
186
|
+
}
|
187
|
+
|
188
|
+
static VALUE
|
189
|
+
rb_grn_table_cursor_set_value (VALUE self, VALUE value)
|
190
|
+
{
|
191
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
192
|
+
|
193
|
+
rb_grn_table_cursor = SELF(self);
|
194
|
+
if (rb_grn_table_cursor->context && rb_grn_table_cursor->cursor) {
|
195
|
+
grn_rc rc;
|
196
|
+
|
197
|
+
rc = grn_table_cursor_set_value(rb_grn_table_cursor->context,
|
198
|
+
rb_grn_table_cursor->cursor,
|
199
|
+
StringValuePtr(value), GRN_OBJ_SET);
|
200
|
+
rb_grn_rc_check(rc, self);
|
201
|
+
}
|
202
|
+
|
203
|
+
return Qnil;
|
204
|
+
}
|
205
|
+
|
206
|
+
static VALUE
|
207
|
+
rb_grn_table_cursor_delete (VALUE self)
|
208
|
+
{
|
209
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
210
|
+
|
211
|
+
rb_grn_table_cursor = SELF(self);
|
212
|
+
if (rb_grn_table_cursor->context && rb_grn_table_cursor->cursor) {
|
213
|
+
grn_rc rc;
|
214
|
+
|
215
|
+
rc = grn_table_cursor_delete(rb_grn_table_cursor->context,
|
216
|
+
rb_grn_table_cursor->cursor);
|
217
|
+
rb_grn_rc_check(rc, self);
|
218
|
+
}
|
219
|
+
|
220
|
+
return Qnil;
|
221
|
+
}
|
222
|
+
|
223
|
+
static VALUE
|
224
|
+
rb_grn_table_cursor_next (VALUE self)
|
225
|
+
{
|
226
|
+
VALUE rb_record = Qnil;
|
227
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
228
|
+
|
229
|
+
rb_grn_table_cursor = SELF(self);
|
230
|
+
if (rb_grn_table_cursor->context && rb_grn_table_cursor->cursor) {
|
231
|
+
grn_id record_id;
|
232
|
+
|
233
|
+
record_id = grn_table_cursor_next(rb_grn_table_cursor->context,
|
234
|
+
rb_grn_table_cursor->cursor);
|
235
|
+
if (record_id != GRN_ID_NIL) /* FIXME: use grn_table_cursor_table */
|
236
|
+
rb_record = rb_grn_record_new(rb_iv_get(self, "@table"), record_id);
|
237
|
+
}
|
238
|
+
|
239
|
+
return rb_record;
|
240
|
+
}
|
241
|
+
|
242
|
+
static VALUE
|
243
|
+
rb_grn_table_cursor_each (VALUE self)
|
244
|
+
{
|
245
|
+
grn_id record_id;
|
246
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
247
|
+
grn_ctx *context;
|
248
|
+
grn_table_cursor *cursor;
|
249
|
+
|
250
|
+
rb_grn_table_cursor = SELF(self);
|
251
|
+
if (!rb_grn_table_cursor->context)
|
252
|
+
return Qnil;
|
253
|
+
if (!rb_grn_table_cursor->cursor)
|
254
|
+
return Qnil;
|
255
|
+
|
256
|
+
context = rb_grn_table_cursor->context;
|
257
|
+
cursor = rb_grn_table_cursor->cursor;
|
258
|
+
while ((record_id = grn_table_cursor_next(context, cursor))) {
|
259
|
+
rb_yield(rb_grn_record_new(rb_iv_get(self, "@table"), record_id));
|
260
|
+
}
|
261
|
+
|
262
|
+
return Qnil;
|
263
|
+
}
|
264
|
+
|
265
|
+
void
|
266
|
+
rb_grn_init_table_cursor (VALUE mGrn)
|
267
|
+
{
|
268
|
+
rb_cGrnTableCursor = rb_define_class_under(mGrn, "TableCurosr", rb_cObject);
|
269
|
+
rb_define_alloc_func(rb_cGrnTableCursor, rb_grn_table_cursor_alloc);
|
270
|
+
|
271
|
+
rb_include_module(rb_cGrnTableCursor, rb_mEnumerable);
|
272
|
+
|
273
|
+
rb_define_method(rb_cGrnTableCursor, "close",
|
274
|
+
rb_grn_table_cursor_close, 0);
|
275
|
+
rb_define_method(rb_cGrnTableCursor, "closed?",
|
276
|
+
rb_grn_table_cursor_closed_p, 0);
|
277
|
+
|
278
|
+
rb_define_method(rb_cGrnTableCursor, "value",
|
279
|
+
rb_grn_table_cursor_get_value, 0);
|
280
|
+
rb_define_method(rb_cGrnTableCursor, "value=",
|
281
|
+
rb_grn_table_cursor_set_value, 1);
|
282
|
+
rb_define_method(rb_cGrnTableCursor, "delete",
|
283
|
+
rb_grn_table_cursor_delete, 0);
|
284
|
+
rb_define_method(rb_cGrnTableCursor, "next",
|
285
|
+
rb_grn_table_cursor_next, 0);
|
286
|
+
|
287
|
+
rb_define_method(rb_cGrnTableCursor, "each",
|
288
|
+
rb_grn_table_cursor_each, 0);
|
289
|
+
|
290
|
+
rb_grn_init_table_cursor_key_support(mGrn);
|
291
|
+
rb_grn_init_array_cursor(mGrn);
|
292
|
+
rb_grn_init_hash_cursor(mGrn);
|
293
|
+
rb_grn_init_patricia_trie_cursor(mGrn);
|
294
|
+
}
|
@@ -0,0 +1,299 @@
|
|
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, context) (RVAL2GRNTABLE(object, context))
|
22
|
+
|
23
|
+
VALUE rb_mGrnTableKeySupport;
|
24
|
+
|
25
|
+
/* FIXME */
|
26
|
+
grn_rc grn_table_get_info(grn_ctx *ctx, grn_obj *table, grn_obj_flags *flags,
|
27
|
+
grn_encoding *encoding, grn_obj **tokenizer);
|
28
|
+
|
29
|
+
static grn_id
|
30
|
+
rb_grn_table_key_support_add_raw (VALUE self, VALUE rb_key,
|
31
|
+
grn_ctx *context, grn_obj *table)
|
32
|
+
{
|
33
|
+
VALUE exception;
|
34
|
+
grn_id id;
|
35
|
+
grn_obj key;
|
36
|
+
grn_search_flags flags;
|
37
|
+
|
38
|
+
RVAL2GRNKEY(rb_key, context, &key, table->header.domain, self);
|
39
|
+
flags = GRN_SEARCH_EXACT | GRN_TABLE_ADD;
|
40
|
+
id = grn_table_lookup(context, table,
|
41
|
+
GRN_BULK_HEAD(&key), GRN_BULK_VSIZE(&key),
|
42
|
+
&flags);
|
43
|
+
exception = rb_grn_context_to_exception(context, self);
|
44
|
+
grn_obj_close(context, &key);
|
45
|
+
if (!NIL_P(exception))
|
46
|
+
rb_exc_raise(exception);
|
47
|
+
|
48
|
+
return id;
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE
|
52
|
+
rb_grn_table_key_support_add (VALUE self, VALUE rb_key)
|
53
|
+
{
|
54
|
+
grn_ctx *context = NULL;
|
55
|
+
grn_obj *table;
|
56
|
+
grn_id id;
|
57
|
+
|
58
|
+
table = SELF(self, &context);
|
59
|
+
|
60
|
+
id = rb_grn_table_key_support_add_raw(self, rb_key, context, table);
|
61
|
+
if (GRN_ID_NIL == id)
|
62
|
+
return Qnil;
|
63
|
+
else
|
64
|
+
return rb_grn_record_new(self, id);
|
65
|
+
}
|
66
|
+
|
67
|
+
static VALUE
|
68
|
+
rb_grn_table_key_support_get_key (VALUE self, VALUE rb_id)
|
69
|
+
{
|
70
|
+
grn_ctx *context = NULL;
|
71
|
+
grn_id id;
|
72
|
+
grn_obj *table, key;
|
73
|
+
int key_size = 0;
|
74
|
+
VALUE rb_key;
|
75
|
+
|
76
|
+
table = SELF(self, &context);
|
77
|
+
|
78
|
+
id = NUM2UINT(rb_id);
|
79
|
+
key_size = grn_table_get_key(context, table, id, NULL, 0);
|
80
|
+
if (key_size == 0)
|
81
|
+
return Qnil;
|
82
|
+
|
83
|
+
GRN_OBJ_INIT(&key, GRN_BULK, 0);
|
84
|
+
grn_bulk_space(context, &key, key_size);
|
85
|
+
grn_table_get_key(context, table, id, GRN_BULK_HEAD(&key), key_size);
|
86
|
+
rb_key = GRNKEY2RVAL(context, GRN_BULK_HEAD(&key), key_size, table, self);
|
87
|
+
grn_obj_close(context, &key);
|
88
|
+
|
89
|
+
return rb_key;
|
90
|
+
}
|
91
|
+
|
92
|
+
static VALUE
|
93
|
+
rb_grn_table_key_support_delete_by_key (VALUE self, VALUE rb_key)
|
94
|
+
{
|
95
|
+
VALUE exception;
|
96
|
+
grn_ctx *context = NULL;
|
97
|
+
grn_obj *table;
|
98
|
+
grn_obj key;
|
99
|
+
grn_rc rc;
|
100
|
+
|
101
|
+
table = SELF(self, &context);
|
102
|
+
|
103
|
+
RVAL2GRNKEY(rb_key, context, &key, table->header.domain, self);
|
104
|
+
rc = grn_table_delete(context, table,
|
105
|
+
GRN_BULK_HEAD(&key), GRN_BULK_VSIZE(&key));
|
106
|
+
exception = rb_grn_context_to_exception(context, self);
|
107
|
+
grn_obj_close(context, &key);
|
108
|
+
if (!NIL_P(exception))
|
109
|
+
rb_exc_raise(exception);
|
110
|
+
rb_grn_rc_check(rc, self);
|
111
|
+
|
112
|
+
return Qnil;
|
113
|
+
}
|
114
|
+
|
115
|
+
static VALUE
|
116
|
+
rb_grn_table_key_support_delete (VALUE self, VALUE rb_id_or_key)
|
117
|
+
{
|
118
|
+
if (FIXNUM_P(rb_id_or_key)) {
|
119
|
+
int argc = 1;
|
120
|
+
VALUE argv[1];
|
121
|
+
argv[0] = rb_id_or_key;
|
122
|
+
return rb_call_super(argc, argv);
|
123
|
+
} else {
|
124
|
+
return rb_grn_table_key_support_delete_by_key(self, rb_id_or_key);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
static VALUE
|
129
|
+
rb_grn_table_key_support_array_reference_by_key (VALUE self, VALUE rb_key)
|
130
|
+
{
|
131
|
+
VALUE exception;
|
132
|
+
grn_ctx *context = NULL;
|
133
|
+
grn_obj *table;
|
134
|
+
grn_obj key;
|
135
|
+
grn_id id;
|
136
|
+
grn_search_flags flags = 0;
|
137
|
+
|
138
|
+
table = SELF(self, &context);
|
139
|
+
|
140
|
+
RVAL2GRNKEY(rb_key, context, &key, table->header.domain, self);
|
141
|
+
flags = GRN_SEARCH_EXACT;
|
142
|
+
id = grn_table_lookup(context, table,
|
143
|
+
GRN_BULK_HEAD(&key), GRN_BULK_VSIZE(&key),
|
144
|
+
&flags);
|
145
|
+
exception = rb_grn_context_to_exception(context, self);
|
146
|
+
grn_obj_close(context, &key);
|
147
|
+
if (!NIL_P(exception))
|
148
|
+
rb_exc_raise(exception);
|
149
|
+
|
150
|
+
if (id == GRN_ID_NIL)
|
151
|
+
return Qnil;
|
152
|
+
else
|
153
|
+
return rb_grn_record_new(self, id);
|
154
|
+
}
|
155
|
+
|
156
|
+
static VALUE
|
157
|
+
rb_grn_table_key_support_array_reference (VALUE self, VALUE rb_id_or_key)
|
158
|
+
{
|
159
|
+
if (FIXNUM_P(rb_id_or_key)) {
|
160
|
+
int argc = 1;
|
161
|
+
VALUE argv[1];
|
162
|
+
argv[0] = rb_id_or_key;
|
163
|
+
return rb_call_super(argc, argv);
|
164
|
+
} else {
|
165
|
+
return rb_grn_table_key_support_array_reference_by_key(self,
|
166
|
+
rb_id_or_key);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
static VALUE
|
172
|
+
rb_grn_table_key_support_array_set_by_key (VALUE self,
|
173
|
+
VALUE rb_key, VALUE rb_value)
|
174
|
+
{
|
175
|
+
VALUE exception;
|
176
|
+
grn_ctx *context = NULL;
|
177
|
+
grn_obj *table;
|
178
|
+
grn_id id;
|
179
|
+
grn_obj value;
|
180
|
+
grn_rc rc;
|
181
|
+
|
182
|
+
table = SELF(self, &context);
|
183
|
+
|
184
|
+
if (NIL_P(rb_key))
|
185
|
+
rb_raise(rb_eArgError, "key should not be nil: <%s>",
|
186
|
+
rb_grn_inspect(self));
|
187
|
+
|
188
|
+
id = rb_grn_table_key_support_add_raw(self, rb_key, context, table);
|
189
|
+
if (GRN_ID_NIL == id)
|
190
|
+
rb_raise(rb_eGrnError,
|
191
|
+
"failed to add new record with key: <%s>: <%s>",
|
192
|
+
rb_grn_inspect(rb_key),
|
193
|
+
rb_grn_inspect(self));
|
194
|
+
|
195
|
+
RVAL2GRNBULK(rb_value, context, &value);
|
196
|
+
rc = grn_obj_set_value(context, table, id, &value, GRN_OBJ_SET);
|
197
|
+
exception = rb_grn_context_to_exception(context, self);
|
198
|
+
grn_obj_close(context, &value);
|
199
|
+
if (!NIL_P(exception))
|
200
|
+
rb_exc_raise(exception);
|
201
|
+
rb_grn_rc_check(rc, self);
|
202
|
+
|
203
|
+
return rb_value;
|
204
|
+
}
|
205
|
+
|
206
|
+
static VALUE
|
207
|
+
rb_grn_table_key_support_array_set (VALUE self,
|
208
|
+
VALUE rb_id_or_key, VALUE rb_value)
|
209
|
+
{
|
210
|
+
if (FIXNUM_P(rb_id_or_key)) {
|
211
|
+
int argc = 2;
|
212
|
+
VALUE argv[2];
|
213
|
+
argv[0] = rb_id_or_key;
|
214
|
+
argv[1] = rb_value;
|
215
|
+
return rb_call_super(argc, argv);
|
216
|
+
} else {
|
217
|
+
return rb_grn_table_key_support_array_set_by_key(self,
|
218
|
+
rb_id_or_key,
|
219
|
+
rb_value);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
static VALUE
|
224
|
+
rb_grn_table_key_support_get_encoding (VALUE self)
|
225
|
+
{
|
226
|
+
grn_ctx *context = NULL;
|
227
|
+
grn_obj *table;
|
228
|
+
grn_encoding encoding;
|
229
|
+
grn_rc rc;
|
230
|
+
|
231
|
+
table = SELF(self, &context);
|
232
|
+
rc = grn_table_get_info(context, table, NULL, &encoding, NULL);
|
233
|
+
rb_grn_context_check(context, self);
|
234
|
+
rb_grn_rc_check(rc, self);
|
235
|
+
|
236
|
+
return GRNENCODING2RVAL(encoding);
|
237
|
+
}
|
238
|
+
|
239
|
+
static VALUE
|
240
|
+
rb_grn_table_key_support_get_default_tokenizer (VALUE self)
|
241
|
+
{
|
242
|
+
grn_ctx *context = NULL;
|
243
|
+
grn_obj *table;
|
244
|
+
grn_obj *tokenizer;
|
245
|
+
grn_rc rc;
|
246
|
+
|
247
|
+
table = SELF(self, &context);
|
248
|
+
rc = grn_table_get_info(context, table, NULL, NULL, &tokenizer);
|
249
|
+
rb_grn_context_check(context, self);
|
250
|
+
rb_grn_rc_check(rc, self);
|
251
|
+
|
252
|
+
return GRNOBJECT2RVAL(Qnil, context, tokenizer, RB_GRN_FALSE);
|
253
|
+
}
|
254
|
+
|
255
|
+
static VALUE
|
256
|
+
rb_grn_table_key_support_set_default_tokenizer (VALUE self, VALUE rb_tokenizer)
|
257
|
+
{
|
258
|
+
grn_ctx *context = NULL;
|
259
|
+
grn_obj *table;
|
260
|
+
grn_obj *tokenizer;
|
261
|
+
grn_rc rc;
|
262
|
+
|
263
|
+
table = SELF(self, &context);
|
264
|
+
tokenizer = RVAL2GRNOBJECT(rb_tokenizer, &context);
|
265
|
+
rc = grn_obj_set_info(context, table,
|
266
|
+
GRN_INFO_DEFAULT_TOKENIZER, tokenizer);
|
267
|
+
rb_grn_context_check(context, self);
|
268
|
+
rb_grn_rc_check(rc, self);
|
269
|
+
|
270
|
+
return Qnil;
|
271
|
+
}
|
272
|
+
|
273
|
+
void
|
274
|
+
rb_grn_init_table_key_support (VALUE mGrn)
|
275
|
+
{
|
276
|
+
rb_mGrnTableKeySupport = rb_define_module_under(rb_cGrnTable, "KeySupport");
|
277
|
+
|
278
|
+
rb_define_method(rb_mGrnTableKeySupport, "add",
|
279
|
+
rb_grn_table_key_support_add, 1);
|
280
|
+
rb_define_method(rb_mGrnTableKeySupport, "key",
|
281
|
+
rb_grn_table_key_support_get_key, 1);
|
282
|
+
|
283
|
+
rb_define_method(rb_mGrnTableKeySupport, "delete",
|
284
|
+
rb_grn_table_key_support_delete, 1);
|
285
|
+
|
286
|
+
rb_define_method(rb_mGrnTableKeySupport, "[]",
|
287
|
+
rb_grn_table_key_support_array_reference, 1);
|
288
|
+
rb_define_method(rb_mGrnTableKeySupport, "[]=",
|
289
|
+
rb_grn_table_key_support_array_set, 2);
|
290
|
+
|
291
|
+
rb_define_method(rb_mGrnTableKeySupport, "encoding",
|
292
|
+
rb_grn_table_key_support_get_encoding, 0);
|
293
|
+
|
294
|
+
rb_define_method(rb_mGrnTableKeySupport, "default_tokenizer",
|
295
|
+
rb_grn_table_key_support_get_default_tokenizer, 0);
|
296
|
+
|
297
|
+
rb_define_method(rb_mGrnTableKeySupport, "default_tokenizer=",
|
298
|
+
rb_grn_table_key_support_set_default_tokenizer, 1);
|
299
|
+
}
|