groonga 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/NEWS.ja.rdoc +13 -0
  2. data/NEWS.rdoc +13 -0
  3. data/README.ja.rdoc +2 -1
  4. data/README.rdoc +2 -1
  5. data/Rakefile +0 -1
  6. data/TUTORIAL.ja.rdoc +49 -4
  7. data/benchmark/read-write-many-small-items.rb +5 -4
  8. data/benchmark/write-many-small-items.rb +5 -4
  9. data/example/bookmark.rb +30 -1
  10. data/example/index-html.rb +79 -0
  11. data/example/search/config.ru +182 -0
  12. data/example/search/public/css/groonga.css +122 -0
  13. data/ext/rb-grn-array.c +12 -9
  14. data/ext/rb-grn-column.c +13 -8
  15. data/ext/rb-grn-context.c +34 -16
  16. data/ext/rb-grn-database.c +3 -2
  17. data/ext/rb-grn-expression-builder.c +8 -2
  18. data/ext/rb-grn-expression.c +3 -3
  19. data/ext/rb-grn-hash.c +13 -10
  20. data/ext/rb-grn-object.c +127 -19
  21. data/ext/rb-grn-patricia-trie.c +8 -7
  22. data/ext/rb-grn-table-cursor.c +2 -40
  23. data/ext/rb-grn-table.c +154 -42
  24. data/ext/rb-grn-type.c +18 -10
  25. data/ext/rb-grn-utils.c +22 -20
  26. data/ext/rb-grn.h +9 -12
  27. data/extconf.rb +1 -1
  28. data/html/developer.html +1 -1
  29. data/html/index.html +2 -2
  30. data/lib/groonga/expression-builder.rb +133 -63
  31. data/lib/groonga/schema.rb +229 -37
  32. data/test/groonga-test-utils.rb +1 -1
  33. data/test/test-array.rb +1 -0
  34. data/test/test-context.rb +7 -1
  35. data/test/test-database.rb +11 -3
  36. data/test/test-expression-builder.rb +26 -2
  37. data/test/test-fix-size-column.rb +2 -1
  38. data/test/test-hash.rb +6 -1
  39. data/test/test-record.rb +2 -1
  40. data/test/test-schema.rb +85 -10
  41. data/test/test-table.rb +99 -3
  42. data/test/test-type.rb +3 -2
  43. data/test/test-variable-size-column.rb +2 -1
  44. data/test-unit/Rakefile +6 -1
  45. data/test-unit/lib/test/unit/autorunner.rb +26 -3
  46. data/test-unit/lib/test/unit/priority.rb +21 -1
  47. data/test-unit/lib/test/unit/testcase.rb +101 -36
  48. data/test-unit/lib/test/unit/ui/console/testrunner.rb +7 -4
  49. data/test-unit/test/{test_testcase.rb → test-testcase.rb} +30 -1
  50. data/test-unit/test/test_assertions.rb +1 -1
  51. metadata +9 -6
data/ext/rb-grn-array.c CHANGED
@@ -62,8 +62,11 @@ VALUE rb_cGrnArray;
62
62
  * Groonga::Contextに結びついているデータベースが一時デー
63
63
  * タベースの場合は例外が発生する。
64
64
  *
65
- * [+:value_size+]
66
- * 値の大きさを指定する。省略すると0になる。
65
+ * [+:value_type+]
66
+ * 値の型を指定する。省略すると値のための領域を確保しない。
67
+ * 値を保存したい場合は必ず指定すること。
68
+ *
69
+ * 参考: Groonga::Type.new
67
70
  *
68
71
  * [+:sub_records+]
69
72
  * +true+を指定すると#groupでグループ化したときに、
@@ -91,13 +94,13 @@ static VALUE
91
94
  rb_grn_array_s_create (int argc, VALUE *argv, VALUE klass)
92
95
  {
93
96
  grn_ctx *context = NULL;
94
- grn_obj *table;
97
+ grn_obj *value_type = NULL, *table;
95
98
  const char *name = NULL, *path = NULL;
96
- unsigned name_size = 0, value_size = 0;
99
+ unsigned name_size = 0;
97
100
  grn_obj_flags flags = GRN_TABLE_NO_KEY;
98
101
  VALUE rb_table;
99
102
  VALUE options, rb_context, rb_name, rb_path, rb_persistent;
100
- VALUE rb_value_size, rb_sub_records;
103
+ VALUE rb_value_type, rb_sub_records;
101
104
 
102
105
  rb_scan_args(argc, argv, "01", &options);
103
106
 
@@ -106,7 +109,7 @@ rb_grn_array_s_create (int argc, VALUE *argv, VALUE klass)
106
109
  "name", &rb_name,
107
110
  "path", &rb_path,
108
111
  "persistent", &rb_persistent,
109
- "value_size", &rb_value_size,
112
+ "value_type", &rb_value_type,
110
113
  "sub_records", &rb_sub_records,
111
114
  NULL);
