rroonga 6.1.3 → 7.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a44ed5f4456e72a24167e4077f73fd94b242fe26
4
- data.tar.gz: d5f416c9f3e0751810397e114a5adbeb046f1626
3
+ metadata.gz: 1349d0af1d5185ee0bdd44af2b212dcf55a28e7a
4
+ data.tar.gz: cfa39b3cf8128946bb1d22d9ee39bc8c39c0860c
5
5
  SHA512:
6
- metadata.gz: ba25928a5113c6550972b540f269ca1ad2b5eac2ed0c72e156011332b641f722337895c2bb1dcd3ef5e73fef5c5fea8c3102f50b81dcabeb198e3c009facb370
7
- data.tar.gz: 8d869ffd01942c02055cf4b5f70b97717a818a467caf9ca590dd51f190dc380f71a844bd0bb8ff958060cf2945ad19cf1b7428ba74c0ed9b5690d13c9dd7c5f2
6
+ metadata.gz: b4a58abe995dd332f77d4e6e36ad837469e6a9653bb3be44ed2fe297c3cfdf5c061f7a76b90de2b045454e79215ac913eb32a9d29718bbafb38dfad65bc44fd8
7
+ data.tar.gz: 1a89ed23b0b257a227998309d9297ccfd10fe5f14feb7d77974ce21ea9d0e34d530c6ffbf35e4fb8ff21236b1f43f7dec7dbce76c1f7f3b9c62c403306ffb875
@@ -1,5 +1,33 @@
1
1
  # NEWS
2
2
 
