groonga 0.9.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. metadata +38 -227
  2. data/AUTHORS +0 -5
  3. data/NEWS.ja.rdoc +0 -114
  4. data/NEWS.rdoc +0 -116
  5. data/README.ja.rdoc +0 -63
  6. data/README.rdoc +0 -64
  7. data/Rakefile +0 -216
  8. data/benchmark/common.rb +0 -49
  9. data/benchmark/read-write-many-small-items.rb +0 -144
  10. data/benchmark/write-many-small-items.rb +0 -135
  11. data/example/bookmark.rb +0 -161
  12. data/example/index-html.rb +0 -89
  13. data/example/search/config.ru +0 -211
  14. data/example/search/public/css/groonga.css +0 -122
  15. data/ext/.gitignore +0 -2
  16. data/ext/rb-grn-accessor.c +0 -52
  17. data/ext/rb-grn-array-cursor.c +0 -36
  18. data/ext/rb-grn-array.c +0 -210
  19. data/ext/rb-grn-column.c +0 -570
  20. data/ext/rb-grn-context.c +0 -655
  21. data/ext/rb-grn-database.c +0 -415
  22. data/ext/rb-grn-encoding-support.c +0 -64
  23. data/ext/rb-grn-encoding.c +0 -257
  24. data/ext/rb-grn-exception.c +0 -1110
  25. data/ext/rb-grn-expression-builder.c +0 -75
  26. data/ext/rb-grn-expression.c +0 -732
  27. data/ext/rb-grn-fix-size-column.c +0 -166
  28. data/ext/rb-grn-hash-cursor.c +0 -38
  29. data/ext/rb-grn-hash.c +0 -294
  30. data/ext/rb-grn-index-column.c +0 -488
  31. data/ext/rb-grn-logger.c +0 -325
  32. data/ext/rb-grn-object.c +0 -1335
  33. data/ext/rb-grn-operation.c +0 -198
  34. data/ext/rb-grn-patricia-trie-cursor.c +0 -39
  35. data/ext/rb-grn-patricia-trie.c +0 -488
  36. data/ext/rb-grn-procedure.c +0 -52
  37. data/ext/rb-grn-query.c +0 -260
  38. data/ext/rb-grn-record.c +0 -40
  39. data/ext/rb-grn-snippet.c +0 -328
  40. data/ext/rb-grn-table-cursor-key-support.c +0 -69
  41. data/ext/rb-grn-table-cursor.c +0 -246
  42. data/ext/rb-grn-table-key-support.c +0 -731
  43. data/ext/rb-grn-table.c +0 -2038
  44. data/ext/rb-grn-type.c +0 -181
  45. data/ext/rb-grn-utils.c +0 -769
  46. data/ext/rb-grn-variable-size-column.c +0 -36
  47. data/ext/rb-grn-variable.c +0 -108
  48. data/ext/rb-grn.h +0 -684
  49. data/ext/rb-groonga.c +0 -113
  50. data/extconf.rb +0 -216
  51. data/html/bar.svg +0 -153
  52. data/html/developer.html +0 -121
  53. data/html/developer.svg +0 -469
  54. data/html/download.svg +0 -253
  55. data/html/favicon.ico +0 -0
  56. data/html/favicon.xcf +0 -0
  57. data/html/footer.html.erb +0 -28
  58. data/html/head.html.erb +0 -4
  59. data/html/header.html.erb +0 -17
  60. data/html/index.html +0 -147
  61. data/html/install.svg +0 -636
  62. data/html/logo.xcf +0 -0
  63. data/html/ranguba.css +0 -248
  64. data/html/tutorial.svg +0 -559
  65. data/lib/groonga.rb +0 -83
  66. data/lib/groonga/expression-builder.rb +0 -285
  67. data/lib/groonga/patricia-trie.rb +0 -53
  68. data/lib/groonga/record.rb +0 -276
  69. data/lib/groonga/schema.rb +0 -916
  70. data/license/GPL +0 -340
  71. data/license/LGPL +0 -504
  72. data/license/RUBY +0 -59
  73. data/misc/grnop2ruby.rb +0 -49
  74. data/pkg-config.rb +0 -333
  75. data/src/rb-grn-table-cursor.c +0 -296
  76. data/test-unit/Rakefile +0 -40
  77. data/test-unit/TODO +0 -5
  78. data/test-unit/bin/testrb +0 -5
  79. data/test-unit/html/classic.html +0 -15
  80. data/test-unit/html/index.html +0 -25
  81. data/test-unit/html/index.html.ja +0 -27
  82. data/test-unit/lib/test/unit.rb +0 -323
  83. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
  84. data/test-unit/lib/test/unit/assertions.rb +0 -1230
  85. data/test-unit/lib/test/unit/attribute.rb +0 -125
  86. data/test-unit/lib/test/unit/autorunner.rb +0 -353
  87. data/test-unit/lib/test/unit/collector.rb +0 -36
  88. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  89. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  90. data/test-unit/lib/test/unit/collector/load.rb +0 -136
  91. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  92. data/test-unit/lib/test/unit/color-scheme.rb +0 -102
  93. data/test-unit/lib/test/unit/color.rb +0 -96
  94. data/test-unit/lib/test/unit/diff.rb +0 -724
  95. data/test-unit/lib/test/unit/error.rb +0 -130
  96. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  97. data/test-unit/lib/test/unit/failure.rb +0 -136
  98. data/test-unit/lib/test/unit/fixture.rb +0 -176
  99. data/test-unit/lib/test/unit/notification.rb +0 -129
  100. data/test-unit/lib/test/unit/omission.rb +0 -191
  101. data/test-unit/lib/test/unit/pending.rb +0 -150
  102. data/test-unit/lib/test/unit/priority.rb +0 -181
  103. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  104. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  105. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  106. data/test-unit/lib/test/unit/testcase.rb +0 -476
  107. data/test-unit/lib/test/unit/testresult.rb +0 -89
  108. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  109. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  110. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -464
  111. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
  112. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -92
  113. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -28
  114. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  115. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  116. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
  117. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  118. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  119. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  120. data/test-unit/lib/test/unit/version.rb +0 -7
  121. data/test-unit/sample/adder.rb +0 -13
  122. data/test-unit/sample/subtracter.rb +0 -12
  123. data/test-unit/sample/test_adder.rb +0 -20
  124. data/test-unit/sample/test_subtracter.rb +0 -20
  125. data/test-unit/sample/test_user.rb +0 -23
  126. data/test-unit/test/collector/test-descendant.rb +0 -133
  127. data/test-unit/test/collector/test-load.rb +0 -329
  128. data/test-unit/test/collector/test_dir.rb +0 -406
  129. data/test-unit/test/collector/test_objectspace.rb +0 -100
  130. data/test-unit/test/run-test.rb +0 -15
  131. data/test-unit/test/test-attribute.rb +0 -86
  132. data/test-unit/test/test-color-scheme.rb +0 -67
  133. data/test-unit/test/test-color.rb +0 -47
  134. data/test-unit/test/test-diff.rb +0 -518
  135. data/test-unit/test/test-emacs-runner.rb +0 -60
  136. data/test-unit/test/test-fixture.rb +0 -287
  137. data/test-unit/test/test-notification.rb +0 -33
  138. data/test-unit/test/test-omission.rb +0 -81
  139. data/test-unit/test/test-pending.rb +0 -70
  140. data/test-unit/test/test-priority.rb +0 -119
  141. data/test-unit/test/test-testcase.rb +0 -554
  142. data/test-unit/test/test_assertions.rb +0 -1151
  143. data/test-unit/test/test_error.rb +0 -26
  144. data/test-unit/test/test_failure.rb +0 -33
  145. data/test-unit/test/test_testresult.rb +0 -113
  146. data/test-unit/test/test_testsuite.rb +0 -129
  147. data/test-unit/test/testunit-test-util.rb +0 -14
  148. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  149. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  150. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  151. data/test-unit/test/util/test_observable.rb +0 -102
  152. data/test-unit/test/util/test_procwrapper.rb +0 -36
  153. data/test/.gitignore +0 -1
  154. data/test/groonga-test-utils.rb +0 -106
  155. data/test/run-test.rb +0 -58
  156. data/test/test-array.rb +0 -97
  157. data/test/test-column.rb +0 -298
  158. data/test/test-context.rb +0 -73
  159. data/test/test-database.rb +0 -113
  160. data/test/test-encoding.rb +0 -33
  161. data/test/test-exception.rb +0 -93
  162. data/test/test-expression-builder.rb +0 -156
  163. data/test/test-expression.rb +0 -133
  164. data/test/test-fix-size-column.rb +0 -65
  165. data/test/test-gqtp.rb +0 -70
  166. data/test/test-hash.rb +0 -312
  167. data/test/test-index-column.rb +0 -81
  168. data/test/test-patricia-trie.rb +0 -189
  169. data/test/test-procedure.rb +0 -37
  170. data/test/test-query.rb +0 -22
  171. data/test/test-record.rb +0 -268
  172. data/test/test-remote.rb +0 -53
  173. data/test/test-schema.rb +0 -416
  174. data/test/test-snippet.rb +0 -121
  175. data/test/test-table-cursor.rb +0 -153
  176. data/test/test-table-offset-and-limit.rb +0 -102
  177. data/test/test-table-select-normalize.rb +0 -48
  178. data/test/test-table-select.rb +0 -145
  179. data/test/test-table.rb +0 -642
  180. data/test/test-type.rb +0 -61
  181. data/test/test-variable-size-column.rb +0 -98
  182. data/test/test-variable.rb +0 -28
  183. data/test/test-vector-column.rb +0 -76
  184. data/test/test-version.rb +0 -31
  185. data/text/TUTORIAL.ja.rdoc +0 -392
  186. data/text/expression.rdoc +0 -284
