Kouhei Sutou
null+****@clear*****
Wed Apr 19 16:32:12 JST 2017
Kouhei Sutou 2017-04-19 16:32:12 +0900 (Wed, 19 Apr 2017) New Revision: cd72ce3e338a3ac7fcb5198f86d6ba3db2365896 https://github.com/groonga/groonga/commit/cd72ce3e338a3ac7fcb5198f86d6ba3db2365896 Message: proc: export mode parse function internally Modified files: lib/grn_proc.h lib/proc.c Modified: lib/grn_proc.h (+5 -0) =================================================================== --- lib/grn_proc.h 2017-04-19 15:41:04 +0900 (9792938) +++ lib/grn_proc.h 2017-04-19 16:32:12 +0900 (47eb487) @@ -85,6 +85,11 @@ const char *grn_proc_option_value_string(grn_ctx *ctx, grn_content_type grn_proc_option_value_content_type(grn_ctx *ctx, grn_obj *option, grn_content_type default_value); +grn_operator grn_proc_option_value_mode(grn_ctx *ctx, + grn_obj *option, + grn_operator default_mode, + const char *context); + void grn_proc_output_object_name(grn_ctx *ctx, grn_obj *obj); void grn_proc_output_object_id_name(grn_ctx *ctx, grn_id id); Modified: lib/proc.c (+19 -9) =================================================================== --- lib/proc.c 2017-04-19 15:41:04 +0900 (f253c77) +++ lib/proc.c 2017-04-19 16:32:12 +0900 (c323340) @@ -1781,13 +1781,16 @@ selector_to_function_data_fin(grn_ctx *ctx, } } -static grn_operator -parse_mode(grn_ctx *ctx, grn_obj *mode, const char *context) +grn_operator +grn_proc_option_value_mode(grn_ctx *ctx, + grn_obj *option, + grn_operator default_mode, + const char *context) { - if (mode->header.domain != GRN_DB_TEXT) { + if (option->header.domain != GRN_DB_TEXT) { grn_obj inspected; GRN_TEXT_INIT(&inspected, 0); - grn_inspect(ctx, &inspected, mode); + grn_inspect(ctx, &inspected, option); GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, "%s: mode must be text: <%.*s>", context, @@ -1797,9 +1800,13 @@ parse_mode(grn_ctx *ctx, grn_obj *mode, const char *context) return GRN_OP_NOP; } + if (GRN_TEXT_LEN(option) == 0) { + return default_mode; + } + #define EQUAL_MODE(name) \ - (GRN_TEXT_LEN(mode) == strlen(name) && \ - memcmp(GRN_TEXT_VALUE(mode), name, strlen(name)) == 0) + (GRN_TEXT_LEN(option) == strlen(name) && \ + memcmp(GRN_TEXT_VALUE(option), name, strlen(name)) == 0) if (EQUAL_MODE("==") || EQUAL_MODE("EQUAL")) { return GRN_OP_EQUAL; @@ -1843,8 +1850,8 @@ parse_mode(grn_ctx *ctx, grn_obj *mode, const char *context) "\"~\", \"@~\", \"REGEXP\"" "]: <%.*s>", context, - (int)GRN_TEXT_LEN(mode), - GRN_TEXT_VALUE(mode)); + (int)GRN_TEXT_LEN(option), + GRN_TEXT_VALUE(option)); return GRN_OP_NOP; } @@ -1907,7 +1914,10 @@ run_query(grn_ctx *ctx, grn_obj *table, if (KEY_EQUAL("expander")) { query_expander_name = value; } else if (KEY_EQUAL("default_mode")) { - default_mode = parse_mode(ctx, value, "query()"); + default_mode = grn_proc_option_value_mode(ctx, + value, + GRN_OP_MATCH, + "query()"); if (ctx->rc != GRN_SUCCESS) { grn_hash_cursor_close(ctx, cursor); rc = ctx->rc; -------------- next part -------------- HTML����������������������������... Download