-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bind grn_column_get_all_index_data()
GitHub: #116 TODO: Add multiple indexes test.
- Loading branch information
Masafumi Yokoyama
committed
Mar 5, 2016
1 parent
947b49c
commit 7707a5e
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 |