/* * Recreates all index columns in the database. * * This method is useful when you have any broken index columns in * the database. You don't need to specify each index column. But * this method spends more time rather than you specify only reindex * needed index columns. * * You can use {Groonga::TableKeySupport#reindex} to specify reindex * target index columns in a table. * * You can use {Groonga::FixSizeColumn#reindex} or * {Groonga::VariableSizeColumn#reindex} to specify reindex target * index columns. They use index columns of the data column as * reindex target index columns. * * You can use {Groonga::IndexColumn#reindex} to specify the reindex * target index column. * * @example How to recreate all index columns in the database * database = Groonga::Database.create(:path => "/tmp/db") * * Groonga::Schema.define do |schema| * schema.create_table("Memos") do |table| * table.short_text("title") * table.text("content") * end * * schema.create_table("BigramTerms", * :type => :patricia_trie, * :key_type => :short_text, * :normalizer => "NormalizerAuto", * :default_tokenizer => "TokenBigram") do |table| * table.index("Memos.title") * table.index("Memos.content") * end * * schema.create_table("MeCabTerms", * :type => :patricia_trie, * :key_type => :short_text, * :normalizer => "NormalizerAuto", * :default_tokenizer => "TokenMecab") do |table| * table.index("Memos.title") * table.index("Memos.content") * end * end * * database.reindex * # They are called: * # Groonga["BigramTerms.Memos_title"].reindex * # Groonga["BigramTerms.Memos_content"].reindex * # Groonga["MeCabTerms.Memos_title"].reindex * # Groonga["MeCabTerms.Memos_content"].reindex * * @overload reindex * @return [void] * * @see Groonga::TableKeySupport#reindex * @see Groonga::FixSizeColumn#reindex * @see Groonga::VariableSizeColumn#reindex * @see Groonga::IndexColumn#reindex * * @since 5.1.1 */ static VALUE rb_grn_database_reindex (VALUE self) { grn_rc rc; grn_ctx *context; grn_obj *database; rb_grn_database_deconstruct(SELF(self), &database, &context, NULL, NULL, NULL, NULL); rc = grn_obj_reindex(context, database); rb_grn_context_check(context, self); rb_grn_rc_check(rc, self); return Qnil; }
/* * Recreates all index columns for the column. * * This method is useful when you have any broken index columns for * the column. You don't need to specify each index column. But this * method spends more time rather than you specify only reindex * needed index columns. * * You can use {Groonga::Database#reindex} to recreate all index * columns in a database. * * You can use {Groonga::TableKeySupport#reindex} to recreate all * index columns in a table. * * You can use {Groonga::IndexColumn#reindex} to specify the reindex * target index column. * * @example How to recreate all index columns for the column * Groonga::Schema.define do |schema| * schema.create_table("Memos") do |table| * table.short_text("title") * table.text("content") * end * * schema.create_table("BigramTerms", * :type => :patricia_trie, * :key_type => :short_text, * :normalizer => "NormalizerAuto", * :default_tokenizer => "TokenBigram") do |table| * table.index("Memos.title") * table.index("Memos.content") * end * * schema.create_table("MeCabTerms", * :type => :patricia_trie, * :key_type => :short_text, * :normalizer => "NormalizerAuto", * :default_tokenizer => "TokenMecab") do |table| * table.index("Memos.title") * table.index("Memos.content") * end * end * * Groonga["Memos.content"].reindex * # They are called: * # Groonga["BigramTerms.Memos_content"].reindex * # Groonga["MeCabTerms.Memos_content"].reindex * # * # They aren't called: * # Groonga["BigramTerms.Memos_title"].reindex * # Groonga["MeCabTerms.Memos_title"].reindex * * @overload reindex * @return [void] * * @see Groonga::Database#reindex * @see Groonga::TableKeySupport#reindex * @see Groonga::FixSizeColumn#reindex * @see Groonga::IndexColumn#reindex * * @since 5.1.1 */ static VALUE rb_grn_variable_size_column_reindex (VALUE self) { grn_rc rc; grn_ctx *context; grn_obj *column; rb_grn_variable_size_column_deconstruct(SELF(self), &column, &context, NULL, NULL, NULL, NULL, NULL, NULL); rc = grn_obj_reindex(context, column); rb_grn_context_check(context, self); rb_grn_rc_check(rc, self); return Qnil; }
static void grn_db_reindex(grn_ctx *ctx, grn_obj *db) { grn_table_cursor *cursor; grn_id id; cursor = grn_table_cursor_open(ctx, db, NULL, 0, NULL, 0, 0, -1, GRN_CURSOR_BY_ID); if (!cursor) { return; } while ((id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) { grn_obj *object; object = grn_ctx_at(ctx, id); if (!object) { ERRCLR(ctx); continue; } switch (object->header.type) { case GRN_TABLE_HASH_KEY : case GRN_TABLE_PAT_KEY : case GRN_TABLE_DAT_KEY : grn_obj_reindex(ctx, object); break; default: break; } grn_obj_unlink(ctx, object); if (ctx->rc != GRN_SUCCESS) { break; } } grn_table_cursor_close(ctx, cursor); }