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