Class: Groonga::InvertedIndexCursor

Inherits:
Data
  • Object
show all
Includes:
Enumerable
Defined in:
ext/groonga/rb-grn-inverted-index-cursor.c

Instance Method Summary collapse

Instance Method Details

#closeObject



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'ext/groonga/rb-grn-inverted-index-cursor.c', line 211

static VALUE
rb_grn_inverted_index_cursor_close (VALUE self)
{
    RbGrnInvertedIndexCursor *rb_grn_cursor;

    TypedData_Get_Struct(self,
                         RbGrnInvertedIndexCursor,
                         &rb_grn_inverted_index_cursor_type,
                         rb_grn_cursor);
    if (!rb_grn_cursor->context) {
        rb_raise(rb_eGrnClosed,
                 "can't access already closed Groonga object: %" PRIsVALUE,
                 self);
    }

    if (rb_grn_cursor->cursor) {
        grn_ii_cursor_close(rb_grn_cursor->context,
                            rb_grn_cursor->cursor);
    }
    rb_grn_cursor->context = NULL;
    rb_grn_cursor->cursor = NULL;

    return Qnil;

}

#closed?Boolean

Returns:

  • (Boolean)


237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'ext/groonga/rb-grn-inverted-index-cursor.c', line 237

static VALUE
rb_grn_inverted_index_cursor_is_closed (VALUE self)
{
    RbGrnInvertedIndexCursor *rb_grn_cursor;

    TypedData_Get_Struct(self,
                         RbGrnInvertedIndexCursor,
                         &rb_grn_inverted_index_cursor_type,
                         rb_grn_cursor);
    if (rb_grn_cursor->context) {
        return Qfalse;
    } else {
        return Qtrue;
    }

}

#eachObject



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'ext/groonga/rb-grn-inverted-index-cursor.c', line 157

static VALUE
rb_grn_inverted_index_cursor_each (int argc, VALUE *argv, VALUE self)
{
    RbGrnInvertedIndexCursor *rb_grn_cursor;
    grn_bool reuse_posting_object;
    VALUE rb_options;
    VALUE rb_reuse_posting_object;
    VALUE rb_table;
    VALUE rb_lexicon;
    VALUE rb_posting = Qnil;

    RETURN_ENUMERATOR(self, argc, argv);

    rb_scan_args(argc, argv, "01", &rb_options);

    rb_grn_scan_options(rb_options,
                        "reuse_posting_object", &rb_reuse_posting_object,
                        NULL);

    TypedData_Get_Struct(self,
                         RbGrnInvertedIndexCursor,
                         &rb_grn_inverted_index_cursor_type,
                         rb_grn_cursor);
    if (!rb_grn_cursor->context) {
        rb_raise(rb_eGrnClosed,
                 "can't access already closed Groonga object: %" PRIsVALUE,
                 self);
    }

    if (!rb_grn_cursor->cursor) {
        return Qnil;
    }

    rb_table = rb_iv_get(self, "@table");
    rb_lexicon = rb_iv_get(self, "@lexicon");
    reuse_posting_object = RVAL2CBOOL(rb_reuse_posting_object);

    if (reuse_posting_object) {
        rb_posting = rb_grn_posting_new(NULL, GRN_ID_NIL, rb_table, rb_lexicon);
    }
    while (GRN_TRUE) {
        if (!reuse_posting_object) {
            rb_posting = Qnil;
        }
        rb_posting = next_value(rb_posting, rb_grn_cursor, rb_table, rb_lexicon);
        if (NIL_P(rb_posting)) {
            break;
        }
        rb_yield(rb_posting);
    }

    return Qnil;
}

#nextObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'ext/groonga/rb-grn-inverted-index-cursor.c', line 127

static VALUE
rb_grn_inverted_index_cursor_next (VALUE self)
{
    RbGrnInvertedIndexCursor *rb_grn_cursor;
    VALUE rb_table;
    VALUE rb_lexicon;
    VALUE rb_posting;

    TypedData_Get_Struct(self,
                         RbGrnInvertedIndexCursor,
                         &rb_grn_inverted_index_cursor_type,
                         rb_grn_cursor);
    if (!rb_grn_cursor->context) {
        rb_raise(rb_eGrnClosed,
                 "can't access already closed Groonga object: %" PRIsVALUE,
                 self);
    }

    if (!rb_grn_cursor->cursor) {
        return Qnil;
    }

    rb_table = rb_iv_get(self, "@table");
    rb_lexicon = rb_iv_get(self, "@lexicon");
    rb_posting = next_value(Qnil, rb_grn_cursor, rb_table, rb_lexicon);

    return rb_posting;

}