Naoya Murakami
null+****@clear*****
Sun Jun 12 07:58:32 JST 2016
Naoya Murakami 2016-06-12 07:58:32 +0900 (Sun, 12 Jun 2016) New Revision: 1e0bfe4fe959a6e54ee299c6d7a426c2120ec39e https://github.com/groonga/groonga/commit/1e0bfe4fe959a6e54ee299c6d7a426c2120ec39e Merged a5e3d15: Merge pull request #553 from naoa/fuzzysearch-non-object-literal-option Message: proc fuzzy_search: support max_distance option with non object literal option Copied files: test/command/suite/select/function/fuzzy_search/max_distance.expected (from test/command/suite/select/function/fuzzy_search/pat/max_expansion.expected) test/command/suite/select/function/fuzzy_search/max_distance.test (from test/command/suite/select/function/fuzzy_search/pat/max_distance.test) Modified files: lib/proc/proc_fuzzy_search.c Renamed files: test/command/suite/select/function/fuzzy_search/object_literal/max_distance.expected (from test/command/suite/select/function/fuzzy_search/pat/max_distance.expected) test/command/suite/select/function/fuzzy_search/object_literal/max_distance.test (from test/command/suite/select/function/fuzzy_search/pat/max_distance.test) test/command/suite/select/function/fuzzy_search/object_literal/max_expansion.expected (from test/command/suite/select/function/fuzzy_search/pat/max_expansion.expected) test/command/suite/select/function/fuzzy_search/object_literal/max_expansion.test (from test/command/suite/select/function/fuzzy_search/pat/max_expansion.test) test/command/suite/select/function/fuzzy_search/object_literal/prefix_length.expected (from test/command/suite/select/function/fuzzy_search/pat/prefix_length.expected) test/command/suite/select/function/fuzzy_search/object_literal/prefix_length.test (from test/command/suite/select/function/fuzzy_search/pat/prefix_length.test) test/command/suite/select/function/fuzzy_search/object_literal/prefix_length_ja.expected (from test/command/suite/select/function/fuzzy_search/pat/prefix_length_ja.expected) test/command/suite/select/function/fuzzy_search/object_literal/prefix_length_ja.test (from test/command/suite/select/function/fuzzy_search/pat/prefix_length_ja.test) test/command/suite/select/function/fuzzy_search/object_literal/transposition.expected (from test/command/suite/select/function/fuzzy_search/pat/transposition.expected) test/command/suite/select/function/fuzzy_search/object_literal/transposition.test (from test/command/suite/select/function/fuzzy_search/pat/transposition.test) Modified: lib/proc/proc_fuzzy_search.c (+45 -38) =================================================================== --- lib/proc/proc_fuzzy_search.c 2016-06-10 23:53:24 +0900 (7d2ab40) +++ lib/proc/proc_fuzzy_search.c 2016-06-12 07:58:32 +0900 (f38114a) @@ -315,51 +315,58 @@ selector_fuzzy_search(grn_ctx *ctx, grn_obj *table, grn_obj *index, if (nargs == 4) { grn_obj *options = args[3]; - grn_hash_cursor *cursor; - void *key; - grn_obj *value; - int key_size; - if (options->header.type != GRN_TABLE_HASH_KEY) { + switch (options->header.type) { + case GRN_BULK : + max_distance = GRN_UINT32_VALUE(options); + break; + case GRN_TABLE_HASH_KEY : + { + grn_hash_cursor *cursor; + void *key; + grn_obj *value; + int key_size; + cursor = grn_hash_cursor_open(ctx, (grn_hash *)options, + NULL, 0, NULL, 0, + 0, -1, 0); + if (!cursor) { + GRN_PLUGIN_ERROR(ctx, GRN_NO_MEMORY_AVAILABLE, + "fuzzy_search(): couldn't open cursor"); + goto exit; + } + while (grn_hash_cursor_next(ctx, cursor) != GRN_ID_NIL) { + grn_hash_cursor_get_key_value(ctx, cursor, &key, &key_size, + (void **)&value); + + if (key_size == 12 && !memcmp(key, "max_distance", 12)) { + max_distance = GRN_UINT32_VALUE(value); + } else if (key_size == 13 && !memcmp(key, "prefix_length", 13)) { + prefix_length = GRN_UINT32_VALUE(value); + } else if (key_size == 13 && !memcmp(key, "max_expansion", 13)) { + max_expansion = GRN_UINT32_VALUE(value); + } else if (key_size == 18 && !memcmp(key, "with_transposition", 18)) { + if (GRN_BOOL_VALUE(value)) { + flags |= GRN_TABLE_FUZZY_SEARCH_WITH_TRANSPOSITION; + } + } else { + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "invalid option name: <%.*s>", + key_size, (char *)key); + grn_hash_cursor_close(ctx, cursor); + goto exit; + } + } + grn_hash_cursor_close(ctx, cursor); + } + break; + default : GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, "fuzzy_search(): " - "3rd argument must be object literal: <%.*s>", + "3rd argument must be integer or object literal: <%.*s>", (int)GRN_TEXT_LEN(options), GRN_TEXT_VALUE(options)); goto exit; } - - cursor = grn_hash_cursor_open(ctx, (grn_hash *)options, - NULL, 0, NULL, 0, - 0, -1, 0); - if (!cursor) { - GRN_PLUGIN_ERROR(ctx, GRN_NO_MEMORY_AVAILABLE, - "fuzzy_search(): couldn't open cursor"); - goto exit; - } - while (grn_hash_cursor_next(ctx, cursor) != GRN_ID_NIL) { - grn_hash_cursor_get_key_value(ctx, cursor, &key, &key_size, - (void **)&value); - - if (key_size == 12 && !memcmp(key, "max_distance", 12)) { - max_distance = GRN_UINT32_VALUE(value); - } else if (key_size == 13 && !memcmp(key, "prefix_length", 13)) { - prefix_length = GRN_UINT32_VALUE(value); - } else if (key_size == 13 && !memcmp(key, "max_expansion", 13)) { - max_expansion = GRN_UINT32_VALUE(value); - } else if (key_size == 18 && !memcmp(key, "with_transposition", 18)) { - if (GRN_BOOL_VALUE(value)) { - flags |= GRN_TABLE_FUZZY_SEARCH_WITH_TRANSPOSITION; - } - } else { - GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, - "invalid option name: <%.*s>", - key_size, (char *)key); - grn_hash_cursor_close(ctx, cursor); - goto exit; - } - } - grn_hash_cursor_close(ctx, cursor); } if (index) { Copied: test/command/suite/select/function/fuzzy_search/max_distance.expected (+2 -2) 70% =================================================================== --- test/command/suite/select/function/fuzzy_search/pat/max_expansion.expected 2016-06-10 23:53:24 +0900 (a5da1ab) +++ test/command/suite/select/function/fuzzy_search/max_distance.expected 2016-06-12 07:58:32 +0900 (90e30b7) @@ -13,5 +13,5 @@ load --table Users {"name": "Ken"} ] [[0,0.0,0.0],3] -select Tags --filter 'fuzzy_search(_key, "To", {"max_distance": 2, "max_expansion": 1})' --output_columns '_key, _score' --match_escalation_threshold -1 -[[0,0.0,0.0],[[[1],[["_key","ShortText"],["_score","Int32"]],["Tom",2]]]] +select Tags --filter 'fuzzy_search(_key, "To", 1)' --output_columns '_key, _score' +[[0,0.0,0.0],[[[1],[["_key","ShortText"],["_score","Int32"]],["Tom",1]]]] Copied: test/command/suite/select/function/fuzzy_search/max_distance.test (+2 -3) 63% =================================================================== --- test/command/suite/select/function/fuzzy_search/pat/max_distance.test 2016-06-10 23:53:24 +0900 (7b2bdc9) +++ test/command/suite/select/function/fuzzy_search/max_distance.test 2016-06-12 07:58:32 +0900 (dd84fbe) @@ -11,6 +11,5 @@ load --table Users {"name": "Ken"} ] -select Tags --filter 'fuzzy_search(_key, "To", {"max_distance": 2})' \ - --output_columns '_key, _score' \ - --match_escalation_threshold -1 +select Tags --filter 'fuzzy_search(_key, "To", 1)' \ + --output_columns '_key, _score' Renamed: test/command/suite/select/function/fuzzy_search/object_literal/max_distance.expected (+0 -0) 100% =================================================================== Renamed: test/command/suite/select/function/fuzzy_search/object_literal/max_distance.test (+0 -0) 100% =================================================================== Renamed: test/command/suite/select/function/fuzzy_search/object_literal/max_expansion.expected (+0 -0) 100% =================================================================== Renamed: test/command/suite/select/function/fuzzy_search/object_literal/max_expansion.test (+0 -0) 100% =================================================================== Renamed: test/command/suite/select/function/fuzzy_search/object_literal/prefix_length.expected (+0 -0) 100% =================================================================== Renamed: test/command/suite/select/function/fuzzy_search/object_literal/prefix_length.test (+0 -0) 100% =================================================================== Renamed: test/command/suite/select/function/fuzzy_search/object_literal/prefix_length_ja.expected (+0 -0) 100% =================================================================== Renamed: test/command/suite/select/function/fuzzy_search/object_literal/prefix_length_ja.test (+0 -0) 100% =================================================================== Renamed: test/command/suite/select/function/fuzzy_search/object_literal/transposition.expected (+0 -0) 100% =================================================================== Renamed: test/command/suite/select/function/fuzzy_search/object_literal/transposition.test (+0 -0) 100% =================================================================== -------------- next part -------------- HTML����������������������������...Download