Kouhei Sutou
null+****@clear*****
Mon Feb 24 18:08:18 JST 2014
Kouhei Sutou 2014-02-24 18:08:18 +0900 (Mon, 24 Feb 2014) New Revision: b8fef298ecb2bac9baae6e7a874aac18ae2dca05 https://github.com/ranguba/rroonga/commit/b8fef298ecb2bac9baae6e7a874aac18ae2dca05 Message: index column: add #inverted? and #forward? predicates Modified files: ext/groonga/rb-grn-index-column.c test/test-index-column.rb Modified: ext/groonga/rb-grn-index-column.c (+59 -0) =================================================================== --- ext/groonga/rb-grn-index-column.c 2014-02-24 17:48:47 +0900 (319e896) +++ ext/groonga/rb-grn-index-column.c 2014-02-24 18:08:18 +0900 (914ec82) @@ -1047,6 +1047,58 @@ rb_grn_index_column_with_position_p (VALUE self) } /* + * @overload inverted? + * @returns [Boolean] @true@ if the index column is inverted index, + * @false@ otherwise. + */ +static VALUE +rb_grn_index_column_inverted_p (VALUE self) +{ + grn_ctx *context; + grn_obj *column; + grn_obj sources; + grn_bool inverted_p; + + rb_grn_index_column_deconstruct(SELF(self), &column, &context, + NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL); + + GRN_RECORD_INIT(&sources, GRN_OBJ_VECTOR, GRN_ID_NIL); + grn_obj_get_info(context, column, GRN_INFO_SOURCE, &sources); + inverted_p = (GRN_BULK_VSIZE(&sources) > 0); + GRN_OBJ_FIN(context, &sources); + + return CBOOL2RVAL(inverted_p); +} + +/* + * @overload forward? + * @returns [Boolean] @true@ if the index column is forward index, + * @false@ otherwise. + */ +static VALUE +rb_grn_index_column_forward_p (VALUE self) +{ + grn_ctx *context; + grn_obj *column; + grn_obj sources; + grn_bool forward_p; + + rb_grn_index_column_deconstruct(SELF(self), &column, &context, + NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL); + + GRN_RECORD_INIT(&sources, GRN_OBJ_VECTOR, GRN_ID_NIL); + grn_obj_get_info(context, column, GRN_INFO_SOURCE, &sources); + forward_p = (GRN_BULK_VSIZE(&sources) == 0); + GRN_OBJ_FIN(context, &sources); + + return CBOOL2RVAL(forward_p); +} + +/* * Opens cursor to iterate posting in the index column. * * @example @@ -1163,6 +1215,13 @@ rb_grn_init_index_column (VALUE mGrn) rb_grn_index_column_with_weight_p, 0); rb_define_method(rb_cGrnIndexColumn, "with_position?", rb_grn_index_column_with_position_p, 0); + + rb_define_method(rb_cGrnIndexColumn, "inverted?", + rb_grn_index_column_inverted_p, 0); + rb_define_method(rb_cGrnIndexColumn, "forward?", + rb_grn_index_column_forward_p, 0); + + rb_define_method(rb_cGrnIndexColumn, "open_cursor", rb_grn_index_column_open_cursor, -1); } Modified: test/test-index-column.rb (+33 -0) =================================================================== --- test/test-index-column.rb 2014-02-24 17:48:47 +0900 (9f6b9fa) +++ test/test-index-column.rb 2014-02-24 18:08:18 +0900 (baa061e) @@ -175,6 +175,34 @@ class IndexColumnTest < Test::Unit::TestCase end end + class InvertedIndexTest < self + setup + def setup_schema + Groonga::Schema.define do |schema| + schema.create_table("Tags", + :type => :patricia_trie, + :key_type => :short_text) do |table| + end + + schema.create_table("Products", + :type => :patricia_trie, + :key_type => :short_text) do |table| + table.reference("tags", "Tags", :type => :vector) + end + + schema.change_table("Tags") do |table| + table.index("Products.tags", :name => "products_tags") + end + end + + @index = Groonga["Tags.products_tags"] + end + + def test_predicate + assert_true(@index.inverted?) + end + end + class ForwardIndexTest < self setup def setup_schema @@ -194,6 +222,11 @@ class IndexColumnTest < Test::Unit::TestCase end @products = Groonga["Products"] + @index = Groonga["Products.tags"] + end + + def test_predicate + assert_true(@index.forward?) end def test_accessor -------------- next part -------------- HTML����������������������������...Download