Kouhei Sutou
null+****@clear*****
Tue Sep 8 11:36:56 JST 2015
Kouhei Sutou 2015-09-08 11:36:56 +0900 (Tue, 08 Sep 2015) New Revision: 572ed89fd820af9cba5df44c67e3765a8c4232f3 https://github.com/groonga/groonga/commit/572ed89fd820af9cba5df44c67e3765a8c4232f3 Message: regexp: make match target reference in vector normalized It's not incompatible change. Because reference vector wasn't supported yet. Added files: test/command/suite/select/filter/no_index/regexp/normalized_vector_reference.expected test/command/suite/select/filter/no_index/regexp/normalized_vector_reference.test Modified files: lib/operator.c Modified: lib/operator.c (+55 -0) =================================================================== --- lib/operator.c 2015-09-08 11:10:19 +0900 (459becd) +++ lib/operator.c 2015-09-08 11:36:56 +0900 (caacda2) @@ -1019,6 +1019,58 @@ grn_operator_exec_prefix(grn_ctx *ctx, grn_obj *target, grn_obj *prefix) } static grn_bool +exec_regexp_uvector_bulk(grn_ctx *ctx, grn_obj *uvector, grn_obj *pattern) +{ +#ifdef GRN_SUPPORT_REGEXP + grn_bool matched = GRN_FALSE; + unsigned int i, size; + OnigRegex regex; + grn_obj *domain; + + size = grn_uvector_size(ctx, uvector); + if (size == 0) { + return GRN_FALSE; + } + + regex = regexp_compile(ctx, GRN_TEXT_VALUE(pattern), GRN_TEXT_LEN(pattern)); + if (!regex) { + return GRN_FALSE; + } + + domain = grn_ctx_at(ctx, uvector->header.domain); + if (!domain) { + onig_free(regex); + return GRN_FALSE; + } + + for (i = 0; i < size; i++) { + grn_id record_id; + char key[GRN_TABLE_MAX_KEY_SIZE]; + int key_size; + + record_id = grn_uvector_get_element(ctx, uvector, i, NULL); + key_size = grn_table_get_key(ctx, domain, record_id, + key, GRN_TABLE_MAX_KEY_SIZE); + if (key_size > 0) { + matched = regexp_is_match(ctx, regex, key, key_size); + } + + if (matched) { + break; + } + } + + grn_obj_unlink(ctx, domain); + + onig_free(regex); + + return matched; +#else + return GRN_FALSE; +#endif +} + +static grn_bool exec_regexp_vector_bulk(grn_ctx *ctx, grn_obj *vector, grn_obj *pattern) { #ifdef GRN_SUPPORT_REGEXP @@ -1084,6 +1136,9 @@ grn_operator_exec_regexp(grn_ctx *ctx, grn_obj *target, grn_obj *pattern) grn_bool matched; GRN_API_ENTER; switch (target->header.type) { + case GRN_UVECTOR : + matched = exec_regexp_uvector_bulk(ctx, target, pattern); + break; case GRN_VECTOR : matched = exec_regexp_vector_bulk(ctx, target, pattern); break; Added: test/command/suite/select/filter/no_index/regexp/normalized_vector_reference.expected (+45 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/no_index/regexp/normalized_vector_reference.expected 2015-09-08 11:36:56 +0900 (ad36ca6) @@ -0,0 +1,45 @@ +table_create Tags TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +[[0,0.0,0.0],true] +table_create Memos TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR Tags +[[0,0.0,0.0],true] +load --table Memos +[ +{"tags": ["Groonga", "Rroonga", "Mroonga"]}, +{"tags": ["Groonga", "PGroonga", "Mroonga"]} +] +[[0,0.0,0.0],2] +select Memos --filter 'tags @~ "\\\\Apgr"' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "tags", + "Tags" + ] + ], + [ + 2, + [ + "groonga", + "pgroonga", + "mroonga" + ] + ] + ] + ] +] Added: test/command/suite/select/filter/no_index/regexp/normalized_vector_reference.test (+12 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/no_index/regexp/normalized_vector_reference.test 2015-09-08 11:36:56 +0900 (8af3629) @@ -0,0 +1,12 @@ +table_create Tags TABLE_PAT_KEY ShortText --normalizer NormalizerAuto + +table_create Memos TABLE_NO_KEY +column_create Memos tags COLUMN_VECTOR Tags + +load --table Memos +[ +{"tags": ["Groonga", "Rroonga", "Mroonga"]}, +{"tags": ["Groonga", "PGroonga", "Mroonga"]} +] + +select Memos --filter 'tags @~ "\\\\Apgr"' -------------- next part -------------- HTML����������������������������... Download