112
115
 
@@ -126,14 +129,14 @@ rb_grn_array_s_create (int argc, VALUE *argv, VALUE klass)
126
129
  if (RVAL2CBOOL(rb_persistent))
127
130
  flags |= GRN_OBJ_PERSISTENT;
128
131
 
129
- if (!NIL_P(rb_value_size))
130
- value_size = NUM2UINT(rb_value_size);
132
+ if (!NIL_P(rb_value_type))
133
+ value_type = RVAL2GRNOBJECT(rb_value_type, &context);
131
134
 
132
135
  if (RVAL2CBOOL(rb_sub_records))
133
136
  flags |= GRN_OBJ_WITH_SUBREC;
134
137
 
135
138
  table = grn_table_create(context, name, name_size, path,
136
- flags, NULL, value_size);
139
+ flags, NULL, value_type);
137
140
  if (!table)
138
141
  rb_grn_context_check(context, rb_ary_new4(argc, argv));
139
142
  rb_table = GRNOBJECT2RVAL(klass, context, table, RB_GRN_TRUE);
data/ext/rb-grn-column.c CHANGED
@@ -170,10 +170,14 @@ rb_grn_column_select (int argc, VALUE *argv, VALUE self)
170
170
  grn_rc rc;
171
171
  VALUE options;
172
172
  VALUE rb_query, rb_name, rb_operator, rb_result;
173
- VALUE rb_expression, builder;
173
+ char *name = NULL, *query;
174
+ unsigned name_size = 0, query_size;
174
175
 
175
176
  rb_scan_args(argc, argv, "11", &rb_query, &options);
176
177
 
178
+ query = StringValueCStr(rb_query);
179
+ query_size = RSTRING_LEN(rb_query);
180
+
177
181
  rb_grn_column_deconstruct(SELF(self), &column, &context,
178
182
  NULL, NULL,
179
183
  NULL, NULL, NULL);
@@ -185,6 +189,11 @@ rb_grn_column_select (int argc, VALUE *argv, VALUE self)
185
189
  "name", &rb_name,
186
190
  NULL);
187
191
 
192
+ if (!NIL_P(rb_name)) {
193
+ name = StringValueCStr(rb_name);
194
+ name_size = RSTRING_LEN(rb_name);
195
+ }
196
+
188
197
  if (!NIL_P(rb_operator))
189
198
  operator = NUM2INT(rb_operator);
190
199
 
@@ -198,13 +207,9 @@ rb_grn_column_select (int argc, VALUE *argv, VALUE self)
198
207
  result = RVAL2GRNTABLE(rb_result, &context);
199
208
  }
200
209
 
201
- builder = rb_grn_column_expression_builder_new(self, rb_name, rb_query);
202
- rb_expression = rb_grn_column_expression_builder_build(builder);
203
-
204
- rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_expression)),
205
- &expression, NULL,
206
- NULL, NULL, NULL, NULL);
207
-
210
+ expression = grn_expr_create_from_str(context, name, name_size,
211
+ query, query_size,
212
+ table, column);
208
213
  rc = grn_table_select(context, table, expression, result, operator);
209
214
  rb_grn_context_check(context, self);
210
215
  rb_grn_rc_check(rc, self);
data/ext/rb-grn-context.c CHANGED
@@ -44,23 +44,25 @@ static VALUE cGrnContext;
44
44
  grn_ctx *
45
45
  rb_grn_context_from_ruby_object (VALUE object)
46
46
  {
47
- grn_ctx *context;
47
+ RbGrnContext *rb_grn_context;
48
48
 
49
49
  if (!RVAL2CBOOL(rb_obj_is_kind_of(object, cGrnContext))) {
50
50
  rb_raise(rb_eTypeError, "not a groonga context");
51
51
  }
52
52
 
53
- Data_Get_Struct(object, grn_ctx, context);
54
- if (!context)
53
+ Data_Get_Struct(object, RbGrnContext, rb_grn_context);
54
+ if (!rb_grn_context)
55
55
  rb_raise(rb_eGrnError, "groonga context is NULL");
56
- return context;
56
+ return &(rb_grn_context->context);
57
57
  }
58
58
 
59
59
  static void
60
60
  rb_grn_context_free (void *pointer)
