Class: Groonga::IndexCursor

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

Instance Method Summary collapse

Methods inherited from Object

#==, #[], #[]=, #accessor?, #append, #builtin?, #close, #closed?, #column?, #dirty?, #domain, #function_procedure?, #id, #index_column?, #inspect, #key_accessor?, #last_modified, #name, #path, #persistent?, #prepend, #procedure?, #range, #reference_column?, #remove, #scorer_procedure?, #selector_only_procedure?, #selector_procedure?, #table?, #temporary?, #touch, #unlink, #window_function_procedure?

Instance Method Details

#eachObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
# File 'ext/groonga/rb-grn-index-cursor.c', line 100

static VALUE
rb_grn_index_cursor_each (int argc, VALUE *argv, VALUE self)
{
    grn_obj *cursor;
    grn_ctx *context;
    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);

    rb_grn_index_cursor_deconstruct(SELF(self), &cursor, &context,
                                    NULL, NULL, NULL, NULL);

    if (!context) {
        return Qnil;
    }

    if (!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,
                                context, cursor, rb_table, rb_lexicon);
        if (NIL_P(rb_posting)) {
            break;
        }
        rb_yield(rb_posting);
    }

    return Qnil;
}

#nextObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'ext/groonga/rb-grn-index-cursor.c', line 79

static VALUE
rb_grn_index_cursor_next (VALUE self)
{
    VALUE rb_posting = Qnil;
    grn_obj *cursor;
    grn_ctx *context;

    rb_grn_index_cursor_deconstruct(SELF(self), &cursor, &context,
                                    NULL, NULL, NULL, NULL);
    if (context && cursor) {
        VALUE rb_table;
        VALUE rb_lexicon;
        rb_table = rb_iv_get(self, "@table");
        rb_lexicon = rb_iv_get(self, "@lexicon");
        rb_posting = next_value(Qnil, context, cursor, rb_table, rb_lexicon);
    }

    return rb_posting;

}