Kouhei Sutou
null+****@clear*****
Mon Jan 25 18:08:06 JST 2016
Kouhei Sutou 2016-01-25 18:08:06 +0900 (Mon, 25 Jan 2016) New Revision: bff3ddce9fb231b902b6db9edc257737d74e0b40 https://github.com/groonga/groonga/commit/bff3ddce9fb231b902b6db9edc257737d74e0b40 Message: mrb: add Groonga::IndexColumn#source_ids Modified files: lib/mrb/mrb_index_column.c Modified: lib/mrb/mrb_index_column.c (+30 -0) =================================================================== --- lib/mrb/mrb_index_column.c 2016-01-25 17:36:28 +0900 (59653eb) +++ lib/mrb/mrb_index_column.c 2016-01-25 18:08:06 +0900 (d31336f) @@ -22,6 +22,7 @@ #ifdef GRN_WITH_MRUBY #include <mruby.h> +#include <mruby/array.h> #include <mruby/class.h> #include <mruby/data.h> @@ -60,6 +61,31 @@ mrb_grn_index_column_get_lexicon(mrb_state *mrb, mrb_value self) } static mrb_value +mrb_grn_index_column_get_source_ids(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + grn_obj *index_column; + grn_obj source_ids; + unsigned int i, n_ids; + mrb_value mrb_source_ids; + + index_column = DATA_PTR(self); + GRN_RECORD_INIT(&source_ids, GRN_OBJ_VECTOR, GRN_DB_VOID); + grn_obj_get_info(ctx, index_column, GRN_INFO_SOURCE, &source_ids); + n_ids = GRN_BULK_VSIZE(&source_ids) / sizeof(grn_id); + + mrb_source_ids = mrb_ary_new_capa(mrb, n_ids); + for (i = 0; i < n_ids; i++) { + grn_id source_id = GRN_RECORD_VALUE_AT(&source_ids, i); + mrb_ary_push(mrb, mrb_source_ids, mrb_fixnum_value(source_id)); + } + + GRN_OBJ_FIN(ctx, &source_ids); + + return mrb_source_ids; +} + +static mrb_value mrb_grn_index_column_estimate_size_for_term_id(mrb_state *mrb, mrb_value self) { grn_ctx *ctx = (grn_ctx *)mrb->ud; @@ -156,6 +182,10 @@ grn_mrb_index_column_init(grn_ctx *ctx) mrb_grn_index_column_get_lexicon, MRB_ARGS_NONE()); + mrb_define_method(mrb, klass, "source_ids", + mrb_grn_index_column_get_source_ids, + MRB_ARGS_NONE()); + mrb_define_method(mrb, klass, "estimate_size_for_term_id", mrb_grn_index_column_estimate_size_for_term_id, MRB_ARGS_REQ(1)); -------------- next part -------------- HTML����������������������������...Download