Masafumi Yokoyama
null+****@clear*****
Sun Jan 10 15:22:16 JST 2016
Masafumi Yokoyama 2016-01-10 15:22:16 +0900 (Sun, 10 Jan 2016) New Revision: 7fc677a91b5336f7ecbe86c78d9e7e066f059a91 https://github.com/ranguba/rroonga/commit/7fc677a91b5336f7ecbe86c78d9e7e066f059a91 Merged 63d7bb7: Merge pull request #113 from ranguba/bind-grn_obj_reindex Message: Add Groonga::FixSizeColumn#reindex to bind grn_obj_reindex() GitHub: #110 Modified files: ext/groonga/rb-grn-fix-size-column.c test/test-fix-size-column.rb Modified: ext/groonga/rb-grn-fix-size-column.c (+85 -0) =================================================================== --- ext/groonga/rb-grn-fix-size-column.c 2016-01-06 18:07:09 +0900 (f6ff5fb) +++ ext/groonga/rb-grn-fix-size-column.c 2016-01-10 15:22:16 +0900 (9afd19a) @@ -1,6 +1,7 @@ /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2009-2010 Kouhei Sutou <kou �� clear-code.com> + Copyright (C) 2016 Masafumi Yokoyama <yokoyama �� clear-code.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -141,6 +142,87 @@ rb_grn_fix_size_column_decrement (int argc, VALUE *argv, VALUE self) return rb_grn_fix_size_column_integer_set(argc, argv, self, GRN_OBJ_DECR); } +/* + * 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::Table#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("Users") do |table| + * table.integer32("age") + * table.integer32("score") + * end + * + * schema.create_table("Numbers", + * :type => :patricia_trie, + * :key_type => :integer32) do |table| + * table.index("Users.age") + * table.index("Users.score") + * end + * + * schema.create_table("Ages", + * :type => :patricia_trie, + * :key_type => :integer32) do |table| + * table.index("Users.age") + * end + * + * schema.create_table("Scores", + * :type => :patricia_trie, + * :key_type => :integer32) do |table| + * table.index("Users.score") + * end + * end + * + * Groonga["Users.age"].reindex + * # They are called: + * # Groonga["Numbers.Users_age"].reindex + * # Groonga["Ages.Users_age"].reindex + * # + * # They aren't called: + * # Groonga["Numbers.Users_score"].reindex + * # Groonga["Scores.Users_score"].reindex + * + * @overload reindex + * @return [void] + * + * @see Groonga::Database#reindex + * @see Groonga::Table#reindex + * @see Groonga::VariableSizeColumn#reindex + * @see Groonga::IndexColumn#reindex + * + * @since 5.1.1 + */ +static VALUE +rb_grn_fix_size_column_reindex (VALUE self) +{ + grn_rc rc; + grn_ctx *context; + grn_obj *column; + + rb_grn_column_deconstruct(SELF(self), &column, &context, + 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; +} + void rb_grn_init_fix_size_column (VALUE mGrn) { @@ -156,4 +238,7 @@ rb_grn_init_fix_size_column (VALUE mGrn) rb_grn_fix_size_column_increment, -1); rb_define_method(rb_cGrnFixSizeColumn, "decrement!", rb_grn_fix_size_column_decrement, -1); + + rb_define_method(rb_cGrnFixSizeColumn, "reindex", + rb_grn_fix_size_column_reindex, 0); } Modified: test/test-fix-size-column.rb (+84 -0) =================================================================== --- test/test-fix-size-column.rb 2016-01-06 18:07:09 +0900 (de34071) +++ test/test-fix-size-column.rb 2016-01-10 15:22:16 +0900 (d2a8f4a) @@ -1,4 +1,5 @@ # Copyright (C) 2009-2014 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2016 Masafumi Yokoyama <yokoyama �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,6 +21,89 @@ class FixSizeColumnTest < Test::Unit::TestCase setup_database end + def test_reindex + Groonga::Schema.define do |schema| + schema.create_table("Users", :type => :hash) do |table| + table.integer32("age") + table.integer32("score") + end + + schema.create_table("Numbers", + :type => :patricia_trie, + :key_type => :integer32) do |table| + table.index("Users.age") + table.index("Users.score") + end + + schema.create_table("Ages", + :type => :patricia_trie, + :key_type => :integer32) do |table| + table.index("Users.age") + end + + schema.create_table("Scores", + :type => :patricia_trie, + :key_type => :integer32) do |table| + table.index("Users.score") + end + end + + users = context["Users"] + users.add("Alice", :age => 16, :score => 123) + users.add("Bob", :age => 29, :score => -10) + + numbers = context["Numbers"] + numbers.delete(16) + numbers.delete(123) + + ages = context["Ages"] + ages.delete(29) + + scores = context["Scores"] + scores.delete(-10) + + assert_equal({ + :numbers => [ + -10, + 29, + ], + :ages => [ + 16, + ], + :scores => [ + 123, + ], + }, + { + :numbers => numbers.collect(&:_key).sort, + :ages => ages.collect(&:_key).sort, + :scores => scores.collect(&:_key).sort, + }) + + context["Users.age"].reindex + + assert_equal({ + :numbers => [ + -10, + 16, + 29, + ], + :ages => [ + 16, + 29, + ], + :scores => [ + 123, + ], + }, + { + :numbers => numbers.collect(&:_key).sort, + :ages => ages.collect(&:_key).sort, + :scores => scores.collect(&:_key).sort, + }) + + end + class OperationTest < self def setup super -------------- next part -------------- HTML����������������������������... Télécharger