Kouhei Sutou
null+****@clear*****
Tue Oct 20 12:37:25 JST 2015
Kouhei Sutou 2015-10-20 12:37:25 +0900 (Tue, 20 Oct 2015) New Revision: 9056bb22372af865ea956e2bc2e22667ffe2d996 https://github.com/groonga/groonga/commit/9056bb22372af865ea956e2bc2e22667ffe2d996 Message: Add grn_obj_is_token_filter_proc() Modified files: include/groonga/obj.h lib/obj.c test/unit/core/test-object.c Modified: include/groonga/obj.h (+1 -0) =================================================================== --- include/groonga/obj.h 2015-10-20 12:37:01 +0900 (6e1e4a4) +++ include/groonga/obj.h 2015-10-20 12:37:25 +0900 (14a4ead) @@ -32,6 +32,7 @@ GRN_API grn_bool grn_obj_is_function_proc(grn_ctx *ctx, grn_obj *obj); GRN_API grn_bool grn_obj_is_selector_proc(grn_ctx *ctx, grn_obj *obj); GRN_API grn_bool grn_obj_is_selector_only_proc(grn_ctx *ctx, grn_obj *obj); GRN_API grn_bool grn_obj_is_normalizer_proc(grn_ctx *ctx, grn_obj *obj); +GRN_API grn_bool grn_obj_is_token_filter_proc(grn_ctx *ctx, grn_obj *obj); GRN_API grn_bool grn_obj_is_scorer_proc(grn_ctx *ctx, grn_obj *obj); GRN_API grn_rc grn_obj_cast(grn_ctx *ctx, Modified: lib/obj.c (+13 -0) =================================================================== --- lib/obj.c 2015-10-20 12:37:01 +0900 (39c9818) +++ lib/obj.c 2015-10-20 12:37:25 +0900 (feb1d1b) @@ -142,6 +142,19 @@ grn_obj_is_normalizer_proc(grn_ctx *ctx, grn_obj *obj) } grn_bool +grn_obj_is_token_filter_proc(grn_ctx *ctx, grn_obj *obj) +{ + grn_proc *proc; + + if (!grn_obj_is_proc(ctx, obj)) { + return GRN_FALSE; + } + + proc = (grn_proc *)obj; + return proc->type == GRN_PROC_TOKEN_FILTER; +} + +grn_bool grn_obj_is_scorer_proc(grn_ctx *ctx, grn_obj *obj) { grn_proc *proc; Modified: test/unit/core/test-object.c (+36 -0) =================================================================== --- test/unit/core/test-object.c 2015-10-20 12:37:01 +0900 (8982ff8) +++ test/unit/core/test-object.c 2015-10-20 12:37:25 +0900 (c82a6f7) @@ -41,6 +41,8 @@ void data_is_selector_proc(void); void test_is_selector_proc(gconstpointer data); void data_is_normalizer_proc(void); void test_is_normalizer_proc(gconstpointer data); +void data_is_token_filter_proc(void); +void test_is_token_filter_proc(gconstpointer data); void data_is_scorer_proc(void); void test_is_scorer_proc(gconstpointer data); @@ -364,6 +366,40 @@ test_is_normalizer_proc(gconstpointer data) } void +data_is_token_filter_proc(void) +{ +#define ADD_DATUM(expected, name) \ + gcut_add_datum((expected ? \ + "token-filter-proc - " name : \ + "not token-filter-proc - " name), \ + "expected", G_TYPE_BOOLEAN, expected, \ + "name", G_TYPE_STRING, name, \ + NULL) + + ADD_DATUM(TRUE, "TokenFilterStopWord"); + ADD_DATUM(FALSE, "TokenBigram"); + +#undef ADD_DATUM +} + +void +test_is_token_filter_proc(gconstpointer data) +{ + const gchar *name; + grn_obj *object; + + assert_send_command("plugin_register token_filters/stop_word"); + + name = gcut_data_get_string(data, "name"); + object = grn_ctx_get(context, name, strlen(name)); + if (gcut_data_get_string(data, "expected")) { + cut_assert_true(grn_obj_is_token_filter_proc(context, object)); + } else { + cut_assert_false(grn_obj_is_token_filter_proc(context, object)); + } +} + +void data_is_scorer_proc(void) { #define ADD_DATUM(expected, name) \ -------------- next part -------------- HTML����������������������������...Download