Kouhei Sutou
null+****@clear*****
Tue Mar 10 18:36:27 JST 2015
Kouhei Sutou 2015-03-10 18:36:27 +0900 (Tue, 10 Mar 2015) New Revision: 59cedbb2eb84beb1a41ed389ab212e90c530f3cf https://github.com/groonga/groonga/commit/59cedbb2eb84beb1a41ed389ab212e90c530f3cf Message: Support regexp in query syntax Syntax is the following: COLUMN_NAME:~REGEXP ":~" is keyword. Added files: test/command/suite/select/query/regexp/no_index.expected test/command/suite/select/query/regexp/no_index.test Modified files: lib/expr.c Modified: lib/expr.c (+20 -0) =================================================================== --- lib/expr.c 2015-03-10 18:34:24 +0900 (e452470) +++ lib/expr.c 2015-03-10 18:36:27 +0900 (1ac47ab) @@ -906,6 +906,7 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op, case GRN_OP_GET_REF : case GRN_OP_ADJUST : case GRN_OP_TERM_EXTRACT : + case GRN_OP_REGEXP : PUSH_CODE(e, op, obj, nargs, code); if (nargs) { int i = nargs - 1; @@ -3460,6 +3461,21 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs) code++; } break; + case GRN_OP_REGEXP : + { + grn_obj *target, *pattern; + grn_bool matched; + POP1(pattern); + POP1(target); + WITH_SPSAVE({ + matched = grn_operator_exec_regexp(ctx, target, pattern); + }); + ALLOC1(res); + grn_obj_reinit(ctx, res, GRN_DB_INT32, 0); + GRN_INT32_SET(ctx, res, matched ? 1 : 0); + } + code++; + break; default : ERR(GRN_FUNCTION_NOT_IMPLEMENTED, "not implemented operator assigned"); goto exit; @@ -5931,6 +5947,10 @@ get_word_(grn_ctx *ctx, efs_info *q) mode = GRN_OP_SUFFIX; q->cur = end + 2; break; + case '~' : + mode = GRN_OP_REGEXP; + q->cur = end + 2; + break; default : mode = GRN_OP_EQUAL; q->cur = end + 1; Added: test/command/suite/select/query/regexp/no_index.expected (+44 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/query/regexp/no_index.expected 2015-03-10 18:36:27 +0900 (eba126e) @@ -0,0 +1,44 @@ +table_create Users TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Users name COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +load --table Users +[ +{"name": "Alice"}, +{"name": "Bob"}, +{"name": "Carlos"} +] +[[0,0.0,0.0],3] +select Users --query 'name:~"a.*l"' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 2 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "name", + "ShortText" + ] + ], + [ + 1, + "Alice" + ], + [ + 3, + "Carlos" + ] + ] + ] +] Added: test/command/suite/select/query/regexp/no_index.test (+11 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/query/regexp/no_index.test 2015-03-10 18:36:27 +0900 (16d6f2b) @@ -0,0 +1,11 @@ +table_create Users TABLE_NO_KEY +column_create Users name COLUMN_SCALAR ShortText + +load --table Users +[ +{"name": "Alice"}, +{"name": "Bob"}, +{"name": "Carlos"} +] + +select Users --query 'name:~"a.*l"' -------------- next part -------------- HTML����������������������������...Download