Kouhei Sutou 2018-10-29 15:44:07 +0900 (Mon, 29 Oct 2018) Revision: cc090d7227f887a3ad7fc1150f3ddf60946432f6 https://github.com/groonga/groonga/commit/cc090d7227f887a3ad7fc1150f3ddf60946432f6 Message: Support parsing token filter options TODO: Support multiple token filters. Modified files: lib/expr.c lib/grn_expr.h lib/proc/proc_table.c Modified: lib/expr.c (+80 -1) =================================================================== --- lib/expr.c 2018-10-29 15:42:32 +0900 (0a6846b5a) +++ lib/expr.c 2018-10-29 15:44:07 +0900 (5490f471b) @@ -997,7 +997,8 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op, grn_obj_is_scorer_proc(ctx, proc) || grn_obj_is_window_function_proc(ctx, proc) || grn_obj_is_tokenizer_proc(ctx, proc) || - grn_obj_is_normalizer_proc(ctx, proc))) { + grn_obj_is_normalizer_proc(ctx, proc) || + grn_obj_is_token_filter_proc(ctx, proc))) { grn_obj buffer; GRN_TEXT_INIT(&buffer, 0); @@ -7599,3 +7600,81 @@ grn_expr_simple_function_call_get_arguments(grn_ctx *ctx, return GRN_SUCCESS; } + +/* TODO: Support multiple calls. */ +grn_bool +grn_expr_is_simple_function_calls(grn_ctx *ctx, grn_obj *expr) +{ + grn_expr *e = (grn_expr *)expr; + grn_expr_code *codes = e->codes; + grn_expr_code *codes_end = codes + e->codes_curr; + + if (codes == codes_end) { + return GRN_FALSE; + } + + for (; codes < codes_end; codes++) { + switch (codes[0].op) { + case GRN_OP_PUSH : + break; + case GRN_OP_CALL : + if (codes + 1 != codes_end) { + return GRN_FALSE; + } + break; + default : + return GRN_FALSE; + } + } + + return GRN_TRUE; +} + +/* TODO: Support multiple calls. */ +unsigned int +grn_expr_simple_function_calls_get_n_calls(grn_ctx *ctx, grn_obj *expr) +{ + return 1; +} + +/* TODO: Support multiple calls. */ +grn_obj * +grn_expr_simple_function_calls_get_function(grn_ctx *ctx, + grn_obj *expr, + unsigned int i) +{ + grn_expr *e = (grn_expr *)expr; + + return e->codes[0].value; +} + +/* TODO: Support multiple calls. */ +grn_rc +grn_expr_simple_function_calls_get_arguments(grn_ctx *ctx, + grn_obj *expr, + unsigned int i, + grn_obj *arguments) +{ + grn_expr *e = (grn_expr *)expr; + grn_expr_code *codes = e->codes; + grn_expr_code *codes_end = codes + e->codes_curr; + + for (codes++; codes < codes_end - 1; codes++) { + grn_obj *value = codes[0].value; + switch (codes[0].op) { + case GRN_OP_PUSH : + grn_vector_add_element(ctx, + arguments, + GRN_BULK_HEAD(value), + GRN_BULK_VSIZE(value), + 0, + value->header.domain); + break; + default : + return GRN_INVALID_ARGUMENT; + break; + } + } + + return GRN_SUCCESS; +} Modified: lib/grn_expr.h (+12 -0) =================================================================== --- lib/grn_expr.h 2018-10-29 15:42:32 +0900 (d0fefc4ce) +++ lib/grn_expr.h 2018-10-29 15:44:07 +0900 (95e0ac64a) @@ -1,6 +1,7 @@ /* -*- c-basic-offset: 2 -*- */ /* Copyright(C) 2013-2018 Brazil + Copyright(C) 2018 Kouhei Sutou <kou****@clear*****> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -125,6 +126,17 @@ grn_rc grn_expr_simple_function_call_get_arguments(grn_ctx *ctx, grn_obj *expr, grn_obj *arguments); +grn_bool grn_expr_is_simple_function_calls(grn_ctx *ctx, grn_obj *expr); +unsigned int grn_expr_simple_function_calls_get_n_calls(grn_ctx *ctx, + grn_obj *expr); +grn_obj *grn_expr_simple_function_calls_get_function(grn_ctx *ctx, + grn_obj *expr, + unsigned int i); +grn_rc grn_expr_simple_function_calls_get_arguments(grn_ctx *ctx, + grn_obj *expr, + unsigned int i, + grn_obj *arguments); + #ifdef __cplusplus } #endif Modified: lib/proc/proc_table.c (+7 -105) =================================================================== --- lib/proc/proc_table.c 2018-10-29 15:42:32 +0900 (ac27b8894) +++ lib/proc/proc_table.c 2018-10-29 15:44:07 +0900 (11a6d4404) @@ -67,103 +67,6 @@ command_table_create_parse_flags(grn_ctx *ctx, return flags; } -static grn_bool -grn_proc_table_set_token_filters_put(grn_ctx *ctx, - grn_obj *token_filters, - const char *token_filter_name, - int token_filter_name_length) -{ - grn_obj *token_filter; - - token_filter = grn_ctx_get(ctx, - token_filter_name, - token_filter_name_length); - if (token_filter) { - GRN_PTR_PUT(ctx, token_filters, token_filter); - return GRN_TRUE; - } else { - GRN_PLUGIN_ERROR(ctx, - GRN_INVALID_ARGUMENT, - "[table][create][token-filter] " - "nonexistent token filter: <%.*s>", - token_filter_name_length, token_filter_name); - return GRN_FALSE; - } -} - -static grn_bool -grn_proc_table_set_token_filters_fill(grn_ctx *ctx, - grn_obj *token_filters, - grn_raw_string *token_filters_raw) -{ - const char *start, *current, *end; - const char *name_start, *name_end; - const char *last_name_end; - - start = token_filters_raw->value; - end = start + token_filters_raw->length; - current = start; - name_start = NULL; - name_end = NULL; - last_name_end = start; - while (current < end) { - switch (current[0]) { - case ' ' : - if (name_start && !name_end) { - name_end = current; - } - break; - case ',' : - if (!name_start) { - goto break_loop; - } - if (!name_end) { - name_end = current; - } - if (!grn_proc_table_set_token_filters_put(ctx, - token_filters, - name_start, - name_end - name_start)) { - return GRN_FALSE; - } - last_name_end = name_end + 1; - name_start = NULL; - name_end = NULL; - break; - default : - if (!name_start) { - name_start = current; - } - break; - } - current++; - } - -break_loop: - if (!name_start) { - GRN_PLUGIN_ERROR(ctx, - GRN_INVALID_ARGUMENT, - "[table][create][token-filter] empty token filter name: " - "<%.*s|%.*s|%.*s>", - (int)(last_name_end - start), start, - (int)(current - last_name_end), last_name_end, - (int)(end - current), current); - return GRN_FALSE; - } - - if (!name_end) { - name_end = current; - } - if (!grn_proc_table_set_token_filters_put(ctx, - token_filters, - name_start, - name_end - name_start)) { - return GRN_FALSE; - } - - return GRN_TRUE; -} - grn_bool grn_proc_table_set_token_filters(grn_ctx *ctx, grn_obj *table, @@ -176,14 +79,13 @@ grn_proc_table_set_token_filters(grn_ctx *ctx, return GRN_TRUE; } - GRN_PTR_INIT(&token_filters, GRN_OBJ_VECTOR, 0); - succeeded = grn_proc_table_set_token_filters_fill(ctx, - &token_filters, - token_filters_raw); - if (succeeded) { - grn_obj_set_info(ctx, table, GRN_INFO_TOKEN_FILTERS, &token_filters); - } - grn_obj_unlink(ctx, &token_filters); + GRN_TEXT_INIT(&token_filters, GRN_OBJ_DO_SHALLOW_COPY); + GRN_TEXT_SET(ctx, + &token_filters, + token_filters_raw->value, + token_filters_raw->length); + grn_obj_set_info(ctx, table, GRN_INFO_TOKEN_FILTERS, &token_filters); + GRN_OBJ_FIN(ctx, &token_filters); return succeeded; } -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181029/9e23d609/attachment-0001.html>