/* * Returns whether the column is compressed or not. If * @type@ is specified, it returns whether the column is * compressed by @type@ or not. * @overload compressed? * @return [Boolean] whether the column is compressed or not. * @overload compressed?(type) * @param [:zlib, :lz4] type (nil) * @return [Boolean] whether specified compressed type is used or not. * @since 1.3.1 */ static VALUE rb_grn_variable_size_column_compressed_p (int argc, VALUE *argv, VALUE self) { RbGrnVariableSizeColumn *rb_grn_column; grn_ctx *context = NULL; grn_obj *column; grn_obj_flags flags; VALUE type; grn_bool compressed_p = GRN_FALSE; grn_bool accept_any_type = GRN_FALSE; grn_bool need_zlib_check = GRN_FALSE; grn_bool need_lz4_check = GRN_FALSE; rb_scan_args(argc, argv, "01", &type); if (NIL_P(type)) { accept_any_type = GRN_TRUE; } else { if (rb_grn_equal_option(type, "zlib")) { need_zlib_check = GRN_TRUE; } else if (rb_grn_equal_option(type, "lzo")) { /* TODO: for backward compatibility */ need_lz4_check = GRN_TRUE; } else if (rb_grn_equal_option(type, "lz4")) { need_lz4_check = GRN_TRUE; } else { rb_raise(rb_eArgError, "compressed type should be <:zlib> or <:lz4>: <%s>", rb_grn_inspect(type)); } } rb_grn_column = SELF(self); rb_grn_object_deconstruct(RB_GRN_OBJECT(rb_grn_column), &column, &context, NULL, NULL, NULL, NULL); flags = column->header.flags; switch (flags & GRN_OBJ_COMPRESS_MASK) { case GRN_OBJ_COMPRESS_ZLIB: if (accept_any_type || need_zlib_check) { grn_obj support_p; GRN_BOOL_INIT(&support_p, 0); grn_obj_get_info(context, NULL, GRN_INFO_SUPPORT_ZLIB, &support_p); compressed_p = GRN_BOOL_VALUE(&support_p); } break; case GRN_OBJ_COMPRESS_LZ4: if (accept_any_type || need_lz4_check) { grn_obj support_p; GRN_BOOL_INIT(&support_p, 0); grn_obj_get_info(context, NULL, GRN_INFO_SUPPORT_LZ4, &support_p); compressed_p = GRN_BOOL_VALUE(&support_p); } break; } return CBOOL2RVAL(compressed_p); }
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); }
/* * call-seq: * column.sources -> Groonga::Columnの配列 * * インデックス対象となっているカラムの配列を返す。 */ static VALUE rb_grn_index_column_get_sources (VALUE self) { grn_ctx *context = NULL; grn_obj *column; grn_obj sources; grn_id *source_ids; VALUE rb_sources; int i, n; rb_grn_index_column_deconstruct(SELF(self), &column, &context, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); GRN_OBJ_INIT(&sources, GRN_BULK, 0, GRN_ID_NIL); grn_obj_get_info(context, column, GRN_INFO_SOURCE, &sources); rb_grn_context_check(context, self); n = GRN_BULK_VSIZE(&sources) / sizeof(grn_id); source_ids = (grn_id *)GRN_BULK_HEAD(&sources); rb_sources = rb_ary_new2(n); for (i = 0; i < n; i++) { grn_obj *source; VALUE rb_source; source = grn_ctx_at(context, *source_ids); rb_source = GRNOBJECT2RVAL(Qnil, context, source, RB_GRN_FALSE); rb_ary_push(rb_sources, rb_source); source_ids++; } grn_obj_unlink(context, &sources); return rb_sources; }
static grn_rc grn_ii_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj) { grn_obj sources; int i, n, have_flags = 0; grn_id *source_ids; GRN_TEXT_PUTS(ctx, buf, "#<column:index "); grn_column_inspect_common(ctx, buf, obj); GRN_TEXT_INIT(&sources, 0); grn_obj_get_info(ctx, obj, GRN_INFO_SOURCE, &sources); source_ids = (grn_id *)GRN_BULK_HEAD(&sources); n = GRN_BULK_VSIZE(&sources) / sizeof(grn_id); GRN_TEXT_PUTS(ctx, buf, " sources:["); for (i = 0; i < n; i++) { grn_id source_id; grn_obj *source; if (i) { GRN_TEXT_PUTS(ctx, buf, ", "); } source_id = source_ids[i]; source = grn_ctx_at(ctx, source_id); if (source) { grn_inspect_name(ctx, buf, source); } else { grn_text_lltoa(ctx, buf, source_id); } } GRN_TEXT_PUTS(ctx, buf, "]"); GRN_OBJ_FIN(ctx, &sources); GRN_TEXT_PUTS(ctx, buf, " flags:"); if (obj->header.flags & GRN_OBJ_WITH_SECTION) { GRN_TEXT_PUTS(ctx, buf, "SECTION"); have_flags = 1; } if (obj->header.flags & GRN_OBJ_WITH_WEIGHT) { if (have_flags) { GRN_TEXT_PUTS(ctx, buf, "|"); } GRN_TEXT_PUTS(ctx, buf, "WEIGHT"); have_flags = 1; } if (obj->header.flags & GRN_OBJ_WITH_POSITION) { if (have_flags) { GRN_TEXT_PUTS(ctx, buf, "|"); } GRN_TEXT_PUTS(ctx, buf, "POSITION"); have_flags = 1; } if (!have_flags) { GRN_TEXT_PUTS(ctx, buf, "NONE"); } GRN_TEXT_PUTS(ctx, buf, " elements:"); grn_ii_inspect_elements(ctx, (grn_ii *)obj, buf); GRN_TEXT_PUTS(ctx, buf, ">"); return GRN_SUCCESS; }
static void command_schema_column_output_sources(grn_ctx *ctx, grn_obj *column) { grn_obj *source_table; grn_obj source_ids; unsigned int i, n_ids; source_table = grn_ctx_at(ctx, grn_obj_get_range(ctx, column)); GRN_RECORD_INIT(&source_ids, GRN_OBJ_VECTOR, GRN_ID_NIL); if (column->header.type == GRN_COLUMN_INDEX) { grn_obj_get_info(ctx, column, GRN_INFO_SOURCE, &source_ids); } n_ids = GRN_BULK_VSIZE(&source_ids) / sizeof(grn_id); grn_ctx_output_array_open(ctx, "sources", n_ids); for (i = 0; i < n_ids; i++) { grn_id source_id; grn_obj *source; source_id = GRN_RECORD_VALUE_AT(&source_ids, i); source = grn_ctx_at(ctx, source_id); grn_ctx_output_map_open(ctx, "source", 3); grn_ctx_output_cstr(ctx, "name"); if (grn_obj_is_table(ctx, source)) { grn_ctx_output_cstr(ctx, "_key"); } else { command_schema_output_column_name(ctx, source); } grn_ctx_output_cstr(ctx, "table"); command_schema_output_name(ctx, source_table); grn_ctx_output_cstr(ctx, "full_name"); if (grn_obj_is_table(ctx, source)) { char name[GRN_TABLE_MAX_KEY_SIZE]; unsigned int name_size; name_size = grn_obj_name(ctx, source, name, GRN_TABLE_MAX_KEY_SIZE); name[name_size] = '\0'; grn_strcat(name, GRN_TABLE_MAX_KEY_SIZE, "._key"); grn_ctx_output_cstr(ctx, name); } else { command_schema_output_name(ctx, source); } grn_ctx_output_map_close(ctx); } grn_ctx_output_array_close(ctx); GRN_OBJ_FIN(ctx, &source_ids); }
/* * Returns the normalizer that is used by {Groonga::IndexColumn}. * * @overload normalizer * @return [nil, Groonga::Procedure] */ static VALUE rb_grn_table_key_support_get_normalizer (VALUE self) { grn_ctx *context = NULL; grn_obj *table; grn_obj *normalizer = NULL; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, NULL, NULL, NULL, NULL, NULL, NULL, NULL); normalizer = grn_obj_get_info(context, table, GRN_INFO_NORMALIZER, NULL); rb_grn_context_check(context, self); return GRNOBJECT2RVAL(Qnil, context, normalizer, GRN_FALSE); }
/* * {Groonga::IndexColumn} で使用するトークナイザを返す。 * * @overload default_tokenizer * @return [nilまたはGroonga::Procedure] */ static VALUE rb_grn_table_key_support_get_default_tokenizer (VALUE self) { grn_ctx *context = NULL; grn_obj *table; grn_obj *tokenizer = NULL; rb_grn_table_key_support_deconstruct(SELF(self), &table, &context, NULL, NULL, NULL, NULL, NULL, NULL, NULL); tokenizer = grn_obj_get_info(context, table, GRN_INFO_DEFAULT_TOKENIZER, NULL); rb_grn_context_check(context, self); return GRNOBJECT2RVAL(Qnil, context, tokenizer, GRN_FALSE); }
void test_support_lzo(void) { int support_p; grn_obj grn_support_p; cut_assert_ensure_context(); GRN_BOOL_INIT(&grn_support_p, 0); grn_obj_get_info(context, NULL, GRN_INFO_SUPPORT_LZO, &grn_support_p); support_p = GRN_BOOL_VALUE(&grn_support_p); GRN_OBJ_FIN(context, &grn_support_p); #ifdef GRN_WITH_LZO cut_assert_true(support_p); #else cut_assert_false(support_p); #endif }
static void command_schema_table_output_normalizer(grn_ctx *ctx, grn_obj *table) { grn_obj *normalizer; normalizer = grn_obj_get_info(ctx, table, GRN_INFO_NORMALIZER, NULL); if (!normalizer) { grn_ctx_output_null(ctx); return; } 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); }
static void command_schema_table_output_tokenizer(grn_ctx *ctx, grn_obj *table) { grn_obj *tokenizer; tokenizer = grn_obj_get_info(ctx, table, GRN_INFO_DEFAULT_TOKENIZER, NULL); if (!tokenizer) { grn_ctx_output_null(ctx); return; } grn_ctx_output_map_open(ctx, "tokenizer", 1); grn_ctx_output_cstr(ctx, "name"); command_schema_output_name(ctx, tokenizer); grn_ctx_output_map_close(ctx); }
void test_temporary_table_default_tokenizer(gpointer data) { grn_obj *table; grn_obj_flags flags = GPOINTER_TO_INT(data); grn_obj *tokenizer = NULL; char name[1024]; int name_size; table = grn_table_create(context, NULL, 0, NULL, flags, NULL, NULL); grn_obj_set_info(context, table, GRN_INFO_DEFAULT_TOKENIZER, get_object("TokenTrigram")); tokenizer = grn_obj_get_info(context, table, GRN_INFO_DEFAULT_TOKENIZER, NULL); name_size = grn_obj_name(context, tokenizer, name, sizeof(name)); name[name_size] = '\0'; cut_assert_equal_string("TokenTrigram", name); }
/* * 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; }
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)"); } } { 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; }
static void command_schema_column_command_collect_arguments(grn_ctx *ctx, grn_obj *table, grn_obj *column, 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("table", table); { char column_name[GRN_TABLE_MAX_KEY_SIZE]; unsigned int column_name_size; column_name_size = grn_column_name(ctx, column, column_name, GRN_TABLE_MAX_KEY_SIZE); column_name[column_name_size] = '\0'; ADD("name", column_name); } { grn_obj flags; GRN_TEXT_INIT(&flags, 0); grn_dump_column_create_flags(ctx, column->header.flags & ~GRN_OBJ_PERSISTENT, &flags); GRN_TEXT_PUTC(ctx, &flags, '\0'); ADD("flags", GRN_TEXT_VALUE(&flags)); GRN_OBJ_FIN(ctx, &flags); } { grn_obj *value_type; value_type = grn_ctx_at(ctx, grn_obj_get_range(ctx, column)); ADD_OBJECT_NAME("type", value_type); } if (column->header.type == GRN_COLUMN_INDEX) { grn_obj source_ids; unsigned int n_ids; GRN_RECORD_INIT(&source_ids, GRN_OBJ_VECTOR, GRN_ID_NIL); grn_obj_get_info(ctx, column, GRN_INFO_SOURCE, &source_ids); n_ids = GRN_BULK_VSIZE(&source_ids) / sizeof(grn_id); if (n_ids > 0) { grn_obj sources; unsigned int i; GRN_TEXT_INIT(&sources, 0); for (i = 0; i < n_ids; i++) { grn_id source_id; grn_obj *source; char name[GRN_TABLE_MAX_KEY_SIZE]; unsigned int name_size; source_id = GRN_RECORD_VALUE_AT(&source_ids, i); source = grn_ctx_at(ctx, source_id); if (grn_obj_is_table(ctx, source)) { grn_strcpy(name, GRN_TABLE_MAX_KEY_SIZE, "_key"); name_size = strlen(name); } else { name_size = grn_column_name(ctx, source, name, GRN_TABLE_MAX_KEY_SIZE); } if (i > 0) { GRN_TEXT_PUTC(ctx, &sources, ','); } GRN_TEXT_PUT(ctx, &sources, name, name_size); } GRN_TEXT_PUTC(ctx, &sources, '\0'); ADD("sources", GRN_TEXT_VALUE(&sources)); GRN_OBJ_FIN(ctx, &sources); } GRN_OBJ_FIN(ctx, &source_ids); } #undef ADD_OBJECT_NAME #undef ADD }
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 }