data/ext/rb-grn-context.c DELETED
@@ -1,655 +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) (RVAL2GRNCONTEXT(object))
22
-
23
- static VALUE cGrnContext;
24
-
25
- /*
26
- * Document-class: Groonga::Context
27
- *
28
- * groonga全体に渡る情報を管理するオブジェクト。通常のアプリ
29
- * ケーションでは1つのコンテキストを作成し、それを利用する。
30
- * 複数のコンテキストを利用する必要はない。
31
- *
32
- * デフォルトで使用されるコンテキストは
33
- * Groonga::Context#defaultでアクセスできる。コンテキストを
34
- * 指定できる箇所でコンテキストの指定を省略したり+nil+を指定
35
- * した場合はGroonga::Context.defaultが利用される。
36
- *
37
- * また、デフォルトのコンテキストは必要になると暗黙のうちに
38
- * 作成される。そのため、コンテキストを意識することは少ない。
39
- *
40
- * 暗黙のうちに作成されるコンテキストにオプションを指定する
41
- * 場合はGroonga::Context.default_options=を使用する。
42
- */
43
-
44
- grn_ctx *
45
- rb_grn_context_from_ruby_object (VALUE object)
46
- {
47
- RbGrnContext *rb_grn_context;
48
-
49
- if (!RVAL2CBOOL(rb_obj_is_kind_of(object, cGrnContext))) {
50
- rb_raise(rb_eTypeError, "not a groonga context");
51
- }
52
-
53
- Data_Get_Struct(object, RbGrnContext, rb_grn_context);
54
- if (!rb_grn_context)
55
- rb_raise(rb_eGrnError, "groonga context is NULL");
56
- return rb_grn_context->context;
57
- }
58
-
59
- void
60
- rb_grn_context_fin (grn_ctx *context)
61
- {
62
- grn_obj *database;
63
-
64
- if (context->stat == GRN_CTX_FIN)
65
- return;
66
-
67
- database = grn_ctx_db(context);
68
- debug("context:database: %p:%p\n", context, database);
69
- if (database && database->header.type == GRN_DB) {
70
- grn_obj_close(context, database);
71
- }
72
- grn_ctx_fin(context);
73
- }
74
-
75
- static void
76
- rb_grn_context_free (void *pointer)
77
- {
78
- RbGrnContext *rb_grn_context = pointer;
79
- grn_ctx *context;
80
-
81
- context = rb_grn_context->context;
82
- debug("context-free: %p\n", context);
83
- if (!rb_grn_exited)
84
- rb_grn_context_fin(context);
85
- debug("context-free: %p: done\n", context);
86
- xfree(rb_grn_context);
87
- }
88
-
89
- static VALUE
90
- rb_grn_context_alloc (VALUE klass)
91
- {
92
- return Data_Wrap_Struct(klass, NULL, rb_grn_context_free, NULL);
93
- }
94
-
95
- VALUE
96
- rb_grn_context_to_exception (grn_ctx *context, VALUE related_object)
97
- {
98
- VALUE exception, exception_class;
99
- const char *message;
100
- grn_obj bulk;
101
-
102
- if (context->rc == GRN_SUCCESS)
103
- return Qnil;
104
-
105
- exception_class = rb_grn_rc_to_exception(context->rc);
106
- message = rb_grn_rc_to_message(context->rc);
107
-
108
- GRN_OBJ_INIT(&bulk, GRN_BULK, 0, GRN_ID_NIL);
109
- GRN_TEXT_PUTS(context, &bulk, message);
110
- GRN_TEXT_PUTS(context, &bulk, ": ");
111
- GRN_TEXT_PUTS(context, &bulk, context->errbuf);
112
- if (!NIL_P(related_object)) {
113
- GRN_TEXT_PUTS(context, &bulk, ": ");
114
- GRN_TEXT_PUTS(context, &bulk, rb_grn_inspect(related_object));
115
- }
116
- GRN_TEXT_PUTS(context, &bulk, "\n");
117
- GRN_TEXT_PUTS(context, &bulk, context->errfile);
118
- GRN_TEXT_PUTS(context, &bulk, ":");
119
- grn_text_itoa(context, &bulk, context->errline);
120
- GRN_TEXT_PUTS(context, &bulk, ": ");
121
- GRN_TEXT_PUTS(context, &bulk, context->errfunc);
122
- GRN_TEXT_PUTS(context, &bulk, "()");
123
- exception = rb_funcall(exception_class, rb_intern("new"), 1,
124
- rb_str_new(GRN_BULK_HEAD(&bulk),
125
- GRN_BULK_VSIZE(&bulk)));
126
- grn_obj_close(context, &bulk);
127
-
128
- return exception;
129
- }
130
-
131
- void
132
- rb_grn_context_check (grn_ctx *context, VALUE related_object)
133
- {
134
- VALUE exception;
135
-
136
- exception = rb_grn_context_to_exception(context, related_object);
137
- if (NIL_P(exception))
138
- return;
139
-
140
- rb_exc_raise(exception);
141
- }
142
-
143
- grn_ctx *
144
- rb_grn_context_ensure (VALUE *context)
145
- {
146
- if (NIL_P(*context))
147
- *context = rb_grn_context_get_default();
148
- return SELF(*context);
149
- }
150
-
151
- VALUE
152
- rb_grn_context_rb_string_new (grn_ctx *context, const char *string, long length)
153
- {
154
- if (length < 0)
155
- length = strlen(string);
156
- #ifdef HAVE_RUBY_ENCODING_H
157
- return rb_enc_str_new(string, length,
158
- rb_grn_encoding_to_ruby_encoding(context->encoding));
159
- #else
160
- return rb_str_new(string, length);
161
- #endif
162
- }
163
-
164
- VALUE
165
- rb_grn_context_rb_string_encode (grn_ctx *context, VALUE rb_string)
166
- {
167
- #ifdef HAVE_RUBY_ENCODING_H
168
- rb_encoding *encoding, *to_encode;
169
-
170
- encoding = rb_enc_get(rb_string);
171
- to_encode = rb_grn_encoding_to_ruby_encoding(context->encoding);
172
- if (rb_enc_to_index(encoding) != rb_enc_to_index(to_encode))
173
- rb_string = rb_str_encode(rb_string, rb_enc_from_encoding(to_encode),
174
- 0, Qnil);
175
- #endif
176
- return rb_string;
177
- }
178
-
179
- /*
180
- * call-seq:
181
- * Groonga::Context.default -> Groonga::Context
182
- *
183
- * デフォルトのコンテキストを返す。デフォルトのコンテキスト
184
- * が作成されていない場合は暗黙のうちに作成し、それを返す。
185
- *
186
- * 暗黙のうちにコンテキストを作成する場合は、
187
- * Groonga::Context.default_optionsに設定されているオプショ
188
- * ンを利用する。
189
- */
190
- static VALUE
191
- rb_grn_context_s_get_default (VALUE self)
192
- {
193
- VALUE context;
194
-
195
- context = rb_cv_get(self, "@@default");
196
- if (NIL_P(context)) {
197
- context = rb_funcall(cGrnContext, rb_intern("new"), 0);
198
- rb_cv_set(self, "@@default", context);
199
- }
200
- return context;
201
- }
202
-
203
- VALUE
204
- rb_grn_context_get_default (void)
205
- {
206
- return rb_grn_context_s_get_default(cGrnContext);
207
- }
208
-
209
- /*
210
- * call-seq:
211
- * Groonga::Context.default=(context)
212
- *
213
- * デフォルトのコンテキストを設定する。+nil+を指定すると、デ
214
- * フォルトのコンテキストをリセットする。リセットすると、次
215
- * 回Groonga::Context.defaultを呼び出したときに新しくコンテ
216
- * キストが作成される。
217
- */
218
- static VALUE
219
- rb_grn_context_s_set_default (VALUE self, VALUE context)
220
- {
221
- rb_cv_set(self, "@@default", context);
222
- return Qnil;
223
- }
224
-
225
- /*
226
- * call-seq:
227
- * Groonga::Context.default_options -> Hash or nil
228
- *
229
- * コンテキストを作成する時に利用するデフォルトのオプション
230
- * を返す。
231
- */
232
- static VALUE
233
- rb_grn_context_s_get_default_options (VALUE self)
234
- {
235
- return rb_cv_get(self, "@@default_options");
236
- }
237
-
238
- /*
239
- * call-seq:
240
- * Groonga::Context.default_options=(options)
241
- *
242
- * コンテキストを作成する時に利用するデフォルトのオプション
243
- * を設定する。利用可能なオプションは
244
- * Groonga::Context.newを参照。
245
- */
246
- static VALUE
247
- rb_grn_context_s_set_default_options (VALUE self, VALUE options)
248
- {
249
- rb_cv_set(self, "@@default_options", options);
250
- return Qnil;
251
- }
252
-
253
- /*
254
- * call-seq:
255
- * Groonga::Context.new(options=nil)
256
- *
257
- * コンテキストを作成する。_options_に指定可能な値は以下の通
258
- * り。
259
- *
260
- * [+:encoding+]
261
- * エンコーディングを指定する。エンコーディングの指定方法
262
- * はGroonga::Encodingを参照。
263
- */
264
- static VALUE
265
- rb_grn_context_initialize (int argc, VALUE *argv, VALUE self)
266
- {
267
- RbGrnContext *rb_grn_context;
268
- grn_ctx *context;
269
- int flags = 0;
270
- VALUE options, default_options;
271
- VALUE rb_encoding;
272
-
273
- rb_scan_args(argc, argv, "01", &options);
274
- default_options = rb_grn_context_s_get_default_options(rb_obj_class(self));
275
- if (NIL_P(default_options))
276
- default_options = rb_hash_new();
277
-
278
- if (NIL_P(options))
279
- options = rb_hash_new();
280
- options = rb_funcall(default_options, rb_intern("merge"), 1, options);
281
-
282
- rb_grn_scan_options(options,
283
- "encoding", &rb_encoding,
284
- NULL);
285
-
286
- rb_grn_context = ALLOC(RbGrnContext);
287
- DATA_PTR(self) = rb_grn_context;
288
- rb_grn_context->self = self;
289
- context = rb_grn_context->context = grn_ctx_open(flags);
290
- rb_grn_context_check(context, self);
291
-
292
- GRN_CTX_USER_DATA(context)->ptr = rb_grn_context;
293
-
294
- if (!NIL_P(rb_encoding)) {
295
- grn_encoding encoding;
296
-
297
- encoding = RVAL2GRNENCODING(rb_encoding, NULL);
298
- GRN_CTX_SET_ENCODING(context, encoding);
299
- }
300
-
301
- debug("context new: %p\n", context);
302
-
303
- return Qnil;
304
- }
305
-
306
- /*
307
- * call-seq:
308
- * context.inspect -> String
309
- *
310
- * コンテキストの中身を人に見やすい文字列で返す。
311
- */
312
- static VALUE
313
- rb_grn_context_inspect (VALUE self)
314
- {
315
- VALUE inspected;
316
- grn_ctx *context;
317
- grn_obj *database;
318
- VALUE rb_database;
319
-
320
- context = SELF(self);
321
-
322
- inspected = rb_str_new2("#<");
323
- rb_str_concat(inspected, rb_inspect(rb_obj_class(self)));
324
- rb_str_cat2(inspected, " ");
325
-
326
- rb_str_cat2(inspected, "encoding: <");
327
- rb_str_concat(inspected, rb_inspect(GRNENCODING2RVAL(context->encoding)));
328
- rb_str_cat2(inspected, ">, ");
329
-
330
- rb_str_cat2(inspected, "database: <");
331
- database = grn_ctx_db(context);
332
- rb_database = GRNDB2RVAL(context, database, RB_GRN_FALSE);
333
- rb_str_concat(inspected, rb_inspect(rb_database));
334
- rb_str_cat2(inspected, ">");
335
-
336
- rb_str_cat2(inspected, ">");
337
- return inspected;
338
- }
339
-
340
- /*
341
- * call-seq:
342
- * context.encoding -> Groonga::Encoding
343
- *
344
- * コンテキストが使うエンコーディングを返す。
345
- */
346
- static VALUE
347
- rb_grn_context_get_encoding (VALUE self)
348
- {
349
- return GRNENCODING2RVAL(GRN_CTX_GET_ENCODING(SELF(self)));
350
- }
351
-
352
- /*
353
- * call-seq:
354
- * context.encoding=(encoding)
355
- *
356
- * コンテキストが使うエンコーディングを設定する。エンコーディ
357
- * ングの指定のしかたはGroonga::Encodingを参照。
358
- */
359
- static VALUE
360
- rb_grn_context_set_encoding (VALUE self, VALUE rb_encoding)
361
- {
362
- grn_ctx *context;
363
- grn_encoding encoding;
364
-
365
- context = SELF(self);
366
- encoding = RVAL2GRNENCODING(rb_encoding, NULL);
367
- GRN_CTX_SET_ENCODING(context, encoding);
368
-
369
- return rb_encoding;
370
- }
371
-
372
- /*
373
- * call-seq:
374
- * context.database -> Groonga::Database
375
- *
376
- * コンテキストが使うデータベースを返す。
377
- */
378
- static VALUE
379
- rb_grn_context_get_database (VALUE self)
380
- {
381
- grn_ctx *context;
382
-
383
- context = SELF(self);
384
- return GRNDB2RVAL(context, grn_ctx_db(context), RB_GRN_FALSE);
385
- }
386
-
387
- /*
388
- * call-seq:
389
- * context.connect(options=nil)
390
- *
391
- * groongaサーバに接続する。_options_に指定可能な値は以下の通
392
- * り。
393
- *
394
- * [+:host+]
395
- * groongaサーバのホスト名。またはIPアドレス。省略すると
396
- * "localhost"に接続する。
397
- *
398
- * [+:port+]
399
- * groongaサーバのポート番号。省略すると10041番ポートに接
400
- * 続する。
401
- */
402
- static VALUE
403
- rb_grn_context_connect (int argc, VALUE *argv, VALUE self)
404
- {
405
- grn_ctx *context;
406
- char *host;
407
- int port;
408
- int flags = 0;
409
- grn_rc rc;
410
- VALUE options, rb_host, rb_port;
411
-
412
- rb_scan_args(argc, argv, "01", &options);
413
- rb_grn_scan_options(options,
414
- "host", &rb_host,
415
- "port", &rb_port,
416
- NULL);
417
-
418
- context = SELF(self);
419
-
420
- if (NIL_P(rb_host)) {
421
- host = "localhost";
422
- } else {
423
- host = StringValueCStr(rb_host);
424
- }
425
-
426
- if (NIL_P(rb_port)) {
427
- port = 10041;
428
- } else {
429
- port = NUM2INT(rb_port);
430
- }
431
-
432
- rc = grn_ctx_connect(context, host, port, flags);
433
- rb_grn_context_check(context, self);
434
- rb_grn_rc_check(rc, self);
435
-
436
- return Qnil;
437
- }
438
-
439
- /*
440
- * call-seq:
441
- * context.send(string) -> ID
442
- *
443
- * groongaサーバにクエリ文字列を送信する。
444
- */
445
- static VALUE
446
- rb_grn_context_send (VALUE self, VALUE rb_string)
447
- {
448
- grn_ctx *context;
449
- char *string;
450
- unsigned int string_size;
451
- int flags = 0;
452
- unsigned int query_id;
453
-
454
- context = SELF(self);
455
- string = StringValuePtr(rb_string);
456
- string_size = RSTRING_LEN(rb_string);
457
- query_id = grn_ctx_send(context, string, string_size, flags);
458
- rb_grn_context_check(context, self);
459
-
460
- return UINT2NUM(query_id);
461
- }
462
-
463
- /*
464
- * call-seq:
465
- * context.receive -> [ID, String]
466
- *
467
- * groongaサーバからクエリ実行結果文字列を受信する。
468
- */
469
- static VALUE
470
- rb_grn_context_receive (VALUE self)
471
- {
472
- grn_ctx *context;
473
- char *string;
474
- unsigned string_size;
475
- int flags = 0;
476
- unsigned int query_id;
477
-
478
- context = SELF(self);
479
- query_id = grn_ctx_recv(context, &string, &string_size, &flags);
480
- rb_grn_context_check(context, self);
481
-
482
- return rb_ary_new3(2, UINT2NUM(query_id), rb_str_new(string, string_size));
483
- }
484
-
485
- static const char *
486
- grn_type_name_old_to_new (const char *name, unsigned int name_size)
487
- {
488
- unsigned int i;
489
-
490
- for (i = 0; i < name_size; i++) {
491
- if (name[i] == '\0')
492
- return NULL;
493
- }
494
-
495
- if (strcmp(name, "<int>") == 0) {
496
- return "Int32";
497
- } else if (strcmp(name, "<uint>") == 0) {
498
- return "UInt32";
499
- } else if (strcmp(name, "<int64>") == 0) {
500
- return "Int64";
501
- } else if (strcmp(name, "<uint64>") == 0) {
502
- return "UInt64";
503
- } else if (strcmp(name, "<float>") == 0) {
504
- return "Float";
505
- } else if (strcmp(name, "<time>") == 0) {
506
- return "Time";
507
- } else if (strcmp(name, "<shorttext>") == 0) {
508
- return "ShortText";
509
- } else if (strcmp(name, "<text>") == 0) {
510
- return "Text";
511
- } else if (strcmp(name, "<longtext>") == 0) {
512
- return "LongText";
513
- } else if (strcmp(name, "<token:delimit>") == 0) {
514
- return "TokenDelimit";
515
- } else if (strcmp(name, "<token:unigram>") == 0) {
516
- return "TokenUnigram";
517
- } else if (strcmp(name, "<token:bigram>") == 0) {
518
- return "TokenBigram";
519
- } else if (strcmp(name, "<token:trigram>") == 0) {
520
- return "TokenTrigram";
521
- } else if (strcmp(name, "<token:mecab>") == 0) {
522
- return "TokenMecab";
523
- }
524
-
525
- return NULL;
526
- }
527
-
528
- grn_obj *
529
- rb_grn_context_get_backward_compatibility (grn_ctx *context,
530
- const char *name,
531
- unsigned int name_size)
532
- {
533
- grn_obj *object;
534
-
535
- object = grn_ctx_get(context, name, name_size);
536
- if (!object) {
537
- const char *new_type_name;
538
-
539
- new_type_name = grn_type_name_old_to_new(name, name_size);
540
- if (new_type_name) {
541
- object = grn_ctx_get(context, new_type_name, strlen(new_type_name));
542
- #if 0
543
- if (object) {
544
- rb_warn("deprecated old data type name <%s> is used. "
545
- "Use new data type name <%s> instead.",
546
- name, new_type_name);
547
- }
548
- #endif
549
- }
550
- }
551
-
552
- return object;
553
- }
554
-
555
-
556
- /*
557
- * call-seq:
558
- * context[name] -> Groonga::Object or nil
559
- * context[id] -> Groonga::Object or nil
560
- *
561
- * コンテキスト管理下にあるオブジェクトを返す。
562
- *
563
- * _name_として文字列を指定した場合はオブジェクト名でオブジェ
564
- * クトを検索する。
565
- *
566
- * _id_として数値を指定した場合はオブジェクトIDでオブジェク
567
- * トを検索する。
568
- */
569
- static VALUE
570
- rb_grn_context_array_reference (VALUE self, VALUE name_or_id)
571
- {
572
- grn_ctx *context;
573
- grn_obj *object;
574
- const char *name;
575
- unsigned int name_size;
576
- grn_id id;
577
-
578
- context = SELF(self);
579
- switch (TYPE(name_or_id)) {
580
- case T_SYMBOL:
581
- name = rb_id2name(SYM2ID(name_or_id));
582
- name_size = strlen(name);
583
- object = rb_grn_context_get_backward_compatibility(context,
584
- name, name_size);
585
- break;
586
- case T_STRING:
587
- name = StringValuePtr(name_or_id);
588
- name_size = RSTRING_LEN(name_or_id);
589
- object = rb_grn_context_get_backward_compatibility(context,
590
- name, name_size);
591
- break;
592
- case T_FIXNUM:
593
- id = NUM2UINT(name_or_id);
594
- object = grn_ctx_at(context, id);
595
- break;
596
- default:
597
- rb_raise(rb_eArgError,
598
- "should be String, Symbol or unsigned integer: %s",
599
- rb_grn_inspect(name_or_id));
600
- break;
601
- }
602
-
603
- return GRNOBJECT2RVAL(Qnil, context, object, RB_GRN_FALSE);
604
- }
605
-
606
- /*
607
- * call-seq:
608
- * context.pop -> 値
609
- *
610
- * コンテキスト内にあるスタックから値を取り出す。このスタッ
611
- * クにはGroonga::Expression#executeの実行結果が格納される。
612
- */
613
- static VALUE
614
- rb_grn_context_pop (VALUE self)
615
- {
616
- grn_ctx *context;
617
- context = SELF(self);
618
- return GRNOBJ2RVAL(Qnil, context, grn_ctx_pop(context), self);
619
- }
620
-
621
- void
622
- rb_grn_init_context (VALUE mGrn)
623
- {
624
- cGrnContext = rb_define_class_under(mGrn, "Context", rb_cObject);
625
- rb_define_alloc_func(cGrnContext, rb_grn_context_alloc);
626
-
627
- rb_cv_set(cGrnContext, "@@default", Qnil);
628
- rb_cv_set(cGrnContext, "@@default_options", Qnil);
629
-
630
- rb_define_singleton_method(cGrnContext, "default",
631
- rb_grn_context_s_get_default, 0);
632
- rb_define_singleton_method(cGrnContext, "default=",
633
- rb_grn_context_s_set_default, 1);
634
- rb_define_singleton_method(cGrnContext, "default_options",
635
- rb_grn_context_s_get_default_options, 0);
636
- rb_define_singleton_method(cGrnContext, "default_options=",
637
- rb_grn_context_s_set_default_options, 1);
638
-
639
- rb_define_method(cGrnContext, "initialize", rb_grn_context_initialize, -1);
640
-
641
- rb_define_method(cGrnContext, "inspect", rb_grn_context_inspect, 0);
642
-
643
- rb_define_method(cGrnContext, "encoding", rb_grn_context_get_encoding, 0);
644
- rb_define_method(cGrnContext, "encoding=", rb_grn_context_set_encoding, 1);
645
-
646
- rb_define_method(cGrnContext, "database", rb_grn_context_get_database, 0);
647
-
648
- rb_define_method(cGrnContext, "[]", rb_grn_context_array_reference, 1);
649
-
650
- rb_define_method(cGrnContext, "pop", rb_grn_context_pop, 0);
651
-
652
- rb_define_method(cGrnContext, "connect", rb_grn_context_connect, -1);
653
- rb_define_method(cGrnContext, "send", rb_grn_context_send, 1);
654
- rb_define_method(cGrnContext, "receive", rb_grn_context_receive, 0);
655
- }