Kouhei Sutou
null+****@clear*****
Sun Jun 8 14:04:38 JST 2014
Kouhei Sutou 2014-06-08 14:04:38 +0900 (Sun, 08 Jun 2014) New Revision: 0112ea02b0753b3b5b168ace909435994c5fb201 https://github.com/ranguba/rroonga/commit/0112ea02b0753b3b5b168ace909435994c5fb201 Message: Support grn_proc_get_type() Added files: ext/groonga/rb-grn-procedure-type.c Modified files: ext/groonga/rb-grn-procedure.c ext/groonga/rb-grn.h ext/groonga/rb-groonga.c test/test-procedure.rb Added: ext/groonga/rb-grn-procedure-type.c (+40 -0) 100644 =================================================================== --- /dev/null +++ ext/groonga/rb-grn-procedure-type.c 2014-06-08 14:04:38 +0900 (78059c3) @@ -0,0 +1,40 @@ +/* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + Copyright (C) 2014 Kouhei Sutou <kou �� 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 + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "rb-grn.h" + +void +rb_grn_init_procedure_type (VALUE mGrn) +{ + VALUE rb_mGrnProcedureType; + + rb_mGrnProcedureType = rb_define_module_under(mGrn, "ProcedureType"); + + rb_define_const(rb_mGrnProcedureType, + "INVALID", INT2NUM(GRN_PROC_INVALID)); + rb_define_const(rb_mGrnProcedureType, + "TOKENIZER", INT2NUM(GRN_PROC_TOKENIZER)); + rb_define_const(rb_mGrnProcedureType, + "COMMAND", INT2NUM(GRN_PROC_COMMAND)); + rb_define_const(rb_mGrnProcedureType, + "FUNCTION", INT2NUM(GRN_PROC_FUNCTION)); + rb_define_const(rb_mGrnProcedureType, + "HOOK", INT2NUM(GRN_PROC_HOOK)); + rb_define_const(rb_mGrnProcedureType, + "NORMALIZER", INT2NUM(GRN_PROC_NORMALIZER)); +} Modified: ext/groonga/rb-grn-procedure.c (+16 -3) =================================================================== --- ext/groonga/rb-grn-procedure.c 2014-06-04 12:32:40 +0900 (fe8a0b5) +++ ext/groonga/rb-grn-procedure.c 2014-06-08 14:04:38 +0900 (b956709) @@ -1,6 +1,6 @@ /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - Copyright (C) 2009 Kouhei Sutou <kou �� clear-code.com> + Copyright (C) 2009-2014 Kouhei Sutou <kou �� 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 @@ -18,8 +18,6 @@ #include "rb-grn.h" -#define SELF(object) (RVAL2GRNPROCEDURE(object)) - VALUE rb_cGrnProcedure; grn_obj * @@ -39,6 +37,19 @@ rb_grn_procedure_to_ruby_object (grn_ctx *context, grn_obj *procedure, return GRNOBJECT2RVAL(rb_cGrnProcedure, context, procedure, owner); } +static VALUE +rb_grn_procedure_get_type (VALUE self) +{ + grn_ctx *context; + grn_obj *procedure; + grn_proc_type type; + + procedure = RVAL2GRNOBJECT(self, &context); + type = grn_proc_get_type(context, procedure); + + return INT2NUM(type); +} + void rb_grn_init_procedure (VALUE mGrn) { @@ -49,4 +60,6 @@ rb_grn_init_procedure (VALUE mGrn) rb_define_const(rb_cGrnProcedure, "BIGRAM", INT2NUM(GRN_DB_BIGRAM)); rb_define_const(rb_cGrnProcedure, "TRIGRAM", INT2NUM(GRN_DB_TRIGRAM)); rb_define_const(rb_cGrnProcedure, "MECAB", INT2NUM(GRN_DB_MECAB)); + + rb_define_method(rb_cGrnProcedure, "type", rb_grn_procedure_get_type, 0); } Modified: ext/groonga/rb-grn.h (+1 -0) =================================================================== --- ext/groonga/rb-grn.h 2014-06-04 12:32:40 +0900 (4eca87f) +++ ext/groonga/rb-grn.h 2014-06-08 14:04:38 +0900 (f872b07) @@ -288,6 +288,7 @@ void rb_grn_init_patricia_trie_cursor (VALUE mGrn); void rb_grn_init_double_array_trie_cursor (VALUE mGrn); void rb_grn_init_type (VALUE mGrn); void rb_grn_init_procedure (VALUE mGrn); +void rb_grn_init_procedure_type (VALUE mGrn); void rb_grn_init_column (VALUE mGrn); void rb_grn_init_fix_size_column (VALUE mGrn); void rb_grn_init_variable_size_column (VALUE mGrn); Modified: ext/groonga/rb-groonga.c (+2 -1) =================================================================== --- ext/groonga/rb-groonga.c 2014-06-04 12:32:40 +0900 (6deabc5) +++ ext/groonga/rb-groonga.c 2014-06-08 14:04:38 +0900 (a0fc4ae) @@ -1,6 +1,6 @@ /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - Copyright (C) 2009-2013 Kouhei Sutou <kou �� clear-code.com> + Copyright (C) 2009-2014 Kouhei Sutou <kou �� 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 @@ -175,6 +175,7 @@ Init_groonga (void) rb_grn_init_posting(mGrn); rb_grn_init_type(mGrn); rb_grn_init_procedure(mGrn); + rb_grn_init_procedure_type(mGrn); rb_grn_init_column(mGrn); rb_grn_init_accessor(mGrn); rb_grn_init_geo_point(mGrn); Modified: test/test-procedure.rb (+8 -1) =================================================================== --- test/test-procedure.rb 2014-06-04 12:32:40 +0900 (a011d10) +++ test/test-procedure.rb 2014-06-08 14:04:38 +0900 (d6a97db) @@ -1,4 +1,4 @@ -# Copyright (C) 2009 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2009-2014 Kouhei Sutou <kou �� 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 @@ -34,4 +34,11 @@ class ProcedureTest < Test::Unit::TestCase assert_equal(expected_name, procedure ? procedure.name : procedure) end + + class TypeTest < self + def test_tokenizer + tokenizer = Groonga["TokenBigram"] + assert_equal(Groonga::ProcedureType::TOKENIZER, tokenizer.type) + end + end end -------------- next part -------------- HTML����������������������������... ダウンロード