Kouhei Sutou
null+****@clear*****
Fri Nov 11 17:52:38 JST 2016
Kouhei Sutou 2016-11-11 17:52:38 +0900 (Fri, 11 Nov 2016) New Revision: b7fc1915725e1c4b35556ca71e15dc0bcf282a96 https://github.com/groonga/groonga/commit/b7fc1915725e1c4b35556ca71e15dc0bcf282a96 Message: select: support query() selector in slices Added files: test/command/suite/select/slices/filtered/selector/prefix_rk_search.expected test/command/suite/select/slices/filtered/selector/prefix_rk_search.test Modified files: lib/proc.c Modified: lib/proc.c (+78 -15) =================================================================== --- lib/proc.c 2016-11-11 17:36:51 +0900 (496ab9e) +++ lib/proc.c 2016-11-11 17:52:38 +0900 (6ea095a) @@ -3249,23 +3249,14 @@ proc_reindex(grn_ctx *ctx, int nargs, grn_obj **args, } static grn_rc -selector_prefix_rk_search(grn_ctx *ctx, grn_obj *table, grn_obj *index, - int nargs, grn_obj **args, - grn_obj *res, grn_operator op) +selector_prefix_rk_search_raw(grn_ctx *ctx, + grn_obj *table, + grn_obj *column, + grn_obj *query, + grn_obj *res, + grn_operator op) { grn_rc rc = GRN_SUCCESS; - grn_obj *column; - grn_obj *query; - - if ((nargs - 1) != 2) { - ERR(GRN_INVALID_ARGUMENT, - "prefix_rk_serach(): wrong number of arguments (%d for 2)", nargs - 1); - rc = ctx->rc; - goto exit; - } - - column = args[1]; - query = args[2]; if (!grn_obj_is_key_accessor(ctx, column)) { grn_obj inspected_column; @@ -3329,6 +3320,78 @@ exit : return rc; } +static grn_rc +selector_prefix_rk_search(grn_ctx *ctx, + grn_obj *table, + grn_obj *index, + int nargs, + grn_obj **args, + grn_obj *res, + grn_operator op) +{ + grn_rc rc = GRN_SUCCESS; + grn_obj *column; + grn_obj *query; + + if ((nargs - 1) != 2) { + ERR(GRN_INVALID_ARGUMENT, + "prefix_rk_serach(): wrong number of arguments (%d for 2)", nargs - 1); + rc = ctx->rc; + goto exit; + } + + column = args[1]; + query = args[2]; + + if (column && + column->header.type == GRN_ACCESSOR && + ((grn_accessor *)column)->next) { + grn_obj *accessor = column; + unsigned int accessor_deep = 0; + grn_obj *base_table = NULL; + grn_obj *base_column = NULL; + grn_obj *base_res = NULL; + grn_accessor *a; + + for (a = (grn_accessor *)accessor; a; a = a->next) { + if (a->next) { + accessor_deep++; + } else { + base_column = (grn_obj *)a; + base_table = a->obj; + base_res = grn_table_create(ctx, NULL, 0, NULL, + GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, + base_table, NULL); + } + } + rc = selector_prefix_rk_search_raw(ctx, + base_table, + base_column, + query, + base_res, + GRN_OP_OR); + if (rc == GRN_SUCCESS) { + grn_accessor_resolve(ctx, + accessor, + accessor_deep, + base_res, + res, + op); + } + grn_obj_close(ctx, base_res); + } else { + rc = selector_prefix_rk_search_raw(ctx, + table, + column, + query, + res, + op); + } + +exit : + return rc; +} + #define DEF_VAR(v,name_str) do {\ (v).name = (name_str);\ (v).name_size = GRN_STRLEN(name_str);\ Added: test/command/suite/select/slices/filtered/selector/prefix_rk_search.expected (+62 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/slices/filtered/selector/prefix_rk_search.expected 2016-11-11 17:52:38 +0900 (99d7b33) @@ -0,0 +1,62 @@ +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +[[0,0.0,0.0],true] +load --table Readings +[ +{"_key": "グルンガ"}, +{"_key": "グルンパ"} +] +[[0,0.0,0.0],2] +log_level --level info +[[0,0.0,0.0],true] +select Readings --filter '_id > 1' --slices[key].filter 'prefix_rk_search(_key, "gur")' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ] + ], + [ + 2, + "グルンパ" + ] + ], + { + "key": [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ] + ], + [ + 2, + "グルンパ" + ] + ] + } + ] +] +#|i| [table][select][index][selector][no-index][prefix_rk_search] <> +#|i| [accessor][resolve][table] (temporary) -> <Readings> -> <ShortText> Added: test/command/suite/select/slices/filtered/selector/prefix_rk_search.test (+13 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/slices/filtered/selector/prefix_rk_search.test 2016-11-11 17:52:38 +0900 (53d417c) @@ -0,0 +1,13 @@ +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto + +load --table Readings +[ +{"_key": "グルンガ"}, +{"_key": "グルンパ"} +] + +log_level --level info +#@add-important-log-levels info +select Readings \ + --filter '_id > 1' \ + --slices[key].filter 'prefix_rk_search(_key, "gur")' -------------- next part -------------- HTML����������������������������... ダウンロード