3
+ ## 7.0.2: 2017-04-29 {#version-7-0-2}
4
+
5
+ ### Improvements
6
+
7
+ * Supported Groonga 7.0.2. Groonga 7.0.1 or older aren't supported.
8
+
9
+ * {Groonga::IndexColumn#open_cursor}: Supported opening a cursor by
10
+ token.
11
+
12
+ * {Groonga::IndexColumn#[]}: Supported a token.
13
+
14
+ * {Groonga::InvertedIndexCursor#closed?}: Added.
15
+
16
+ * {Groonga::TableKeySupport#key?}: Added.
17
+
18
+ * {Groonga::TableKeySupport#has_key?}: Deprecated. Use
19
+ {Groonga::TableKeySupport#key?} instead.
20
+
21
+ * {Groonga::DataColumn#apply_window_function}: Supported `:group_keys`.
22
+
23
+ * {Groonga::Column#weight_vector?}: Added.
24
+
25
+ * {Groonga::DataColumn#apply_expression}: Added.
26
+
27
+ * {Groonga::Column#data?}: Added.
28
+
29
+ * {Groonga::DefaultCache}: Added.
30
+
3
31
  ## 6.1.3: 2017-01-12 {#version-6-1-3}
4
32
 
5
33
  ### Improvements
@@ -609,12 +609,11 @@ rb_grn_column_truncate (VALUE self)
609
609
  }
610
610
 
611
611
  /*
612
- * _column_ が {Groonga::IndexColumn} の場合は +true+ を返し、
613
- * そうでない場合は +false+ を返す。
612
+ * @overload index?
613
+ * @return [Bool] `true` if the column is an index column
614
+ * ({Groonga::IndexColumn}), `false` otherwise.
614
615
  *
615
616
  * @since 1.0.5
616
- *
617
- * @overload index?
618
617
  */
619
618
  static VALUE
620
619
  rb_grn_column_index_p (VALUE self)
@@ -634,64 +633,83 @@ rb_grn_column_index_p (VALUE self)
634
633
  }
635
634
 
636
635
  /*
637
- * _column_ がベクターカラムの場合は +true+ を返し、
638
- * そうでない場合は +false+ を返す。
636
+ * @overload vector?
637
+ * @return [Bool] `true` if the column is a vector column,
638
+ * `false` otherwise.
639
639
  *
640
640
  * @since 1.0.5
641
- *
642
- * @overload vector?
643
641
  */
644
642
  static VALUE
645
643
  rb_grn_column_vector_p (VALUE self)
646
644
  {
647
645
  grn_ctx *context;
648
646
  grn_obj *column;
649
- grn_column_flags flags;
650
- grn_column_flags column_type;
651
647
 
652
648
  rb_grn_column_deconstruct(SELF(self), &column, &context,
653
649
  NULL, NULL,
654
650
  NULL, NULL, NULL);
655
651
 
656
- if (column->header.type != GRN_COLUMN_VAR_SIZE) {
657
- return Qfalse;
658
- }
652
+ return CBOOL2RVAL(grn_obj_is_vector_column(context, column));
653
+ }
659
654
 
660
- flags = grn_column_get_flags(context, column);
661
- column_type = (flags & GRN_OBJ_COLUMN_TYPE_MASK);
662
- return CBOOL2RVAL(column_type == GRN_OBJ_COLUMN_VECTOR);
655
+ /*
656
+ * @overload weight_vector?
657
+ * @return [Bool] `true` if the column is a weight vector column,
658
+ * `false` otherwise.
659
+ *
660
+ * @since 7.0.2
661
+ */
662
+ static VALUE
663
+ rb_grn_column_weight_vector_p (VALUE self)
664
+ {
665
+ grn_ctx *context;
666
+ grn_obj *column;
667
+
668
+ rb_grn_column_deconstruct(SELF(self), &column, &context,
669
+ NULL, NULL,
670
+ NULL, NULL, NULL);
671
+
672
+ return CBOOL2RVAL(grn_obj_is_weight_vector_column(context, column));
663
673
  }
664
674
 
665
675
  /*
666
- * _column_ がスカラーカラムの場合は +true+ を返し、
667
- * そうでない場合は +false+ を返す。
676
+ * @overload scalar?
677
+ * @return [Bool] `true` if the column is a scalar column,
678
+ * `false` otherwise.
668
679
  *
669
680
  * @since 1.0.5
670
- *
671
- * @overload scalar?
672
681
  */
673
682
  static VALUE
674
683
  rb_grn_column_scalar_p (VALUE self)
675
684
  {
676
685
  grn_ctx *context;
677
686
  grn_obj *column;
678
- grn_column_flags flags;
679
- grn_column_flags column_type;
680
687
 
681
688
  rb_grn_column_deconstruct(SELF(self), &column, &context,
682
689
  NULL, NULL,
683
690
  NULL, NULL, NULL);
684
691
 
685
- switch (column->header.type) {
686
- case GRN_COLUMN_FIX_SIZE:
687
- return Qtrue;
688
- case GRN_COLUMN_VAR_SIZE:
689
- flags = grn_column_get_flags(context, column);
690
- column_type = (flags & GRN_OBJ_COLUMN_TYPE_MASK);
691
- return CBOOL2RVAL(column_type == GRN_OBJ_COLUMN_SCALAR);
692
- default:
693
- return Qfalse;
694
- }
692
+ return CBOOL2RVAL(grn_obj_is_scalar_column(context, column));
693
+ }
694
+
695
+ /*
696
+ * @overload data?
697
+ * @return [Bool] `true` if the column is a data column (a scalar
698
+ * column or a vector column), `false` otherwise.
699
+ *
700
+ * @since 7.0.2
701
+ */
702
+ static VALUE
703
+ rb_grn_column_data_p (VALUE self)
704
+ {
705
+ grn_ctx *context;
706
+ grn_obj *column;
707
+
708
+ rb_grn_column_deconstruct(SELF(self), &column, &context,
709
+ NULL, NULL,
710
+ NULL, NULL, NULL);
711
+
712
+ return CBOOL2RVAL(grn_obj_is_data_column(context, column));
695
713
  }
696
714
 
697
715
  /*
@@ -842,7 +860,10 @@ rb_grn_init_column (VALUE mGrn)
842
860
  /* deprecated: backward compatibility */
843
861
  rb_define_alias(rb_cGrnColumn, "index_column?", "index?");
844
862
  rb_define_method(rb_cGrnColumn, "vector?", rb_grn_column_vector_p, 0);
863
+ rb_define_method(rb_cGrnColumn, "weight_vector?",
864
+ rb_grn_column_weight_vector_p, 0);
845
865
  rb_define_method(rb_cGrnColumn, "scalar?", rb_grn_column_scalar_p, 0);
866
+ rb_define_method(rb_cGrnColumn, "data?", rb_grn_column_data_p, 0);
846
867
 
847
868
  rb_define_method(rb_cGrnColumn, "with_weight?",
848
869
  rb_grn_column_with_weight_p, 0);
@@ -991,7 +991,7 @@ rb_grn_context_object_created (VALUE rb_context, VALUE rb_object)
991
991
  void
992
992
  rb_grn_init_context (VALUE mGrn)
993
993
  {
994
- cGrnContext = rb_define_class_under(mGrn, "Context", rb_cObject);
994
+ cGrnContext = rb_define_class_under(mGrn, "Context", rb_cData);
995
995
  rb_define_alloc_func(cGrnContext, rb_grn_context_alloc);
996
996
 
997
997
  rb_cv_set(cGrnContext, "@@default", Qnil);
@@ -70,6 +70,9 @@ VALUE rb_cGrnDataColumn;
70
70
  * @overload apply_window_function(options={}) {|record| }
71
71
  * @param options [::Hash] The name and value pairs.
72
72
  * @option options [::Array<String>] :sort_keys
73
+ * TODO: Description.
74
+ * @option options [::Array<String>] :group_keys
75
+ * TODO: Description.
73
76
  *
74
77
  * @yield [record]
75
78
  * It yields an object that builds expression. The block must
@@ -93,6 +96,7 @@ rb_grn_data_column_apply_window_function (int argc, VALUE *argv, VALUE self)
93
96
  grn_obj *window_function_call = NULL;
94
97
  VALUE rb_options;
95
98
  VALUE rb_sort_keys;
99
+ VALUE rb_group_keys;
96
100
  VALUE rb_builder;
97
101
  VALUE rb_window_function_call;
98
102
 
@@ -106,6 +110,7 @@ rb_grn_data_column_apply_window_function (int argc, VALUE *argv, VALUE self)
106
110
  rb_scan_args(argc, argv, "01", &rb_options);
107
111
  rb_grn_scan_options(rb_options,
108
112
  "sort_keys", &rb_sort_keys,
113
+ "group_keys", &rb_group_keys,
109
114
  NULL);
110
115
 
111
116
  if (!NIL_P(rb_sort_keys)) {
@@ -126,6 +131,24 @@ rb_grn_data_column_apply_window_function (int argc, VALUE *argv, VALUE self)
126
131
  rb_table);
127
132
  }
128
133
 
134
+ if (!NIL_P(rb_group_keys)) {
135
+ VALUE rb_table;
136
+
137
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(rb_group_keys, rb_cArray)))
138
+ rb_raise(rb_eArgError, ":group_keys should be an array of key: <%s>",
139
+ rb_grn_inspect(rb_group_keys));
140
+
141
+ definition.n_group_keys = RARRAY_LEN(rb_group_keys);
142
+ definition.group_keys = ALLOCA_N(grn_table_sort_key,
143
+ definition.n_group_keys);
144
+ rb_table = GRNOBJECT2RVAL(Qnil, context, table, GRN_FALSE);
145
+ rb_grn_table_sort_keys_fill(context,
146
+ definition.group_keys,
147
+ definition.n_group_keys,
148
+ rb_group_keys,
149
+ rb_table);
150
+ }
151
+
129
152
  rb_builder = rb_grn_record_expression_builder_new(rb_table, Qnil);
130
153
  rb_window_function_call =
131
154
  rb_grn_record_expression_builder_build(rb_builder);
@@ -144,6 +167,84 @@ rb_grn_data_column_apply_window_function (int argc, VALUE *argv, VALUE self)
144
167
  return self;
145
168
  }
146
169
 
170
+ /*
171
+ * Applies the expression to all records in the table of the
172
+ * column. Results are stored into the column.
173
+ *
174
+ * @example Compute column values from other column values.
175
+ *
176
+ * Groonga::Schema.define do |schema|
177
+ * schema.create_table("Comments") do |table|
178
+ * # The column that has base data to compute "plus1" column data.
179
+ * table.uint32("base")
180
+ * # The column for storing computed value with "base" column data.
181
+ * table.uint32("plus1")
182
+ * end
183
+ * end
184
+ * comments = Groonga["Comments"]
185
+ * plus1 = Groonga["Comments.plus1"]
186
+ *
187
+ * 3.times do |i|
188
+ * comments.add(:base => i)
189
+ * end
190
+ *
191
+ * plus1.apply_expression do |record|
192
+ * # Computes "base" column value plus one.
193
+ * record.base + 1
194
+ * end
195
+ *
196
+ * comments.each do |comment|
197
+ * p [comment.base, comment.plus1]
198
+ * # -> [0, 1]
199
+ * # -> [1, 2]
200
+ * # -> [2, 3]
201
+ * end
202
+ *
203
+ * @overload apply_expression {|record| }
204
+ *
205
+ * @yield [record]
206
+ * It yields an object that builds expression. The block must
207
+ * build an expression to be applied to all records.
208
+ * @yieldparam [Groonga::RecordExpressionBuilder] record
209
+ * The expression builder to create an expression.
210
+ * @yieldreturn [Groonga::ExpressionBuilder]
211
+ * It must be an expression.
212
+ *
213
+ * @since 7.0.2
214
+ */
215
+ static VALUE
216
+ rb_grn_data_column_apply_expression (VALUE self)
217
+ {
218
+ grn_rc rc;
219
+ grn_ctx *context;
220
+ grn_obj *column;
221
+ grn_obj *table;
222
+ VALUE rb_table;
223
+ grn_obj *expression = NULL;
224
+ VALUE rb_builder;
225
+ VALUE rb_expression;
226
+
227
+ rb_grn_column_deconstruct(SELF(self), &column, &context,
228
+ NULL, &table,
229
+ NULL, NULL, NULL);
230
+ rb_table = GRNOBJECT2RVAL(Qnil, context, table, GRN_FALSE);
231
+
232
+ rb_builder = rb_grn_record_expression_builder_new(rb_table, Qnil);
233
+ rb_expression = rb_grn_record_expression_builder_build(rb_builder);
234
+ rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_expression)),
235
+ &expression, NULL,
236
+ NULL, NULL, NULL, NULL);
237
+
238
+ rc = grn_table_apply_expr(context,
239
+ table,
240
+ column,
241
+ expression);
242
+ rb_grn_context_check(context, self);
243
+ rb_grn_rc_check(rc, self);
244
+
245
+ return self;
246
+ }
247
+
147
248
  void
148
249
  rb_grn_init_data_column (VALUE mGrn)
149
250
  {
@@ -151,6 +252,8 @@ rb_grn_init_data_column (VALUE mGrn)
151
252
 
152
253
  rb_define_method(rb_cGrnDataColumn, "apply_window_function",
153
254
  rb_grn_data_column_apply_window_function, -1);
255
+ rb_define_method(rb_cGrnDataColumn, "apply_expression",
256
+ rb_grn_data_column_apply_expression, 0);
154
257
 
155
258
  rb_grn_init_fix_size_column(mGrn);
156
259
  rb_grn_init_variable_size_column(mGrn);
@@ -0,0 +1,104 @@
1
+ /* -*- mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
+ /*
3
+ Copyright (C) 2017 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+ #include "rb-grn.h"
20
+
21
+ /*
22
+ * Document-module: Groonga::DefaultCache
23
+ *
24
+ * This module provides the default cache related features.
25
+ *
26
+ * @since 7.0.2
27
+ */
28
+
29
+ /*
30
+ * @overload base_path
31
+ * @return [String, nil] the default cache base path or `nil`.
32
+ *
33
+ * @since 7.0.2
34
+ */
35
+ static VALUE
36
+ rb_grn_default_cache_s_get_base_path (VALUE klass)
37
+ {
38
+ const char *base_path;
39
+
40
+ base_path = grn_get_default_cache_base_path();
41
+ if (base_path) {
42
+ return rb_str_new_cstr(base_path);
43
+ } else {
44
+ return Qnil;
45
+ }
46
+ }
47
+
48
+ /*
49
+ * @overload base_path=(base_path)
50
+ * @param base_path [String, nil] The new default cache base path.
51
+ * If you specify `String`, the default cache will be persistent.
52
+ * If you specify `nil`, the default cache will be just on memory.
53
+ * You need to call {.reopen} to apply this change.
54
+ * @return [String, nil] The `base_path` itself.
55
+ *
56
+ * @since 7.0.2
57
+ */
58
+ static VALUE
59
+ rb_grn_default_cache_s_set_base_path (VALUE klass, VALUE rb_base_path)
60
+ {
61
+ if (NIL_P(rb_base_path)) {
62
+ grn_set_default_cache_base_path(NULL);
63
+ } else {
64
+ const char *base_path;
65
+ base_path = StringValueCStr(rb_base_path);
66
+ grn_set_default_cache_base_path(base_path);
67
+ }
68
+
69
+ return rb_base_path;
70
+ }
71
+
72
+ /*
73
+ * @overload reopen
74
+ * Reopens the default cache.
75
+ *
76
+ * @return [void]
77
+ *
78
+ * @since 7.0.2
79
+ */
80
+ static VALUE
81
+ rb_grn_default_cache_s_reopen (VALUE klass)
82
+ {
83
+ grn_rc rc;
84
+
85
+ rc = grn_cache_default_reopen();
86
+ rb_grn_rc_check(rc, klass);
87
+
88
+ return Qnil;
89
+ }
90
+
91
+ void
92
+ rb_grn_init_default_cache (VALUE mGrn)
93
+ {
94
+ VALUE mGrnDefaultCache;
95
+
96
+ mGrnDefaultCache = rb_define_module_under(mGrn, "DefaultCache");
97
+
98
+ rb_define_singleton_method(mGrnDefaultCache, "base_path",
99
+ rb_grn_default_cache_s_get_base_path, 0);
100
+ rb_define_singleton_method(mGrnDefaultCache, "base_path=",
101
+ rb_grn_default_cache_s_set_base_path, 1);
102
+ rb_define_singleton_method(mGrnDefaultCache, "reopen",
103
+ rb_grn_default_cache_s_reopen, 0);
104
+ }
@@ -1,6 +1,6 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2009-2015 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2017 Kouhei Sutou <kou@clear-code.com>
4
4
  Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
5
5
 
6
6
  This library is free software; you can redistribute it and/or
@@ -54,11 +54,18 @@ void
54
54
  rb_grn_index_column_bind (RbGrnIndexColumn *rb_grn_index_column,
55
55
  grn_ctx *context, grn_obj *column)
56
56
  {
57
+ RbGrnColumn *rb_grn_column;
57
58
  RbGrnObject *rb_grn_object;
58
59
 
59
- rb_grn_column_bind(RB_GRN_COLUMN(rb_grn_index_column), context, column);
60
- rb_grn_object = RB_GRN_OBJECT(rb_grn_index_column);
60
+ rb_grn_column = RB_GRN_COLUMN(rb_grn_index_column);
61
+ rb_grn_column_bind(rb_grn_column, context, column);
62
+
63
+ grn_obj_reinit(context,
64
+ rb_grn_column->value,
65
+ GRN_DB_UINT32,
66
+ 0);
61
67
 
68
+ rb_grn_object = RB_GRN_OBJECT(rb_grn_index_column);
62
69
  rb_grn_index_column->old_value = grn_obj_open(context, GRN_BULK, 0,
63
70
  rb_grn_object->range_id);
64
71
  rb_grn_index_column->set_value =
@@ -191,6 +198,38 @@ rb_grn_index_column_inspect (VALUE self)
191
198
  return inspected;
192
199
  }
193
200
 
201
+ static VALUE
202
+ rb_grn_index_column_array_reference (VALUE self, VALUE rb_token)
203
+ {
204
+ grn_ctx *context = NULL;
205
+ grn_obj *column;
206
+ grn_obj *domain;
207
+ grn_id token_id;
208
+ grn_obj *value;
209
+ VALUE rb_value;
210
+
211
+ rb_grn_index_column_deconstruct(SELF(self),
212
+ &column,
213
+ &context,
214
+ NULL,
215
+ &domain,
216
+ &value,
217
+ NULL,
218
+ NULL,
219
+ NULL,
220
+ NULL,
221
+ NULL,
222
+ NULL);
223
+
224
+ token_id = RVAL2GRNID(rb_token, context, domain, self);
225
+ GRN_BULK_REWIND(value);
226
+ grn_obj_get_value(context, column, token_id, value);
227
+ rb_grn_context_check(context, self);
228
+ rb_value = GRNVALUE2RVAL(context, value, NULL, self);
229
+
230
+ return rb_value;
231
+ }
232
+
194
233
  /*
195
234
  * Adds a record that has @value@ content to inverted index for fast
196
235
  * fulltext serach. Normally, this method is not used
@@ -933,6 +972,12 @@ rb_grn_index_column_medium_p (VALUE self)
933
972
  return CBOOL2RVAL(flags & GRN_OBJ_INDEX_MEDIUM);
934
973
  }
935
974
 
975
+ static VALUE
976
+ call_close (VALUE object)
977
+ {
978
+ return rb_funcall(object, rb_intern("close"), 0);
979
+ }
980
+
936
981
  /*
937
982
  * Opens cursor to iterate posting in the index column.
938
983
  *
@@ -958,13 +1003,14 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
958
1003
  grn_ctx *context;
959
1004
  grn_obj *column;
960
1005
  grn_column_flags column_flags;
1006
+ grn_obj *domain_object;
961
1007
  grn_obj *range_object;
962
- grn_table_cursor *table_cursor;
1008
+ grn_table_cursor *table_cursor = NULL;
1009
+ grn_id token_id = GRN_ID_NIL;
963
1010
  grn_id rid_min = GRN_ID_NIL;
964
1011
  grn_id rid_max = GRN_ID_MAX;
965
1012
  int flags = 0;
966
- grn_obj *index_cursor;
967
- VALUE rb_table_cursor;
1013
+ VALUE rb_table_cursor_or_token;
968
1014
  VALUE options;
969
1015
  VALUE rb_with_section, rb_with_weight, rb_with_position;
970
1016
  VALUE rb_table;
@@ -972,21 +1018,28 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
972
1018
  VALUE rb_cursor;
973
1019
 
974
1020
  rb_grn_index_column_deconstruct(SELF(self), &column, &context,
975
- NULL, NULL,
1021
+ NULL, &domain_object,
976
1022
  NULL, NULL, NULL,
977
1023
  NULL, &range_object,
978
1024
  NULL, NULL);
979
1025
 
980
- rb_scan_args(argc, argv, "11", &rb_table_cursor, &options);
1026
+ rb_scan_args(argc, argv, "11", &rb_table_cursor_or_token, &options);
981
1027
  rb_grn_scan_options(options,
982
1028
  "with_section", &rb_with_section,
983
1029
  "with_weight", &rb_with_weight,
984
1030
  "with_position", &rb_with_position,
985
1031
  NULL);
986
1032
 
987
- table_cursor = RVAL2GRNTABLECURSOR(rb_table_cursor, NULL);
988
1033
  rb_table = GRNOBJECT2RVAL(Qnil, context, range_object, GRN_FALSE);
989
- rb_lexicon = rb_iv_get(rb_table_cursor, "@table");
1034
+ rb_lexicon = rb_funcall(self, rb_intern("table"), 0);
1035
+ if (CBOOL2RVAL(rb_obj_is_kind_of(rb_table_cursor_or_token,
1036
+ rb_cGrnTableCursor))) {
1037
+ VALUE rb_table_cursor = rb_table_cursor_or_token;
1038
+ table_cursor = RVAL2GRNTABLECURSOR(rb_table_cursor, NULL);
1039
+ } else {
1040
+ VALUE rb_token = rb_table_cursor_or_token;
1041
+ token_id = RVAL2GRNID(rb_token, context, domain_object, self);
1042
+ }
990
1043
 
991
1044
  column_flags = grn_column_get_flags(context, column);
992
1045
 
@@ -1008,13 +1061,34 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
1008
1061
  flags |= GRN_OBJ_WITH_POSITION;
1009
1062
  }
1010
1063
 
1011
- index_cursor = grn_index_cursor_open(context, table_cursor,
1012
- column, rid_min, rid_max, flags);
1013
-
1014
- rb_cursor = GRNINDEXCURSOR2RVAL(context, index_cursor, rb_table, rb_lexicon);
1064
+ if (table_cursor) {
1065
+ grn_obj *index_cursor;
1066
+ index_cursor = grn_index_cursor_open(context, table_cursor,
1067
+ column, rid_min, rid_max, flags);
1068
+ rb_cursor = GRNINDEXCURSOR2RVAL(context,
1069
+ index_cursor,
1070
+ rb_table,
1071
+ rb_lexicon);
1072
+ } else {
1073
+ grn_ii *ii = (grn_ii *)column;
1074
+ grn_ii_cursor *ii_cursor;
1075
+ ii_cursor = grn_ii_cursor_open(context,
1076
+ ii,
1077
+ token_id,
1078
+ rid_min,
1079
+ rid_max,
1080
+ grn_ii_get_n_elements(context, ii),
1081
+ flags);
1082
+ rb_cursor = rb_grn_inverted_index_cursor_to_ruby_object(context,
1083
+ ii_cursor,
1084
+ token_id,
1085
+ flags,
1086
+ rb_table,
1087
+ rb_lexicon);
1088
+ }
1015
1089
 
1016
1090
  if (rb_block_given_p())
1017
- return rb_ensure(rb_yield, rb_cursor, rb_grn_object_close, rb_cursor);
1091
+ return rb_ensure(rb_yield, rb_cursor, call_close, rb_cursor);
1018
1092
  else
1019
1093
  return rb_cursor;
1020
1094
  }
@@ -1337,6 +1411,10 @@ rb_grn_init_index_column (VALUE mGrn)
1337
1411
  rb_define_method(rb_cGrnIndexColumn, "inspect",
1338
1412
  rb_grn_index_column_inspect, 0);
1339
1413
 
1414
+ rb_define_method(rb_cGrnIndexColumn, "[]",
1415
+ rb_grn_index_column_array_reference, 1);
1416
+ rb_undef_method(rb_cGrnIndexColumn, "[]=");
1417
+
1340
1418
  rb_define_method(rb_cGrnIndexColumn, "add",
1341
1419
  rb_grn_index_column_add, -1);
1342
1420
  rb_define_method(rb_cGrnIndexColumn, "delete",