static void command_schema_output_normalizers(grn_ctx *ctx) { grn_obj normalizers; unsigned int i, n; GRN_PTR_INIT(&normalizers, GRN_OBJ_VECTOR, GRN_DB_OBJECT); grn_ctx_get_all_normalizers(ctx, &normalizers); grn_ctx_output_cstr(ctx, "normalizers"); n = GRN_BULK_VSIZE(&normalizers) / sizeof(grn_obj *); grn_ctx_output_map_open(ctx, "normalizers", n); for (i = 0; i < n; i++) { grn_obj *normalizer; normalizer = GRN_PTR_VALUE_AT(&normalizers, i); command_schema_output_name(ctx, normalizer); grn_ctx_output_map_open(ctx, "normalizer", 1); grn_ctx_output_cstr(ctx, "name"); command_schema_output_name(ctx, normalizer); grn_ctx_output_map_close(ctx); } grn_ctx_output_map_close(ctx); GRN_OBJ_FIN(ctx, &normalizers); }
static void command_schema_table_output_token_filters(grn_ctx *ctx, grn_obj *table) { grn_obj token_filters; int i, n; GRN_PTR_INIT(&token_filters, GRN_OBJ_VECTOR, GRN_DB_OBJECT); if (table->header.type != GRN_TABLE_NO_KEY) { grn_obj_get_info(ctx, table, GRN_INFO_TOKEN_FILTERS, &token_filters); } n = GRN_BULK_VSIZE(&token_filters) / sizeof(grn_obj *); grn_ctx_output_array_open(ctx, "token_filters", n); for (i = 0; i < n; i++) { grn_obj *token_filter; token_filter = GRN_PTR_VALUE_AT(&token_filters, i); grn_ctx_output_map_open(ctx, "token_filter", 1); grn_ctx_output_cstr(ctx, "name"); command_schema_output_name(ctx, token_filter); grn_ctx_output_map_close(ctx); } grn_ctx_output_array_close(ctx); GRN_OBJ_FIN(ctx, &token_filters); }
static void command_schema_output_token_filters(grn_ctx *ctx) { grn_obj token_filters; int i, n; GRN_PTR_INIT(&token_filters, GRN_OBJ_VECTOR, GRN_DB_OBJECT); grn_ctx_get_all_token_filters(ctx, &token_filters); grn_ctx_output_cstr(ctx, "token_filters"); n = GRN_BULK_VSIZE(&token_filters) / sizeof(grn_obj *); grn_ctx_output_map_open(ctx, "token_filters", n); for (i = 0; i < n; i++) { grn_obj *token_filter; token_filter = GRN_PTR_VALUE_AT(&token_filters, i); command_schema_output_name(ctx, token_filter); grn_ctx_output_map_open(ctx, "token_filter", 1); grn_ctx_output_cstr(ctx, "name"); command_schema_output_name(ctx, token_filter); grn_ctx_output_map_close(ctx); } grn_ctx_output_map_close(ctx); GRN_OBJ_FIN(ctx, &token_filters); }
/* * Extracts keywords from _expression_. The keywords order isn't * guaranteed. * * @example * expression.parse("Ruby OR Groonga") * expression.keywords #=> ["Groonga", "Ruby"] * * @overload keywords * @return [::Array<String>] the extracted keywords * * @since 4.0.6 */ static VALUE rb_grn_expression_get_keywords (VALUE self) { grn_ctx *context = NULL; grn_obj *expression; grn_obj keywords; VALUE rb_keywords = rb_ary_new(); rb_grn_expression_deconstruct(SELF(self), &expression, &context, NULL, NULL, NULL, NULL, NULL); GRN_PTR_INIT(&keywords, GRN_OBJ_VECTOR, GRN_ID_NIL); grn_expr_get_keywords(context, expression, &keywords); { int i, n_keywords; n_keywords = GRN_BULK_VSIZE(&keywords) / sizeof(grn_obj *); for (i = 0; i < n_keywords; i++) { grn_obj *keyword = GRN_PTR_VALUE_AT(&keywords, i); rb_ary_push(rb_keywords, GRNBULK2RVAL(context, keyword, NULL, self)); } } GRN_OBJ_FIN(context, &keywords); return rb_keywords; }
static grn_obj * func_highlight_html(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) { grn_obj *highlighted = NULL; grn_obj *string; grn_obj *lexicon = NULL; grn_obj *expression = NULL; grn_highlighter *highlighter; grn_obj *highlighter_ptr; if (!(1 <= nargs && nargs <= 2)) { GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, "highlight_html(): wrong number of arguments (%d for 1..2)", nargs); highlighted = grn_plugin_proc_alloc(ctx, user_data, GRN_DB_VOID, 0); return highlighted; } string = args[0]; if (nargs == 2) { lexicon = args[1]; } grn_proc_get_info(ctx, user_data, NULL, NULL, &expression); highlighter_ptr = grn_expr_get_var(ctx, expression, GRN_FUNC_HIGHLIGHT_HTML_CACHE_NAME, strlen(GRN_FUNC_HIGHLIGHT_HTML_CACHE_NAME)); if (highlighter_ptr) { highlighter = (grn_highlighter *)GRN_PTR_VALUE(highlighter_ptr); } else { highlighter_ptr = grn_expr_get_or_add_var(ctx, expression, GRN_FUNC_HIGHLIGHT_HTML_CACHE_NAME, strlen(GRN_FUNC_HIGHLIGHT_HTML_CACHE_NAME)); GRN_OBJ_FIN(ctx, highlighter_ptr); GRN_PTR_INIT(highlighter_ptr, GRN_OBJ_OWN, GRN_DB_OBJECT); highlighter = func_highlight_html_create_highlighter(ctx, expression); grn_highlighter_set_lexicon(ctx, highlighter, lexicon); GRN_PTR_SET(ctx, highlighter_ptr, highlighter); } highlighted = grn_plugin_proc_alloc(ctx, user_data, GRN_DB_TEXT, 0); grn_highlighter_highlight(ctx, highlighter, GRN_TEXT_VALUE(string), GRN_TEXT_LEN(string), highlighted); return highlighted; }
static grn_obj * proc_column_create(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) { uint32_t nvars; grn_obj *buf = args[0]; grn_expr_var *vars; grn_proc_get_info(ctx, user_data, &vars, &nvars, NULL); if (nvars == 6) { grn_obj_flags flags = grn_atoi(GRN_TEXT_VALUE(&vars[2].value), GRN_BULK_CURR(&vars[2].value), NULL); grn_obj *column, *table = grn_ctx_get(ctx, GRN_TEXT_VALUE(&vars[0].value), GRN_TEXT_LEN(&vars[0].value)); grn_obj *type = grn_ctx_get(ctx, GRN_TEXT_VALUE(&vars[3].value), GRN_TEXT_LEN(&vars[3].value)); if (GRN_TEXT_LEN(&vars[1].value)) { flags |= GRN_OBJ_PERSISTENT; } column = grn_column_create(ctx, table, GRN_TEXT_VALUE(&vars[1].value), GRN_TEXT_LEN(&vars[1].value), NULL, flags, type); if (column) { if (GRN_TEXT_LEN(&vars[4].value)) { grn_obj sources, source_ids, **p, **pe; GRN_PTR_INIT(&sources, GRN_OBJ_VECTOR, GRN_ID_NIL); GRN_UINT32_INIT(&source_ids, GRN_OBJ_VECTOR); grn_obj_columns(ctx, type, GRN_TEXT_VALUE(&vars[4].value), GRN_TEXT_LEN(&vars[4].value), &sources); p = (grn_obj **)GRN_BULK_HEAD(&sources); pe = (grn_obj **)GRN_BULK_CURR(&sources); while (p < pe) { grn_id source_id = grn_obj_id(ctx, *p++); if (source_id) { GRN_UINT32_PUT(ctx, &source_ids, source_id); } } if (GRN_BULK_VSIZE(&source_ids)) { grn_obj_set_info(ctx, column, GRN_INFO_SOURCE, &source_ids); } GRN_OBJ_FIN(ctx, &source_ids); GRN_OBJ_FIN(ctx, &sources); } grn_obj_unlink(ctx, column); } GRN_TEXT_PUTS(ctx, buf, ctx->rc ? "false" : "true"); } return buf; }
static grn_obj * func_highlight_html(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) { grn_obj *highlighted = NULL; #define N_REQUIRED_ARGS 1 if (nargs == N_REQUIRED_ARGS) { grn_obj *string = args[0]; grn_obj *expression = NULL; grn_obj *keywords; grn_obj *keywords_ptr; grn_bool use_html_escape = GRN_TRUE; grn_proc_get_info(ctx, user_data, NULL, NULL, &expression); keywords_ptr = grn_expr_get_var(ctx, expression, GRN_FUNC_HIGHLIGHT_HTML_CACHE_NAME, strlen(GRN_FUNC_HIGHLIGHT_HTML_CACHE_NAME)); if (keywords_ptr) { keywords = GRN_PTR_VALUE(keywords_ptr); } else { keywords_ptr = grn_expr_get_or_add_var(ctx, expression, GRN_FUNC_HIGHLIGHT_HTML_CACHE_NAME, strlen(GRN_FUNC_HIGHLIGHT_HTML_CACHE_NAME)); GRN_OBJ_FIN(ctx, keywords_ptr); GRN_PTR_INIT(keywords_ptr, GRN_OBJ_OWN, GRN_DB_OBJECT); keywords = func_highlight_html_create_keywords_table(ctx, expression); GRN_PTR_SET(ctx, keywords_ptr, keywords); } highlighted = highlight_keywords(ctx, user_data, string, keywords, use_html_escape, "<span class=\"keyword\">", strlen("<span class=\"keyword\">"), "</span>", strlen("</span>")); } #undef N_REQUIRED_ARGS if (!highlighted) { highlighted = grn_plugin_proc_alloc(ctx, user_data, GRN_DB_VOID, 0); } return highlighted; }
void cut_setup(void) { cut_remove_path(tmp_directory, NULL); g_mkdir_with_parents(tmp_directory, 0700); path = g_build_filename(tmp_directory, "text-table-select", NULL); grn_ctx_init(&context, 0); database = grn_db_create(&context, path, NULL); cond = NULL; expr = NULL; res = NULL; GRN_TEXT_INIT(&text_buf, 0); GRN_UINT32_INIT(&int_buf, 0); GRN_PTR_INIT(&ptr_buf, 0, GRN_ID_NIL); }
static grn_obj * func_highlight_html_create_keywords_table(grn_ctx *ctx, grn_obj *expression) { grn_obj *keywords; grn_obj *condition_ptr = NULL; grn_obj *condition = NULL; keywords = grn_table_create(ctx, NULL, 0, NULL, GRN_OBJ_TABLE_PAT_KEY, grn_ctx_at(ctx, GRN_DB_SHORT_TEXT), NULL); { grn_obj *normalizer; normalizer = grn_ctx_get(ctx, "NormalizerAuto", -1); grn_obj_set_info(ctx, keywords, GRN_INFO_NORMALIZER, normalizer); grn_obj_unlink(ctx, normalizer); } condition_ptr = grn_expr_get_var(ctx, expression, GRN_SELECT_INTERNAL_VAR_CONDITION, strlen(GRN_SELECT_INTERNAL_VAR_CONDITION)); if (condition_ptr) { condition = GRN_PTR_VALUE(condition_ptr); } if (condition) { size_t i, n_keywords; grn_obj current_keywords; GRN_PTR_INIT(¤t_keywords, GRN_OBJ_VECTOR, GRN_ID_NIL); grn_expr_get_keywords(ctx, condition, ¤t_keywords); n_keywords = GRN_BULK_VSIZE(¤t_keywords) / sizeof(grn_obj *); for (i = 0; i < n_keywords; i++) { grn_obj *keyword; keyword = GRN_PTR_VALUE_AT(¤t_keywords, i); grn_table_add(ctx, keywords, GRN_TEXT_VALUE(keyword), GRN_TEXT_LEN(keyword), NULL); } grn_obj_unlink(ctx, ¤t_keywords); } return keywords; }
static void grn_loader_init(grn_loader *loader) { GRN_TEXT_INIT(&loader->values, 0); GRN_UINT32_INIT(&loader->level, GRN_OBJ_VECTOR); GRN_PTR_INIT(&loader->columns, GRN_OBJ_VECTOR, GRN_ID_NIL); loader->id_offset = -1; loader->key_offset = -1; loader->table = NULL; loader->last = NULL; loader->ifexists = NULL; loader->each = NULL; loader->values_size = 0; loader->nrecords = 0; loader->stat = GRN_LOADER_BEGIN; loader->columns_status = GRN_LOADER_COLUMNS_UNSET; loader->rc = GRN_SUCCESS; loader->errbuf[0] = '\0'; }
static void command_schema_output_types(grn_ctx *ctx) { grn_obj types; unsigned int i, n; GRN_PTR_INIT(&types, GRN_OBJ_VECTOR, GRN_DB_OBJECT); grn_ctx_get_all_types(ctx, &types); grn_ctx_output_cstr(ctx, "types"); n = GRN_BULK_VSIZE(&types) / sizeof(grn_obj *); grn_ctx_output_map_open(ctx, "types", n); for (i = 0; i < n; i++) { grn_obj *type; type = GRN_PTR_VALUE_AT(&types, i); command_schema_output_name(ctx, type); grn_ctx_output_map_open(ctx, "type", 4); grn_ctx_output_cstr(ctx, "name"); command_schema_output_name(ctx, type); grn_ctx_output_cstr(ctx, "size"); grn_ctx_output_int64(ctx, grn_type_size(ctx, type)); grn_ctx_output_cstr(ctx, "can_be_key_type"); grn_ctx_output_bool(ctx, grn_type_size(ctx, type) <= GRN_TABLE_MAX_KEY_SIZE); grn_ctx_output_cstr(ctx, "can_be_value_type"); grn_ctx_output_bool(ctx, !(type->header.flags & GRN_OBJ_KEY_VAR_SIZE)); grn_ctx_output_map_close(ctx); } grn_ctx_output_map_close(ctx); GRN_OBJ_FIN(ctx, &types); }
static mrb_value mrb_grn_expression_set_condition(mrb_state *mrb, mrb_value self) { grn_ctx *ctx = (grn_ctx *)mrb->ud; grn_obj *expr; mrb_value mrb_condition; grn_obj *condition_ptr; mrb_get_args(mrb, "o", &mrb_condition); expr = DATA_PTR(self); condition_ptr = grn_expr_get_or_add_var(ctx, expr, GRN_SELECT_INTERNAL_VAR_CONDITION, GRN_SELECT_INTERNAL_VAR_CONDITION_LEN); GRN_OBJ_FIN(ctx, condition_ptr); GRN_PTR_INIT(condition_ptr, 0, GRN_DB_OBJECT); GRN_PTR_SET(ctx, condition_ptr, GRN_MRB_DATA_PTR(mrb_condition)); return mrb_nil_value(); }
/* * Returns the token filters that are used by {Groonga::IndexColumn}. * * @overload token_filters * @return [::Array<Groonga::Procedure>] */ static VALUE rb_grn_table_key_support_get_token_filters (VALUE self) { grn_ctx *context = NULL; grn_obj *table; grn_obj token_filters; VALUE rb_token_filters; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, NULL, NULL, NULL, NULL, NULL, NULL, NULL); GRN_PTR_INIT(&token_filters, GRN_VECTOR, GRN_ID_NIL); grn_obj_get_info(context, table, GRN_INFO_TOKEN_FILTERS, &token_filters); rb_token_filters = GRNPVECTOR2RVAL(context, &token_filters); rb_grn_context_check(context, self); return rb_token_filters; }
/* * _expression_ で使用可能な変数を作成する。 * * @overload define_variable(options={}) * @param [::Hash] options The name and value * pairs. Omitted names are initialized as the default value. * @option options :name [String] (nil) * 変数の名前。省略した場合は名前を付けない。 * @option options :domain [Groonga::Table] (nil) * テーブルを指定すると、そのテーブル用のレコードとして初期化する。 * @option options :reference [Bool] (nil) * Initializes this variable as reference hold variable if * @:reference@ is true. Reference hold variable is GRN_PTR type * in groonga. You can't use @:reference@ with @:domain@. * @return [Groonga::Variable] * */ static VALUE rb_grn_expression_define_variable (int argc, VALUE *argv, VALUE self) { grn_ctx *context = NULL; grn_obj *expression, *variable; char *name = NULL; unsigned name_size = 0; VALUE options, rb_name, rb_domain, rb_variable, rb_reference; rb_scan_args(argc, argv, "01", &options); rb_grn_expression_deconstruct(SELF(self), &expression, &context, NULL, NULL, NULL, NULL, NULL); rb_grn_scan_options(options, "name", &rb_name, "domain", &rb_domain, "reference", &rb_reference, NULL); if (!NIL_P(rb_name)) { name = StringValuePtr(rb_name); name_size = RSTRING_LEN(rb_name); } variable = grn_expr_add_var(context, expression, name, name_size); rb_variable = GRNVARIABLE2RVAL(context, variable); if (RVAL2CBOOL(rb_obj_is_kind_of(rb_domain, rb_cGrnTable))) { grn_id domain_id; domain_id = NUM2UINT(rb_funcall(rb_domain, rb_intern("id"), 0)); GRN_RECORD_INIT(variable, 0, domain_id); } else if (!NIL_P(rb_reference) && RVAL2CBOOL(rb_reference)) { GRN_PTR_INIT(variable, 0, GRN_DB_OBJECT); } return rb_variable; }
/* * Sets token filters that used in {Groonga::IndexColumn}. * * @example * # Use "TokenFilterStem" and "TokenfilterStopWord" * table.token_filters = ["TokenFilterStem", "TokenFilterStopWord"] * * @overload token_filters=(token_filters) * @param token_filters [::Array<String>] Token filter names. */ static VALUE rb_grn_table_key_support_set_token_filters (VALUE self, VALUE rb_token_filters) { grn_ctx *context; grn_obj *table; grn_obj token_filters; grn_rc rc; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, NULL, NULL, NULL, NULL, NULL, NULL, NULL); GRN_PTR_INIT(&token_filters, GRN_OBJ_VECTOR, GRN_ID_NIL); RVAL2GRNPVECTOR(rb_token_filters, context, &token_filters); rc = grn_obj_set_info(context, table, GRN_INFO_TOKEN_FILTERS, &token_filters); grn_obj_unlink(context, &token_filters); rb_grn_context_check(context, self); rb_grn_rc_check(rc, self); return Qnil; }
static void command_schema_table_command_collect_arguments(grn_ctx *ctx, grn_obj *table, grn_obj *arguments) { #define ADD(name_, value_) \ grn_vector_add_element(ctx, arguments, \ name_, strlen(name_), \ 0, GRN_DB_TEXT); \ grn_vector_add_element(ctx, arguments, \ value_, strlen(value_), \ 0, GRN_DB_TEXT) #define ADD_OBJECT_NAME(name_, object_) do { \ char object_name[GRN_TABLE_MAX_KEY_SIZE]; \ unsigned int object_name_size; \ object_name_size = grn_obj_name(ctx, object_, \ object_name, \ GRN_TABLE_MAX_KEY_SIZE); \ object_name[object_name_size] = '\0'; \ ADD(name_, object_name); \ } while (GRN_FALSE) ADD_OBJECT_NAME("name", table); { grn_obj flags; grn_table_flags table_flags; grn_table_flags ignored_flags = GRN_OBJ_KEY_NORMALIZE | GRN_OBJ_PERSISTENT; GRN_TEXT_INIT(&flags, 0); grn_table_get_info(ctx, table, &table_flags, NULL, NULL, NULL, NULL); grn_dump_table_create_flags(ctx, table_flags & ~ignored_flags, &flags); GRN_TEXT_PUTC(ctx, &flags, '\0'); ADD("flags", GRN_TEXT_VALUE(&flags)); GRN_OBJ_FIN(ctx, &flags); } { grn_obj *key_type = NULL; if (table->header.type != GRN_TABLE_NO_KEY && table->header.domain != GRN_ID_NIL) { key_type = grn_ctx_at(ctx, table->header.domain); } if (key_type) { ADD_OBJECT_NAME("key_type", key_type); } } { grn_obj *value_type = NULL; grn_id range = GRN_ID_NIL; if (table->header.type != GRN_TABLE_DAT_KEY) { range = grn_obj_get_range(ctx, table); } if (range != GRN_ID_NIL) { value_type = grn_ctx_at(ctx, range); } if (value_type) { ADD_OBJECT_NAME("value_type", value_type); } } { grn_obj *tokenizer; tokenizer = grn_obj_get_info(ctx, table, GRN_INFO_DEFAULT_TOKENIZER, NULL); if (tokenizer) { ADD_OBJECT_NAME("default_tokenizer", tokenizer); } } { grn_obj *normalizer; normalizer = grn_obj_get_info(ctx, table, GRN_INFO_NORMALIZER, NULL); if (!normalizer && (table->header.flags & GRN_OBJ_KEY_NORMALIZE)) { normalizer = grn_ctx_get(ctx, "NormalizerAuto", -1); } if (normalizer) { ADD_OBJECT_NAME("normalizer", normalizer); } } if (table->header.type != GRN_TABLE_NO_KEY) { grn_obj token_filters; int n; GRN_PTR_INIT(&token_filters, GRN_OBJ_VECTOR, GRN_DB_OBJECT); grn_obj_get_info(ctx, table, GRN_INFO_TOKEN_FILTERS, &token_filters); n = GRN_BULK_VSIZE(&token_filters) / sizeof(grn_obj *); if (n > 0) { grn_obj token_filter_names; int i; GRN_TEXT_INIT(&token_filter_names, 0); for (i = 0; i < n; i++) { grn_obj *token_filter; char name[GRN_TABLE_MAX_KEY_SIZE]; int name_size; token_filter = GRN_PTR_VALUE_AT(&token_filters, i); name_size = grn_obj_name(ctx, token_filter, name, GRN_TABLE_MAX_KEY_SIZE); if (i > 0) { GRN_TEXT_PUTC(ctx, &token_filter_names, ','); } GRN_TEXT_PUT(ctx, &token_filter_names, name, name_size); } GRN_TEXT_PUTC(ctx, &token_filter_names, '\0'); ADD("token_filters", GRN_TEXT_VALUE(&token_filter_names)); GRN_OBJ_FIN(ctx, &token_filter_names); } GRN_OBJ_FIN(ctx, &token_filters); } #undef ADD_OBJECT_NAME #undef ADD }
static grn_obj * func_snippet_html(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) { grn_obj *snippets = NULL; /* TODO: support parameters */ if (nargs == 1) { grn_obj *text = args[0]; grn_obj *expression = NULL; grn_obj *condition_ptr = NULL; grn_obj *condition = NULL; grn_obj *snip = NULL; int flags = GRN_SNIP_SKIP_LEADING_SPACES; unsigned int width = 200; unsigned int max_n_results = 3; const char *open_tag = "<span class=\"keyword\">"; const char *close_tag = "</span>"; grn_snip_mapping *mapping = GRN_SNIP_MAPPING_HTML_ESCAPE; grn_proc_get_info(ctx, user_data, NULL, NULL, &expression); condition_ptr = grn_expr_get_var(ctx, expression, GRN_SELECT_INTERNAL_VAR_CONDITION, strlen(GRN_SELECT_INTERNAL_VAR_CONDITION)); if (condition_ptr) { condition = GRN_PTR_VALUE(condition_ptr); } if (condition) { grn_obj *snip_ptr; snip_ptr = grn_expr_get_var(ctx, expression, GRN_FUNC_SNIPPET_HTML_CACHE_NAME, strlen(GRN_FUNC_SNIPPET_HTML_CACHE_NAME)); if (snip_ptr) { snip = GRN_PTR_VALUE(snip_ptr); } else { snip_ptr = grn_expr_get_or_add_var(ctx, expression, GRN_FUNC_SNIPPET_HTML_CACHE_NAME, strlen(GRN_FUNC_SNIPPET_HTML_CACHE_NAME)); GRN_OBJ_FIN(ctx, snip_ptr); GRN_PTR_INIT(snip_ptr, GRN_OBJ_OWN, GRN_DB_OBJECT); snip = grn_snip_open(ctx, flags, width, max_n_results, open_tag, strlen(open_tag), close_tag, strlen(close_tag), mapping); if (snip) { grn_snip_set_normalizer(ctx, snip, GRN_NORMALIZER_AUTO); grn_expr_snip_add_conditions(ctx, condition, snip, 0, NULL, NULL, NULL, NULL); GRN_PTR_SET(ctx, snip_ptr, snip); } } } if (snip) { snippets = snippet_exec(ctx, snip, text, user_data, NULL, 0, NULL, 0); } } if (!snippets) { snippets = grn_plugin_proc_alloc(ctx, user_data, GRN_DB_VOID, 0); } return snippets; }
static VALUE rb_grn_table_key_support_inspect_content (VALUE self, VALUE inspected) { RbGrnTableKeySupport *rb_grn_table; grn_ctx *context = NULL; grn_obj *table; rb_grn_table = SELF(self); if (!rb_grn_table) return inspected; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (!table) return inspected; if (!context) return inspected; { grn_obj value; grn_encoding encoding; rb_str_cat2(inspected, ", "); rb_str_cat2(inspected, "encoding: <"); GRN_OBJ_INIT(&value, GRN_BULK, 0, GRN_ID_NIL); grn_obj_get_info(context, table, GRN_INFO_ENCODING, &value); encoding = *((grn_encoding *)GRN_BULK_HEAD(&value)); grn_obj_unlink(context, &value); if (context->rc == GRN_SUCCESS) { rb_str_concat(inspected, rb_inspect(GRNENCODING2RVAL(encoding))); } else { rb_str_cat2(inspected, "invalid"); } rb_str_cat2(inspected, ">"); } { grn_obj *default_tokenizer; rb_str_cat2(inspected, ", "); rb_str_cat2(inspected, "default_tokenizer: "); default_tokenizer = grn_obj_get_info(context, table, GRN_INFO_DEFAULT_TOKENIZER, NULL); if (default_tokenizer) { rb_grn_object_inspect_object_content_name(inspected, context, default_tokenizer); } else { rb_str_cat2(inspected, "(nil)"); } } { int i, n; grn_obj token_filters; rb_str_cat2(inspected, ", "); rb_str_cat2(inspected, "token_filters: ["); GRN_PTR_INIT(&token_filters, GRN_OBJ_VECTOR, GRN_ID_NIL); grn_obj_get_info(context, table, GRN_INFO_TOKEN_FILTERS, &token_filters); n = GRN_BULK_VSIZE(&token_filters) / sizeof(grn_obj *); for (i = 0; i < n; i++) { grn_obj *token_filter = GRN_PTR_VALUE_AT(&token_filters, i); if (i > 0) { rb_str_cat2(inspected, ", "); } rb_grn_object_inspect_object_content_name(inspected, context, token_filter); } rb_str_cat2(inspected, "]"); } { grn_obj *normalizer; rb_str_cat2(inspected, ", "); rb_str_cat2(inspected, "normalizer: "); normalizer = grn_obj_get_info(context, table, GRN_INFO_NORMALIZER, NULL); if (normalizer) { rb_grn_object_inspect_object_content_name(inspected, context, normalizer); } else { rb_str_cat2(inspected, "(nil)"); } } return inspected; }