Navigation Menu

Skip to content

Commit

Permalink
Add Column#weight_vector?
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 25, 2017
1 parent 75fc614 commit 2e9786d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ext/groonga/rb-grn-column.c
Expand Up @@ -654,6 +654,26 @@ rb_grn_column_vector_p (VALUE self)
return CBOOL2RVAL(grn_obj_is_vector_column(context, column));
}

/*
* @overload weight_vector?
* @return [Bool] `true` if the column is a weight vector column,
* `false` otherwise.
*
* @since 7.0.2
*/
static VALUE
rb_grn_column_weight_vector_p (VALUE self)
{
grn_ctx *context;
grn_obj *column;

rb_grn_column_deconstruct(SELF(self), &column, &context,
NULL, NULL,
NULL, NULL, NULL);

return CBOOL2RVAL(grn_obj_is_weight_vector_column(context, column));
}

/*
* _column_ がスカラーカラムの場合は +true+ を返し、
* そうでない場合は +false+ を返す。
Expand Down Expand Up @@ -834,6 +854,8 @@ rb_grn_init_column (VALUE mGrn)
/* deprecated: backward compatibility */
rb_define_alias(rb_cGrnColumn, "index_column?", "index?");
rb_define_method(rb_cGrnColumn, "vector?", rb_grn_column_vector_p, 0);
rb_define_method(rb_cGrnColumn, "weight_vector?",
rb_grn_column_weight_vector_p, 0);
rb_define_method(rb_cGrnColumn, "scalar?", rb_grn_column_scalar_p, 0);

rb_define_method(rb_cGrnColumn, "with_weight?",
Expand Down
6 changes: 6 additions & 0 deletions test/test-fix-size-column.rb
Expand Up @@ -128,6 +128,12 @@ def test_vector?
assert_not_predicate(@n_viewed, :vector?)
end

def test_weight_vector?
assert do
not @n_viewed.weight_vector?
end
end

def test_scalar?
assert_predicate(@n_viewed, :scalar?)
end
Expand Down
6 changes: 6 additions & 0 deletions test/test-index-column.rb
Expand Up @@ -48,6 +48,12 @@ def test_vector?
assert_not_predicate(@index, :vector?)
end

def test_weight_vector?
assert do
not @index.weight_vector?
end
end

def test_scalar?
assert_not_predicate(@index, :scalar?)
end
Expand Down
13 changes: 13 additions & 0 deletions test/test-variable-size-column.rb
Expand Up @@ -46,6 +46,13 @@ def setup_users_table
@users.define_column("nick_names", "ShortText",
:type => :vector,
:path => @users_nick_names_column_path.to_s)

@users_tags_column_path = @columns_dir + "tags"
@tags =
@users.define_column("tags", "ShortText",
:type => :vector,
:with_weight => true,
:path => @users_tags_column_path.to_s)
end

def setup_users
Expand All @@ -62,6 +69,12 @@ def test_vector?
assert_predicate(@nick_names, :vector?)
end

def test_weigth_vector?
assert do
@tags.weight_vector?
end
end

def test_scalar?
assert_not_predicate(@nick_names, :scalar?)
end
Expand Down

0 comments on commit 2e9786d

Please sign in to comment.