61
61
  {
62
- grn_ctx *context = pointer;
62
+ RbGrnContext *rb_grn_context = pointer;
63
+ grn_ctx *context;
63
64
 
65
+ context = &(rb_grn_context->context);
64
66
  debug("context-free: %p\n", context);
65
67
  if (context->stat != GRN_CTX_FIN) {
66
68
  grn_obj *database;
@@ -73,7 +75,9 @@ rb_grn_context_free (void *pointer)
73
75
  grn_ctx_fin(context);
74
76
  }
75
77
  debug("context-free: %p: done\n", context);
76
- xfree(context);
78
+ xfree(rb_grn_context);
79
+
80
+ GRN_CTX_USER_DATA(context)->ptr = NULL;
77
81
  }
78
82
 
79
83
  static VALUE
@@ -226,6 +230,7 @@ rb_grn_context_s_set_default_options (VALUE self, VALUE options)
226
230
  static VALUE
227
231
  rb_grn_context_initialize (int argc, VALUE *argv, VALUE self)
228
232
  {
233
+ RbGrnContext *rb_grn_context;
229
234
  grn_ctx *context;
230
235
  int flags = 0;
231
236
  grn_rc rc;
@@ -245,11 +250,14 @@ rb_grn_context_initialize (int argc, VALUE *argv, VALUE self)
245
250
  "encoding", &rb_encoding,
246
251
  NULL);
247
252
 
248
- context = ALLOC(grn_ctx);
249
- DATA_PTR(self) = context;
253
+ rb_grn_context = ALLOC(RbGrnContext);
254
+ DATA_PTR(self) = rb_grn_context;
255
+ context = &(rb_grn_context->context);
250
256
  rc = grn_ctx_init(context, flags);
251
257
  rb_grn_context_check(context, self);
252
258
 
