Kouhei Sutou
null+****@clear*****
Fri Sep 8 17:50:55 JST 2017
Kouhei Sutou 2017-09-08 17:50:55 +0900 (Fri, 08 Sep 2017) New Revision: dbf02a58a415964730ba3d6b4cf8269c1a8b60e2 https://github.com/groonga/groonga/commit/dbf02a58a415964730ba3d6b4cf8269c1a8b60e2 Message: NO_SYNTAX_ERROR: support "+" query Added files: test/command/suite/select/query_flags/query_no_syntax_error/and_only.expected test/command/suite/select/query_flags/query_no_syntax_error/and_only.test Modified files: lib/expr.c Modified: lib/expr.c (+14 -4) =================================================================== --- lib/expr.c 2017-09-04 23:32:58 +0900 (323278474) +++ lib/expr.c 2017-09-08 17:50:55 +0900 (d6e49ad40) @@ -7423,17 +7423,19 @@ parse_query(grn_ctx *ctx, efs_info *q) grn_operator mode; efs_op op_, *op = &op_; grn_bool first_token = GRN_TRUE; + grn_bool only_first_and = GRN_FALSE; grn_bool block_started = GRN_FALSE; op->op = q->default_op; op->weight = DEFAULT_WEIGHT; while (!ctx->rc) { skip_space(ctx, q); + if (q->cur >= q->str_end) { goto exit; } + if (*q->cur == '\0') { goto exit; } + + only_first_and = GRN_FALSE; switch (*q->cur) { - case '\0' : - goto exit; - break; case GRN_QUERY_PARENR : if (q->paren_depth == 0 && q->flags & GRN_EXPR_QUERY_NO_SYNTAX_ERROR) { const char parenr = GRN_QUERY_PARENR; @@ -7513,7 +7515,9 @@ parse_query(grn_ctx *ctx, efs_info *q) } break; case GRN_QUERY_AND : - if (!first_token) { + if (first_token) { + only_first_and = GRN_TRUE; + } else { op->op = GRN_OP_AND; parse_query_accept_logical_op(ctx, q, @@ -7611,6 +7615,12 @@ exit : q, q->pending_token.string, q->pending_token.string_length); + } else if (only_first_and) { + const char query_and[] = {GRN_QUERY_AND}; + parse_query_accept_string(ctx, + q, + query_and, + 1); } if (q->paren_depth > 0) { int paren_depth = q->paren_depth; Added: test/command/suite/select/query_flags/query_no_syntax_error/and_only.expected (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/query_flags/query_no_syntax_error/and_only.expected 2017-09-08 17:50:55 +0900 (5d3e54998) @@ -0,0 +1,14 @@ +table_create Names TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +table_create Tokens TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto +[[0,0.0,0.0],true] +column_create Tokens names_key COLUMN_INDEX|WITH_POSITION Names _key +[[0,0.0,0.0],true] +load --table Names +[ +{"_key": "name (x+y)"}, +{"_key": "name (x y)"} +] +[[0,0.0,0.0],2] +select Names --match_columns "_key" --query "+" --query_flags ALLOW_PRAGMA|ALLOW_COLUMN|QUERY_NO_SYNTAX_ERROR +[[0,0.0,0.0],[[[1],[["_id","UInt32"],["_key","ShortText"]],[1,"name (x+y)"]]]] Added: test/command/suite/select/query_flags/query_no_syntax_error/and_only.test (+17 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/query_flags/query_no_syntax_error/and_only.test 2017-09-08 17:50:55 +0900 (7272005dd) @@ -0,0 +1,17 @@ +table_create Names TABLE_PAT_KEY ShortText + +table_create Tokens TABLE_PAT_KEY ShortText \ + --default_tokenizer TokenBigram \ + --normalizer NormalizerAuto +column_create Tokens names_key COLUMN_INDEX|WITH_POSITION Names _key + +load --table Names +[ +{"_key": "name (x+y)"}, +{"_key": "name (x y)"} +] + +select Names \ + --match_columns "_key" \ + --query "+" \ + --query_flags ALLOW_PRAGMA|ALLOW_COLUMN|QUERY_NO_SYNTAX_ERROR -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170908/86c0d942/attachment-0001.htm