Hiroshi Hatake
hatak****@clear*****
Wed Jan 6 18:18:24 JST 2016
そういえば、コメントを見ていて疑問に感じたのですが、 > You don't need to specify each index column. But this > + * method spends more time rather than you specify only reindex > + * needed index columns. と書いているので、 実はインデックスの再作成が必要なカラム(の文字列?シンボル?)を引数に取る事もできるメソッドにした方が良いとかありますか? もしも無いなら、 > But this > + * method spends more time rather than you specify only reindex > + * needed index columns. の行は削ってしまうとか。 指定出来る必要があるなら、コメントの最初は > + * Recreates all index columns in the table. ではなく、 Recreate all or specified index columns in the table. としてみるのはどうでしょうか? -- Hiroshi Hatake <hatak****@clear*****> 2016/01/06 18:07、Masafumi Yokoyama <null+****@clear*****> のメール: > Author > Masafumi Yokoyama <yokoy****@clear*****> > Date > 2016-01-06 18:07:09 +0900 (Wed, 06 Jan 2016) > New Revision > f67013037a2ce655057c4e5880a529b67f9b881c > Message > Add Groonga::Table#reindex to bind grn_obj_reindex() > > GitHub: #110 > Modified files > ext/groonga/rb-grn-table.c > test/test-table.rb > Modified: ext/groonga/rb-grn-table.c (+57 -1) > =================================================================== > ... > 1 > 2 > 3 > 4 > > 5 > 6 > 7 > ... > 2678 > 2679 > 2680 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 2681 > 2682 > 2683 > ... > 2765 > 2766 > 2767 > > > 2768 > 2769 > 2770 > ... > 1 > 2 > > 3 > 4 > 5 > 6 > 7 > ... > 2678 > 2679 > 2680 > 2681 > 2682 > 2683 > 2684 > 2685 > 2686 > 2687 > 2688 > 2689 > 2690 > 2691 > 2692 > 2693 > 2694 > 2695 > 2696 > 2697 > 2698 > 2699 > 2700 > 2701 > 2702 > 2703 > 2704 > 2705 > 2706 > 2707 > 2708 > 2709 > 2710 > 2711 > 2712 > 2713 > 2714 > 2715 > 2716 > 2717 > 2718 > 2719 > 2720 > 2721 > 2722 > 2723 > 2724 > 2725 > 2726 > 2727 > 2728 > 2729 > 2730 > 2731 > 2732 > 2733 > 2734 > 2735 > 2736 > 2737 > ... > 2819 > 2820 > 2821 > 2822 > 2823 > 2824 > 2825 > 2826 > @@ -1,7 +1,7 @@ > /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ > /* > - Copyright (C) 2014-2015 Masafumi Yokoyama <yokoy****@clear*****> > Copyright (C) 2009-2015 Kouhei Sutou <kou****@clear*****> > + Copyright (C) 2014-2016 Masafumi Yokoyama <yokoy****@clear*****> > > This library is free software; you can redistribute it and/or > modify it under the terms of the GNU Lesser General Public > @@ -2678,6 +2678,60 @@ rb_grn_table_rename (VALUE self, VALUE rb_name) > return self; > } > > +/* > + * Recreates all index columns in the table. > + * > + * This method is useful when you have any broken index columns in > + * the table. You don't need to specify each index column. But this > + * method spends more time rather than you specify only reindex > + * needed index columns. > + * > + * @example How to recreate all index columns in the table > + * Groonga::Schema.define do |schema| > + * schema.create_table("Memos") do |table| > + * table.short_text("title") > + * table.text("content") > + * end > + * > + * schema.create_table("Terms", > + * :type => :patricia_trie, > + * :key_type => :short_text, > + * :normalizer => "NormalizerAuto", > + * :default_tokenizer => "TokenBigram") do |table| > + * table.index("Memos.title") > + * table.index("Memos.content") > + * end > + * end > + * > + * Groonga["Terms"].reindex > + * # => > + * # Groonga["Terms.Memos_title"].reindex > + * # Groonga["Terms.Memos_content"].reindex > + * > + * @overload reindex > + * @return [void] > + * > + * @since 5.1.1 > + */ > +static VALUE > +rb_grn_table_reindex (VALUE self) > +{ > + grn_rc rc; > + grn_ctx *context; > + grn_obj *table; > + > + rb_grn_table_deconstruct(SELF(self), &table, &context, > + NULL, NULL, NULL, > + NULL, NULL, > + NULL); > + > + rc = grn_obj_reindex(context, table); > + rb_grn_context_check(context, self); > + rb_grn_rc_check(rc, self); > + > + return Qnil; > +} > + > void > rb_grn_init_table (VALUE mGrn) > { > @@ -2765,6 +2819,8 @@ rb_grn_init_table (VALUE mGrn) > > rb_define_method(rb_cGrnTable, "rename", rb_grn_table_rename, 1); > > + rb_define_method(rb_cGrnTable, "reindex", rb_grn_table_reindex, 0); > + > rb_grn_init_table_key_support(mGrn); > rb_grn_init_array(mGrn); > rb_grn_init_hash(mGrn); > Modified: test/test-table.rb (+40 -0) > =================================================================== > ... > 1 > > 2 > 3 > 4 > ... > 421 > 422 > 423 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 424 > 425 > 426 > ... > 1 > 2 > 3 > 4 > 5 > ... > 422 > 423 > 424 > 425 > 426 > 427 > 428 > 429 > 430 > 431 > 432 > 433 > 434 > 435 > 436 > 437 > 438 > 439 > 440 > 441 > 442 > 443 > 444 > 445 > 446 > 447 > 448 > 449 > 450 > 451 > 452 > 453 > 454 > 455 > 456 > 457 > 458 > 459 > 460 > 461 > 462 > 463 > 464 > 465 > 466 > @@ -1,4 +1,5 @@ > # Copyright (C) 2009-2013 Kouhei Sutou <kou****@clear*****> > +# Copyright (C) 2016 Masafumi Yokoyama <yokoy****@clear*****> > # > # This library is free software; you can redistribute it and/or > # modify it under the terms of the GNU Lesser General Public > @@ -421,6 +422,45 @@ class TableTest < Test::Unit::TestCase > sorted_bookmarks.collect(&:value)) > end > > + def test_reindex > + Groonga::Schema.define do |schema| > + schema.create_table("Memos", > + :type => :array) do |table| > + table.text("content") > + end > + schema.create_table("Terms", > + :type => :patricia_trie, > + :key_type => :short_text, > + :default_tokenizer => "TokenBigram", > + :normalizer => "NormalizerAuto") do |table| > + table.index("Memos.content") > + end > + end > + > + memos = context["Memos"] > + memos.add(:content => "This is a memo") > + > + terms = context["Terms"] > + terms.delete("this") > + > + assert_equal([ > + "a", > + "is", > + "memo", > + ], > + terms.collect(&:_key).sort) > + > + terms.reindex > + > + assert_equal([ > + "a", > + "is", > + "memo", > + "this", > + ], > + terms.collect(&:_key).sort) > + end > + > sub_test_case "#geo_sort" do > setup > def setup_schema > _______________________________________________ > Groonga-commit mailing list > Groon****@lists***** > http://lists.osdn.me/mailman/listinfo/groonga-commit -------------- next part -------------- An HTML attachment was scrubbed...Download