Kouhei Sutou
null+****@clear*****
Fri Apr 13 17:43:56 JST 2018
Kouhei Sutou 2018-04-13 17:43:56 +0900 (Fri, 13 Apr 2018) New Revision: d190dd3159eb079b6045ccfdddca7d5037dc6c75 https://github.com/groonga/groonga/commit/d190dd3159eb079b6045ccfdddca7d5037dc6c75 Message: table_create: support normalizer with options It has a memory leak. Added files: test/command/suite/table_create/normalizer/nfkc100/options/one.expected test/command/suite/table_create/normalizer/nfkc100/options/one.test Modified files: lib/proc/proc_table.c test/command/suite/table_create/normalizer/nonexistent.expected Modified: lib/proc/proc_table.c (+10 -14) =================================================================== --- lib/proc/proc_table.c 2018-04-12 10:40:43 +0900 (d8d8642c2) +++ lib/proc/proc_table.c 2018-04-13 17:43:56 +0900 (be92d8a30) @@ -198,7 +198,7 @@ command_table_create(grn_ctx *ctx, grn_raw_string key_type_raw; grn_raw_string value_type_raw; grn_obj *default_tokenizer_raw; - grn_raw_string normalizer_raw; + grn_obj *normalizer_raw; grn_raw_string token_filters_raw; grn_obj *table; const char *rest; @@ -218,7 +218,7 @@ command_table_create(grn_ctx *ctx, GET_VALUE(value_type); default_tokenizer_raw = grn_plugin_proc_get_var(ctx, user_data, "default_tokenizer", -1); - GET_VALUE(normalizer); + normalizer_raw = grn_plugin_proc_get_var(ctx, user_data, "normalizer", -1); GET_VALUE(token_filters); #undef GET_VALUE @@ -307,24 +307,20 @@ command_table_create(grn_ctx *ctx, } } - if (normalizer_raw.length > 0) { - grn_obj *normalizer; - - normalizer = grn_ctx_get(ctx, - normalizer_raw.value, - normalizer_raw.length); - if (!normalizer) { + if (GRN_TEXT_LEN(normalizer_raw) > 0) { + grn_obj_set_info(ctx, table, GRN_INFO_NORMALIZER, normalizer_raw); + if (ctx->rc != GRN_SUCCESS) { GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, - "[table][create][%.*s] unknown normalizer: <%.*s>", + "[table][create][%.*s] " + "failed to set normalizer: <%.*s>: %s", (int)name_raw.length, name_raw.value, - (int)normalizer_raw.length, - normalizer_raw.value); + (int)GRN_TEXT_LEN(normalizer_raw), + GRN_TEXT_VALUE(normalizer_raw), + ctx->errbuf); goto exit; } - grn_obj_set_info(ctx, table, GRN_INFO_NORMALIZER, normalizer); - grn_obj_unlink(ctx, normalizer); } if (!grn_proc_table_set_token_filters(ctx, table, &token_filters_raw)) { Added: test/command/suite/table_create/normalizer/nfkc100/options/one.expected (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/table_create/normalizer/nfkc100/options/one.expected 2018-04-13 17:43:56 +0900 (20f3ac9eb) @@ -0,0 +1,16 @@ +table_create Memos TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Memos content COLUMN_SCALAR Text +[[0,0.0,0.0],true] +table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer 'NormalizerNFKC100("unify_kana", true)' +[[0,0.0,0.0],true] +column_create Terms memos_content COLUMN_INDEX Memos content +[[0,0.0,0.0],true] +load --table Memos +[ +{"content": "リンゴ"}, +{"content": "りんご"} +] +[[0,0.0,0.0],2] +select Terms --output_columns _key --limit -1 +[[0,0.0,0.0],[[[3],[["_key","ShortText"]],["ご"],["りん"],["んご"]]]] Added: test/command/suite/table_create/normalizer/nfkc100/options/one.test (+15 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/table_create/normalizer/nfkc100/options/one.test 2018-04-13 17:43:56 +0900 (5cd4b1a62) @@ -0,0 +1,15 @@ +table_create Memos TABLE_NO_KEY +column_create Memos content COLUMN_SCALAR Text + +table_create Terms TABLE_PAT_KEY ShortText \ + --default_tokenizer TokenBigram \ + --normalizer 'NormalizerNFKC100("unify_kana", true)' +column_create Terms memos_content COLUMN_INDEX Memos content + +load --table Memos +[ +{"content": "リンゴ"}, +{"content": "りんご"} +] + +select Terms --output_columns _key --limit -1 Modified: test/command/suite/table_create/normalizer/nonexistent.expected (+3 -2) =================================================================== --- test/command/suite/table_create/normalizer/nonexistent.expected 2018-04-12 10:40:43 +0900 (a00cfb5a4) +++ test/command/suite/table_create/normalizer/nonexistent.expected 2018-04-13 17:43:56 +0900 (a49db0b2e) @@ -6,9 +6,10 @@ table_create Terms TABLE_PAT_KEY ShortText --normalizer NormalizerNonexistent 0.0, 0.0 ], - "[table][create][Terms] unknown normalizer: <NormalizerNonexistent>" + "[table][create][Terms] failed to set normalizer: <NormalizerNonexistent>: [info][set][normalizer][Terms] unknown normalizer: <N" ], false ] -#|e| [table][create][Terms] unknown normalizer: <NormalizerNonexistent> +#|e| [info][set][normalizer][Terms] unknown normalizer: <NormalizerNonexistent> +#|e| [table][create][Terms] failed to set normalizer: <NormalizerNonexistent>: [info][set][normalizer][Terms] unknown normalizer: <NormalizerNonexistent> dump -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180413/547f18a9/attachment-0001.htm