Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind grn_column_get_all_index_data() #120

Merged
merged 1 commit into from
Mar 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions ext/groonga/rb-grn-column.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* vim: set sts=4 sw=4 ts=8 noet: */
/*
Copyright (C) 2009-2015 Kouhei Sutou <[email protected]>
Copyright (C) 2016 Masafumi Yokoyama <[email protected]>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -753,6 +754,45 @@ rb_grn_column_get_indexes (int argc, VALUE *argv, VALUE self)
return rb_indexes;
}

/*
* 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
Expand Down Expand Up @@ -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);

Expand Down
33 changes: 33 additions & 0 deletions test/test-column.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (C) 2009-2013 Kouhei Sutou <[email protected]>
# Copyright (C) 2016 Masafumi Yokoyama <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -584,4 +585,36 @@ def test_indexed
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