static void command_schema_output_plugins(grn_ctx *ctx) { grn_obj plugin_names; unsigned int i, n; GRN_TEXT_INIT(&plugin_names, GRN_OBJ_VECTOR); grn_plugin_get_names(ctx, &plugin_names); grn_ctx_output_cstr(ctx, "plugins"); n = grn_vector_size(ctx, &plugin_names); grn_ctx_output_map_open(ctx, "plugins", n); for (i = 0; i < n; i++) { const char *name; unsigned int name_size; name_size = grn_vector_get_element(ctx, &plugin_names, i, &name, NULL, NULL); grn_ctx_output_str(ctx, name, name_size); grn_ctx_output_map_open(ctx, "plugin", 1); grn_ctx_output_cstr(ctx, "name"); grn_ctx_output_str(ctx, name, name_size); grn_ctx_output_map_close(ctx); } grn_ctx_output_map_close(ctx); GRN_OBJ_FIN(ctx, &plugin_names); }
static grn_obj * command_query_expand(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) { const char *expander; size_t expander_size; const char *query; size_t query_size; const char *flags_raw; size_t flags_raw_size; grn_expr_flags flags = GRN_EXPR_SYNTAX_QUERY; grn_obj expanded_query; expander = grn_plugin_proc_get_var_string(ctx, user_data, "expander", -1, &expander_size); query = grn_plugin_proc_get_var_string(ctx, user_data, "query", -1, &query_size); flags_raw = grn_plugin_proc_get_var_string(ctx, user_data, "flags", -1, &flags_raw_size); if (flags_raw_size > 0) { flags |= grn_proc_expr_query_flags_parse(ctx, flags_raw, flags_raw_size, "[query][expand]"); } else { flags |= GRN_EXPR_ALLOW_PRAGMA | GRN_EXPR_ALLOW_COLUMN; } if (ctx->rc != GRN_SUCCESS) { return NULL; } GRN_TEXT_INIT(&expanded_query, 0); grn_proc_syntax_expand_query(ctx, query, query_size, flags, expander, expander_size, &expanded_query, "[query][expand]"); if (ctx->rc == GRN_SUCCESS) { grn_ctx_output_str(ctx, GRN_TEXT_VALUE(&expanded_query), GRN_TEXT_LEN(&expanded_query)); } GRN_OBJ_FIN(ctx, &expanded_query); return NULL; }
static void command_schema_output_column_name(grn_ctx *ctx, grn_obj *column) { char name[GRN_TABLE_MAX_KEY_SIZE]; unsigned int name_size; name_size = grn_column_name(ctx, column, name, GRN_TABLE_MAX_KEY_SIZE); grn_ctx_output_str(ctx, name, name_size); }
static void command_schema_output_name(grn_ctx *ctx, grn_obj *obj) { if (obj) { char name[GRN_TABLE_MAX_KEY_SIZE]; unsigned int name_size; name_size = grn_obj_name(ctx, obj, name, GRN_TABLE_MAX_KEY_SIZE); grn_ctx_output_str(ctx, name, name_size); } else { grn_ctx_output_null(ctx); } }
static void output_tokens(grn_ctx *ctx, grn_obj *tokens, grn_obj *lexicon, grn_obj *index_column) { int i, n_tokens, n_elements; grn_obj estimated_size; n_tokens = GRN_BULK_VSIZE(tokens) / sizeof(tokenize_token); n_elements = 3; if (index_column) { n_elements++; GRN_UINT32_INIT(&estimated_size, 0); } grn_ctx_output_array_open(ctx, "TOKENS", n_tokens); for (i = 0; i < n_tokens; i++) { tokenize_token *token; char value[GRN_TABLE_MAX_KEY_SIZE]; unsigned int value_size; token = ((tokenize_token *)(GRN_BULK_HEAD(tokens))) + i; grn_ctx_output_map_open(ctx, "TOKEN", n_elements); grn_ctx_output_cstr(ctx, "value"); value_size = grn_table_get_key(ctx, lexicon, token->id, value, GRN_TABLE_MAX_KEY_SIZE); grn_ctx_output_str(ctx, value, value_size); grn_ctx_output_cstr(ctx, "position"); grn_ctx_output_int32(ctx, token->position); grn_ctx_output_cstr(ctx, "force_prefix"); grn_ctx_output_bool(ctx, token->force_prefix); if (index_column) { GRN_BULK_REWIND(&estimated_size); grn_obj_get_value(ctx, index_column, token->id, &estimated_size); grn_ctx_output_cstr(ctx, "estimated_size"); grn_ctx_output_int64(ctx, GRN_UINT32_VALUE(&estimated_size)); } grn_ctx_output_map_close(ctx); } if (index_column) { GRN_OBJ_FIN(ctx, &estimated_size); } grn_ctx_output_array_close(ctx); }
static void command_schema_output_command(grn_ctx *ctx, const char *command_name, grn_obj *arguments) { grn_ctx_output_map_open(ctx, "command", 3); grn_ctx_output_cstr(ctx, "name"); grn_ctx_output_cstr(ctx, command_name); grn_ctx_output_cstr(ctx, "arguments"); { int i, n; n = grn_vector_size(ctx, arguments); grn_ctx_output_map_open(ctx, "arguments", n / 2); for (i = 0; i < n; i += 2) { const char *name; unsigned int name_size; const char *value; unsigned int value_size; name_size = grn_vector_get_element(ctx, arguments, i, &name, NULL, NULL); value_size = grn_vector_get_element(ctx, arguments, i + 1, &value, NULL, NULL); grn_ctx_output_str(ctx, name, name_size); grn_ctx_output_str(ctx, value, value_size); } grn_ctx_output_map_close(ctx); } grn_ctx_output_cstr(ctx, "command_line"); { int i, n; grn_obj command_line; GRN_TEXT_INIT(&command_line, 0); GRN_TEXT_PUTS(ctx, &command_line, command_name); n = grn_vector_size(ctx, arguments); for (i = 0; i < n; i += 2) { const char *name; unsigned int name_size; const char *value; unsigned int value_size; name_size = grn_vector_get_element(ctx, arguments, i, &name, NULL, NULL); value_size = grn_vector_get_element(ctx, arguments, i + 1, &value, NULL, NULL); grn_text_printf(ctx, &command_line, " --%.*s %.*s", name_size, name, value_size, value); } grn_ctx_output_str(ctx, GRN_TEXT_VALUE(&command_line), GRN_TEXT_LEN(&command_line)); GRN_OBJ_FIN(ctx, &command_line); } grn_ctx_output_map_close(ctx); }