Masafumi Yokoyama
null+****@clear*****
Sat Mar 5 14:53:33 JST 2016
Masafumi Yokoyama 2016-03-05 14:53:33 +0900 (Sat, 05 Mar 2016) New Revision: 7707a5e4bfa0f9b7182999054b0f7c36fc428759 https://github.com/ranguba/rroonga/commit/7707a5e4bfa0f9b7182999054b0f7c36fc428759 Merged dc4f11e: Merge pull request #120 from ranguba/bind-grn_column_get_all_index_data Message: Bind grn_column_get_all_index_data() GitHub: #116 TODO: Add multiple indexes test. Modified files: ext/groonga/rb-grn-column.c test/test-column.rb Modified: ext/groonga/rb-grn-column.c (+41 -0) =================================================================== --- ext/groonga/rb-grn-column.c 2016-03-05 14:34:23 +0900 (9092422) +++ ext/groonga/rb-grn-column.c 2016-03-05 14:53:33 +0900 (d84f9ad) @@ -2,6 +2,7 @@ /* vim: set sts=4 sw=4 ts=8 noet: */ /* Copyright (C) 2009-2015 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 @@ -754,6 +755,45 @@ rb_grn_column_get_indexes (int argc, VALUE *argv, VALUE self) } /* + * Return all indexes on `column`. + * + * @overload all_indexes + * @return [Array<index_column>] All indexes on `column`. + * + * @since 6.0.0 + */ +static VALUE +rb_grn_column_get_all_indexes (VALUE self) +{ + grn_ctx *context; + grn_obj *column; + grn_index_datum *index_data = NULL; + int i, n_indexes; + VALUE rb_indexes; + + rb_grn_column_deconstruct(SELF(self), &column, &context, + NULL, NULL, + NULL, NULL, NULL); + + rb_indexes = rb_ary_new(); + n_indexes = grn_column_get_all_index_data(context, column, NULL, 0); + if (n_indexes == 0) + return rb_indexes; + + index_data = xmalloc(sizeof(grn_index_datum) * n_indexes); + n_indexes = grn_column_get_all_index_data(context, column, + index_data, n_indexes); + for (i = 0; i < n_indexes; i++) { + VALUE rb_index; + rb_index = GRNOBJECT2RVAL(Qnil, context, index_data[i].index, GRN_FALSE); + rb_ary_push(rb_indexes, rb_index); + grn_obj_unlink(context, index_data[i].index); + } + xfree(index_data); + return rb_indexes; +} + +/* * Renames the column to name. * @since 1.3.0 * @overload rename(name) @@ -813,6 +853,7 @@ rb_grn_init_column (VALUE mGrn) rb_grn_column_with_weight_p, 0); rb_define_method(rb_cGrnColumn, "indexes", rb_grn_column_get_indexes, -1); + rb_define_method(rb_cGrnColumn, "all_indexes", rb_grn_column_get_all_indexes, 0); rb_define_method(rb_cGrnColumn, "rename", rb_grn_column_rename, 1); Modified: test/test-column.rb (+33 -0) =================================================================== --- test/test-column.rb 2016-03-05 14:34:23 +0900 (17d03ea) +++ test/test-column.rb 2016-03-05 14:53:33 +0900 (58b677e) @@ -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 @@ -584,4 +585,36 @@ class ColumnTest < Test::Unit::TestCase assert_equal(["title1"], select.call) end end + + class AllIndexedTest < self + def setup + super + Groonga::Schema.define do |schema| + schema.create_table("Comments") do |table| + table.short_text("title") + end + end + @title = Groonga["Comments.title"] + end + + def test_nothing + assert_equal([], @title.all_indexes) + end + + def test_one_index + Groonga::Schema.define do |schema| + schema.create_table("Terms", + :type => :patricia_trie, + :default_tokenizer => "TokenBigram") do |table| + table.index("Comments.title") + end + end + assert_equal([Groonga["Terms.Comments_title"]], + @title.all_indexes) + end + + def test_multiple_indexes + # TODO + end + end end -------------- next part -------------- HTML����������������������������...Descargar