259
+ GRN_CTX_USER_DATA(context)->ptr = rb_grn_context;
260
+
253
261
  if (!NIL_P(rb_encoding)) {
254
262
  grn_encoding encoding;
255
263
 
@@ -432,23 +440,33 @@ rb_grn_context_array_reference (VALUE self, VALUE name_or_id)
432
440
  {
433
441
  grn_ctx *context;
434
442
  grn_obj *object;
443
+ const char *name;
444
+ unsigned int name_size;
445
+ grn_id id;
435
446
 
436
447
  context = SELF(self);
437
- if (RVAL2CBOOL(rb_obj_is_kind_of(name_or_id, rb_cString))) {
438
- const char *name;
439
- unsigned int name_size;
440
-
448
+ switch (TYPE(name_or_id)) {
449
+ case T_SYMBOL:
450
+ name = rb_id2name(SYM2ID(name_or_id));
451
+ name_size = strlen(name);
452
+ object = rb_grn_context_get_backward_compatibility(context,
453
+ name, name_size);
454
+ break;
455
+ case T_STRING:
441
456
  name = StringValuePtr(name_or_id);
442
457
  name_size = RSTRING_LEN(name_or_id);
443
458
  object = rb_grn_context_get_backward_compatibility(context,
444
459
  name, name_size);
445
- } else if (RVAL2CBOOL(rb_obj_is_kind_of(name_or_id, rb_cInteger))) {
446
- unsigned id;
460
+ break;
461
+ case T_FIXNUM:
447
462
  id = NUM2UINT(name_or_id);
448
463
  object = grn_ctx_at(context, id);
449
- } else {
450
- rb_raise(rb_eArgError, "should be string or unsigned integer: %s",
464
+ break;
465
+ default:
466
+ rb_raise(rb_eArgError,
467
+ "should be String, Symbol or unsigned integer: %s",
451
468
  rb_grn_inspect(name_or_id));
469
+ break;
452
470
  }
453
471
 
454
472
  return GRNOBJECT2RVAL(Qnil, context, object, RB_GRN_FALSE);
@@ -252,7 +252,8 @@ rb_grn_database_each (VALUE self)
252
252
 
253
253
  rb_grn_database_deconstruct(SELF(self), &database, &context,
254
254
  NULL, NULL, NULL, NULL);
255
- cursor = grn_table_cursor_open(context, database, NULL, 0, NULL, 0, 0);
255
+ cursor = grn_table_cursor_open(context, database, NULL, 0, NULL, 0,
256
+ 0, 0, GRN_CURSOR_ASCENDING);
256
257
  rb_cursor = GRNTABLECURSOR2RVAL(Qnil, context, cursor);
257
258
  rb_iv_set(self, "cursor", rb_cursor);
258
259
  while ((id = grn_table_cursor_next(context, cursor)) != GRN_ID_NIL) {
@@ -262,7 +263,7 @@ rb_grn_database_each (VALUE self)
262
263
  if (object)
263
264
  rb_yield(GRNOBJECT2RVAL(Qnil, context, object, RB_GRN_FALSE));
264
265
  }
265
- rb_grn_table_cursor_close(rb_cursor);
266
+ rb_grn_object_close(rb_cursor);
266
267
  rb_iv_set(self, "cursor", Qnil);
267
268
 
268
269
  return Qnil;
@@ -50,13 +50,19 @@ build_block (VALUE self)
50
50
  VALUE
51
51
  rb_grn_record_expression_builder_build (VALUE self)
52
52
  {
53
- return rb_iterate(build, self, build_block, self);
53
+ if (rb_block_given_p())
54
+ return rb_iterate(build, self, build_block, self);
55
+ else
56
+ return build(self);
54
57
  }
55
58
 
56
59
  VALUE
57
60
  rb_grn_column_expression_builder_build (VALUE self)
58
61
  {
59
- return rb_iterate(build, self, build_block, self);
62
+ if (rb_block_given_p())
63
+ return rb_iterate(build, self, build_block, self);
64
+ else
65
+ return build(self);
60
66
  }
61
67
 
62
68
  void
@@ -26,10 +26,10 @@ void
26
26
  rb_grn_expression_finalizer (grn_ctx *context, grn_obj *object,
27
27
  RbGrnExpression *rb_grn_expression)
28
28
  {
29
- if (!context)
30
- return;
29
+ if (context && rb_grn_expression->value)
30
+ grn_obj_close(context, rb_grn_expression->value);
31
31
 
32
- grn_obj_close(context, rb_grn_expression->value);
32
+ rb_grn_expression->value = NULL;
33
33
  }
34
34
 
35
35
  void
data/ext/rb-grn-hash.c CHANGED
@@ -80,8 +80,11 @@ VALUE rb_cGrnHash;
80
80
  * 省略した場合は文字列をキーとして使用する。この場合、
81
81
  * 4096バイトまで使用可能である。
82
82
  *
83
- * [+:value_size+]
84
- * 値の大きさを指定する。省略すると0になる。
83
+ * [+:value_type+]
84
+ * 値の型を指定する。省略すると値のための領域を確保しない。
85
+ * 値を保存したい場合は必ず指定すること。
86
+ *
87
+ * 参考: Groonga::Type.new
85
88
  *
86
89
  * [+:default_tokenizer+]
87
90
  * Groonga::IndexColumnで使用するトークナイザを指定する。
@@ -142,13 +145,13 @@ static VALUE
142
145
  rb_grn_hash_s_create (int argc, VALUE *argv, VALUE self)
143
146
  {
144
147
  grn_ctx *context;
145
- grn_obj *key_type = NULL, *table;
148
+ grn_obj *key_type = NULL, *value_type = NULL, *table;
146
149
  const char *name = NULL, *path = NULL;
147
- unsigned name_size = 0, value_size = 0;
150
+ unsigned name_size = 0;
148
151
  grn_obj_flags flags = GRN_TABLE_HASH_KEY;
149
152
  VALUE rb_table;
150
153
  VALUE options, rb_context, rb_name, rb_path, rb_persistent;
151
- VALUE rb_key_type, rb_value_size, rb_default_tokenizer;
154
+ VALUE rb_key_type, rb_value_type, rb_default_tokenizer;
152
155
  VALUE rb_sub_records;
153
156
 
154
157
  rb_scan_args(argc, argv, "01", &options);
@@ -159,7 +162,7 @@ rb_grn_hash_s_create (int argc, VALUE *argv, VALUE self)
159
162
  "path", &rb_path,
160
163
  "persistent", &rb_persistent,
161
164
  "key_type", &rb_key_type,
162
- "value_size", &rb_value_size,
165
+ "value_type", &rb_value_type,
163
166
  "default_tokenizer", &rb_default_tokenizer,
164
167
  "sub_records", &rb_sub_records,
165
168
  NULL);
@@ -186,14 +189,14 @@ rb_grn_hash_s_create (int argc, VALUE *argv, VALUE self)
186
189
  key_type = RVAL2GRNOBJECT(rb_key_type, &context);
187
190
  }
188
191
 
189
- if (!NIL_P(rb_value_size))
190
- value_size = NUM2UINT(rb_value_size);
192
+ if (!NIL_P(rb_value_type))
193
+ value_type = RVAL2GRNOBJECT(rb_value_type, &context);
191
194
 
192
- if (RVAL2CBOOL(rb_sub_records))
195
+ if (RVAL2CBOOL(rb_sub_records))
193
196
  flags |= GRN_OBJ_WITH_SUBREC;
194
197
 
195
198
  table = grn_table_create(context, name, name_size, path,
196
- flags, key_type, value_size);
199
+ flags, key_type, value_type);
197
200
  if (!table)
198
201
  rb_grn_context_check(context, rb_ary_new4(argc, argv));
199
202
  rb_table = rb_grn_object_alloc(self);
data/ext/rb-grn-object.c CHANGED
@@ -83,7 +83,6 @@ rb_grn_object_finalizer (grn_ctx *context, grn_obj *grn_object,
83
83
  grn_user_data *user_data)
84
84
  {
85
85
  RbGrnObject *rb_grn_object;
86
- rb_grn_boolean need_finalize = RB_GRN_TRUE;
87
86
 
88
87
  rb_grn_object = user_data->ptr;
89
88
 
@@ -95,19 +94,9 @@ rb_grn_object_finalizer (grn_ctx *context, grn_obj *grn_object,
95
94
  rb_grn_object->context, rb_grn_object->object,
96
95
  grn_object->header.type);
97
96
 
98
- if (rb_grn_object->context != context ||
99
- rb_grn_object->object != grn_object) {
100
- if (grn_object->header.type == GRN_DB)
101
- grn_ctx_use(context, NULL);
102
- need_finalize = RB_GRN_FALSE;
103
- }
104
-
105
97
  rb_grn_object->context = NULL;
106
98
  rb_grn_object->object = NULL;
107
99
 
108
- if (!need_finalize)
109
- return GRN_SUCCESS;
110
-
111
100
  switch (grn_object->header.type) {
112
101
  case GRN_DB:
113
102
  grn_ctx_use(context, NULL);
@@ -115,6 +104,9 @@ rb_grn_object_finalizer (grn_ctx *context, grn_obj *grn_object,
115
104
  case GRN_TYPE:
116
105
  case GRN_ACCESSOR:
117
106
  case GRN_PROC:
107
+ case GRN_CURSOR_TABLE_HASH_KEY:
108
+ case GRN_CURSOR_TABLE_PAT_KEY:
109
+ case GRN_CURSOR_TABLE_NO_KEY:
118
110
  break;
119
111
  case GRN_TABLE_HASH_KEY:
120
112
  case GRN_TABLE_PAT_KEY:
@@ -140,7 +132,7 @@ rb_grn_object_finalizer (grn_ctx *context, grn_obj *grn_object,
140
132
  break;
141
133
  default:
142
134
  rb_raise(rb_eTypeError,
143
- "unsupported groonga object type: 0x%x",
135
+ "unsupported groonga object type for finalizer: 0x%x",
144
136
  grn_object->header.type);
145
137
  break;
146
138
  }
@@ -161,8 +153,9 @@ rb_grn_object_free (RbGrnObject *rb_grn_object)
161
153
  rb_grn_object->context = NULL;
162
154
  rb_grn_object->object = NULL;
163
155
  debug("type: %x\n", grn_object->header.type);
164
- if (rb_grn_object->need_close)
156
+ if (rb_grn_object->need_close) {
165
157
  grn_obj_close(context, grn_object);
158
+ }
166
159
  }
167
160
  xfree(rb_grn_object);
168
161
  }
@@ -217,7 +210,7 @@ rb_grn_object_to_ruby_class (grn_obj *object)
217
210
  break;
218
211
  default:
219
212
  rb_raise(rb_eTypeError,
220
- "unsupported groonga object type: 0x%x",
213
+ "unsupported groonga object type for class detection: 0x%x",
221
214
  object->header.type);
222
215
  break;
223
216
  }
@@ -266,17 +259,20 @@ rb_grn_object_bind_common (VALUE klass, VALUE self, VALUE rb_context,
266
259
  rb_grn_object->need_close = RB_GRN_TRUE;
267
260
  switch (object->header.type) {
268
261
  case GRN_DB:
262
+ case GRN_CURSOR_TABLE_HASH_KEY:
263
+ case GRN_CURSOR_TABLE_PAT_KEY:
264
+ case GRN_CURSOR_TABLE_NO_KEY:
269
265
  case GRN_TABLE_HASH_KEY:
270
266
  case GRN_TABLE_PAT_KEY:
271
267
  case GRN_TABLE_NO_KEY:
272
268
  case GRN_COLUMN_FIX_SIZE:
273
269
  case GRN_COLUMN_VAR_SIZE:
274
270
  case GRN_COLUMN_INDEX:
271
+ case GRN_EXPR:
275
272
  grn_obj_user_data(context, object)->ptr = rb_grn_object;
276
273
  grn_obj_set_finalizer(context, object, rb_grn_object_finalizer);
277
274
  break;
278
275
  case GRN_PROC:
279
- case GRN_EXPR:
280
276
  case GRN_TYPE:
281
277
  rb_grn_object->need_close = RB_GRN_FALSE;
282
278
  break;
@@ -320,10 +316,10 @@ rb_grn_object_assign (VALUE klass, VALUE self, VALUE rb_context,
320
316
 
321
317
  if (klass == rb_cGrnDatabase ||
322
318
  (RVAL2CBOOL(rb_obj_is_kind_of(self, rb_cGrnType))) ||
323
- klass == rb_cGrnAccessor ||
324
319
  klass == rb_cGrnHashCursor ||
325
320
  klass == rb_cGrnPatriciaTrieCursor ||
326
321
  klass == rb_cGrnArrayCursor ||
322
+ klass == rb_cGrnAccessor ||
327
323
  klass == rb_cGrnProcedure ||
328
324
  klass == rb_cGrnVariable) {
329
325
  rb_grn_object = ALLOC(RbGrnObject);
@@ -359,7 +355,7 @@ rb_grn_object_assign (VALUE klass, VALUE self, VALUE rb_context,
359
355
  context, object);
360
356
  } else {
361
357
  rb_raise(rb_eTypeError,
362
- "unsupported groonga object type: 0x%x",
358
+ "unsupported groonga object type for assignment: 0x%x",
363
359
  object->header.type);
364
360
  }
365
361
 
@@ -424,7 +420,7 @@ rb_grn_object_close (VALUE self)
424
420
  * _object_が開放済みの場合は+true+を返し、そうでない場合は
425
421
  * +false+を返す。
426
422
  */
427
- static VALUE
423
+ VALUE
428
424
  rb_grn_object_closed_p (VALUE self)
429
425
  {
430
426
  grn_obj *object;
@@ -536,7 +532,11 @@ rb_grn_object_inspect_content_domain (VALUE inspected,
536
532
 
537
533
  domain_object = grn_ctx_at(context, domain);
538
534
  if (domain_object) {
539
- rb_grn_object_inspect_object(inspected, context, domain_object);
535
+ if (domain_object == object) {
536
+ rb_str_cat2(inspected, "self");
537
+ } else {
538
+ rb_grn_object_inspect_object(inspected, context, domain_object);
539
+ }
540
540
  } else {
541
541
  rb_str_concat(inspected, rb_obj_as_string(UINT2NUM(domain)));
542
542
  }
@@ -579,6 +579,112 @@ rb_grn_object_inspect_content_range (VALUE inspected,
579
579
  return inspected;
580
580
  }
581
581
 
582
+ static VALUE
583
+ rb_grn_object_inspect_content_flags (VALUE inspected,
584
+ grn_ctx *context, grn_obj *object)
585
+ {
586
+ grn_obj_flags flags;
587
+ VALUE inspected_flags;
588
+
589
+ rb_str_cat2(inspected, "flags: ");
590
+
591
+ flags = object->header.flags;
592
+
593
+ inspected_flags = rb_ary_new();
594
+
595
+ if (0) {
596
+ if (flags & GRN_OBJ_TABLE_HASH_KEY)
597
+ rb_ary_push(inspected_flags, rb_str_new2("TABLE_HASH_KEY"));
598
+ if (flags & GRN_OBJ_TABLE_PAT_KEY)
599
+ rb_ary_push(inspected_flags, rb_str_new2("TABLE_PAT_KEY"));
600
+ if (flags & GRN_OBJ_TABLE_NO_KEY)
601
+ rb_ary_push(inspected_flags, rb_str_new2("TABLE_NO_KEY"));
602
+ if (flags & GRN_OBJ_TABLE_ALIAS)
603
+ rb_ary_push(inspected_flags, rb_str_new2("TABLE_ALIAS"));
604
+ }
605
+
606
+ switch (object->header.type) {
607
+ case GRN_COLUMN_FIX_SIZE:
608
+ case GRN_COLUMN_VAR_SIZE:
609
+ case GRN_TYPE:
610
+ if (flags & GRN_OBJ_KEY_UINT)
611
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_UINT"));
612
+ if (flags & GRN_OBJ_KEY_INT)
613
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_INT"));
614
+ if (flags & GRN_OBJ_KEY_FLOAT)
615
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_FLOAT"));
616
+ break;
617
+ default:
618
+ break;
619
+ }
620
+
621
+ switch (object->header.type) {
622
+ case GRN_TABLE_HASH_KEY:
623
+ case GRN_TABLE_PAT_KEY:
624
+ if (flags & GRN_OBJ_KEY_WITH_SIS)
625
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_WITH_SIS"));
626
+ if (flags & GRN_OBJ_KEY_NORMALIZE)
627
+ rb_ary_push(inspected_flags, rb_str_new2("KEY_NORMALIZE"));
628
+ break;
629
+ default:
630
+ break;
631
+ }
632
+
633
+ if (0) {
634
+ if (flags & GRN_OBJ_COLUMN_SCALAR)
635
+ rb_ary_push(inspected_flags, rb_str_new2("COLUMN_SCALAR"));
636
+ if (flags & GRN_OBJ_COLUMN_VECTOR)
637
+ rb_ary_push(inspected_flags, rb_str_new2("COLUMN_VECTOR"));
638
+ if (flags & GRN_OBJ_COLUMN_INDEX)
639
+ rb_ary_push(inspected_flags, rb_str_new2("COLUMN_INDEX"));
640
+ }
641
+
642
+ switch (object->header.type) {
643
+ case GRN_COLUMN_FIX_SIZE:
644
+ case GRN_COLUMN_VAR_SIZE:
645
+ if (flags & GRN_OBJ_COMPRESS_ZLIB)
646
+ rb_ary_push(inspected_flags, rb_str_new2("COMPRESS_ZLIB"));
647
+ if (flags & GRN_OBJ_COMPRESS_LZO)
648
+ rb_ary_push(inspected_flags, rb_str_new2("COMPRESS_LZO"));
649
+ break;
650
+ default:
651
+ break;
652
+ }
653
+
654
+ if (flags & GRN_OBJ_WITH_SECTION)
655
+ rb_ary_push(inspected_flags, rb_str_new2("WITH_SECTION"));
656
+ if (flags & GRN_OBJ_WITH_WEIGHT)
657
+ rb_ary_push(inspected_flags, rb_str_new2("WITH_WEIGHT"));
658
+ if (flags & GRN_OBJ_WITH_POSITION)
659
+ rb_ary_push(inspected_flags, rb_str_new2("WITH_POSITION"));
660
+ if (flags & GRN_OBJ_WITH_BUFFER)
661
+ rb_ary_push(inspected_flags, rb_str_new2("WITH_BUFFER"));
662
+
663
+ if (flags & GRN_OBJ_UNIT_DOCUMENT_SECTION)
664
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_SECTION"));
665
+ if (flags & GRN_OBJ_UNIT_DOCUMENT_POSITION)
666
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_DOCUMENT_POSITION"));
667
+
668
+ if (flags & GRN_OBJ_UNIT_SECTION_POSITION)
669
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_SECTION_POSITION"));
670
+
671
+ if (flags & GRN_OBJ_UNIT_USERDEF_DOCUMENT)
672
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_DOCUMENT"));
673
+ if (flags & GRN_OBJ_UNIT_USERDEF_SECTION)
674
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_SECTION"));
675
+ if (flags & GRN_OBJ_UNIT_USERDEF_POSITION)
676
+ rb_ary_push(inspected_flags, rb_str_new2("UNIT_USERDEF_POSITION"));
677
+
678
+ if (flags & GRN_OBJ_WITH_SUBREC)
679
+ rb_ary_push(inspected_flags, rb_str_new2("WITH_SUBREC"));
680
+
681
+ rb_str_cat2(inspected, "<");
682
+ rb_str_concat(inspected, rb_ary_join(inspected_flags, rb_str_new2("|")));
683
+ rb_str_cat2(inspected, ">");
684
+
685
+ return inspected;
686
+ }
687
+
582
688
  VALUE
583
689
  rb_grn_object_inspect_object_content (VALUE inspected,
584
690
  grn_ctx *context, grn_obj *object)
@@ -592,6 +698,8 @@ rb_grn_object_inspect_object_content (VALUE inspected,
592
698
  rb_grn_object_inspect_content_domain(inspected, context, object);
593
699
  rb_str_cat2(inspected, ", ");
594
700
  rb_grn_object_inspect_content_range(inspected, context, object);
701
+ rb_str_cat2(inspected, ", ");
702
+ rb_grn_object_inspect_content_flags(inspected, context, object);
595
703
 
596
704
  return inspected;
597
705
  }
@@ -26,13 +26,14 @@ static VALUE
26
26
  rb_grn_patricia_trie_s_create (int argc, VALUE *argv, VALUE self)
27
27
  {
28
28
  grn_ctx *context;
29
- grn_obj *key_type = NULL, *table;
29
+ grn_obj *key_type = NULL, *value_type = NULL, *table;
30
30
  const char *name = NULL, *path = NULL;
31
- unsigned name_size = 0, value_size = 0;
31
+ unsigned name_size = 0;
32
32
  grn_obj_flags flags = GRN_TABLE_PAT_KEY;
33
33
  VALUE rb_table;
34
34
  VALUE options, rb_context, rb_name, rb_path, rb_persistent;
35
- VALUE rb_key_normalize, rb_key_with_sis, rb_key_type, rb_value_size;
35
+ VALUE rb_key_normalize, rb_key_with_sis, rb_key_type;
36
+ VALUE rb_value_type;
36
37
  VALUE rb_default_tokenizer, rb_sub_records;
37
38
 
38
39
  rb_scan_args(argc, argv, "01", &options);
@@ -45,7 +46,7 @@ rb_grn_patricia_trie_s_create (int argc, VALUE *argv, VALUE self)
45
46
  "key_normalize", &rb_key_normalize,
46
47
  "key_with_sis", &rb_key_with_sis,
47
48
  "key_type", &rb_key_type,
48
- "value_size", &rb_value_size,
49
+ "value_type", &rb_value_type,
49
50
  "default_tokenizer", &rb_default_tokenizer,
50
51
  "sub_records", &rb_sub_records,
51
52
  NULL);
@@ -78,14 +79,14 @@ rb_grn_patricia_trie_s_create (int argc, VALUE *argv, VALUE self)
78
79
  key_type = RVAL2GRNOBJECT(rb_key_type, &context);
79
80
  }
80
81
 
81
- if (!NIL_P(rb_value_size))
82
- value_size = NUM2UINT(rb_value_size);
82
+ if (!NIL_P(rb_value_type))
83
+ value_type = RVAL2GRNOBJECT(rb_value_type, &context);
83
84
 
84
85
  if (RVAL2CBOOL(rb_sub_records))
85
86
  flags |= GRN_OBJ_WITH_SUBREC;
86
87
 
87
88
  table = grn_table_create(context, name, name_size, path,
88
- flags, key_type, value_size);
89
+ flags, key_type, value_type);
89
90
  if (!table)
90
91
  rb_grn_context_check(context, rb_ary_new4(argc, argv));
91
92
  rb_table = rb_grn_object_alloc(self);
@@ -57,44 +57,6 @@ rb_grn_table_cursor_deconstruct (RbGrnTableCursor *rb_grn_table_cursor,
57
57
  range_id, range);
58
58
  }
59
59
 
60
- VALUE
61
- rb_grn_table_cursor_close (VALUE self)
62
- {
63
- RbGrnTableCursor *rb_grn_table_cursor;
64
- grn_table_cursor *cursor;
65
- grn_ctx *context;
66
-
67
- rb_grn_table_cursor = SELF(self);
68
- rb_grn_table_cursor_deconstruct(rb_grn_table_cursor, &cursor, &context,
69
- NULL, NULL, NULL, NULL);
70
-
71
- if (context && cursor) {
72
- RbGrnObject *rb_grn_object;
73
-
74
- rb_grn_object = RB_GRN_OBJECT(rb_grn_table_cursor);
75
- grn_obj_close(context, cursor);
76
- rb_grn_object->context = NULL;
77
- rb_grn_object->object = NULL;
78
- }
79
-
80
- return Qnil;
81
- }
82
-
83
- static VALUE
84
- rb_grn_table_cursor_closed_p (VALUE self)
85
- {
86
- grn_table_cursor *cursor;
87
- grn_ctx *context;
88
-
89
- rb_grn_table_cursor_deconstruct(SELF(self), &cursor, &context,
90
- NULL, NULL, NULL, NULL);
91
-
92
- if (context && cursor)
93
- return Qfalse;
94
- else
95
- return Qtrue;
96
- }
97
-
98
60
  static VALUE
99
61
  rb_grn_table_cursor_get_value (VALUE self)
100
62
  {
@@ -204,9 +166,9 @@ rb_grn_init_table_cursor (VALUE mGrn)
204
166
  rb_include_module(rb_cGrnTableCursor, rb_mEnumerable);
205
167
 
206
168
  rb_define_method(rb_cGrnTableCursor, "close",
207
- rb_grn_table_cursor_close, 0);
169
+ rb_grn_object_close, 0);
208
170
  rb_define_method(rb_cGrnTableCursor, "closed?",
209
- rb_grn_table_cursor_closed_p, 0);
171
+ rb_grn_object_closed_p, 0);
210
172
 
211
173
  rb_define_method(rb_cGrnTableCursor, "value",
212
174
  rb_grn_table_cursor_get_value, 0);