Masafumi Yokoyama
null+****@clear*****
Wed Jan 6 18:07:09 JST 2016
Masafumi Yokoyama 2016-01-06 18:07:09 +0900 (Wed, 06 Jan 2016) New Revision: f67013037a2ce655057c4e5880a529b67f9b881c https://github.com/ranguba/rroonga/commit/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) =================================================================== --- ext/groonga/rb-grn-table.c 2016-01-06 16:56:13 +0900 (a9a718a) +++ ext/groonga/rb-grn-table.c 2016-01-06 18:07:09 +0900 (61ab52f) @@ -1,7 +1,7 @@ /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - Copyright (C) 2014-2015 Masafumi Yokoyama <yokoyama �� clear-code.com> Copyright (C) 2009-2015 Kouhei Sutou <kou �� clear-code.com> + Copyright (C) 2014-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 @@ -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) =================================================================== --- test/test-table.rb 2016-01-06 16:56:13 +0900 (fc991ac) +++ test/test-table.rb 2016-01-06 18:07:09 +0900 (a1b79ee) @@ -1,4 +1,5 @@ # Copyright (C) 2009-2013 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 @@ -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 -------------- next part -------------- HTML����������������������������...Download