Susumu Yata
null+****@clear*****
Wed Oct 18 11:54:40 JST 2017
Susumu Yata 2017-10-18 11:54:40 +0900 (Wed, 18 Oct 2017) New Revision: 5fa6f75819b74bb8d032f02b4b58df0135af977d https://github.com/groonga/groonga/commit/5fa6f75819b74bb8d032f02b4b58df0135af977d Message: NO_SYNTAX_ERROR: support queries with empty or only-and blocks Ref: #767 Added files: test/command/suite/select/query_flags/query_no_syntax_error/and_only_block.expected test/command/suite/select/query_flags/query_no_syntax_error/and_only_block.test test/command/suite/select/query_flags/query_no_syntax_error/empty_block.expected test/command/suite/select/query_flags/query_no_syntax_error/empty_block.test Modified files: lib/expr.c Modified: lib/expr.c (+29 -9) =================================================================== --- lib/expr.c 2017-10-18 09:11:15 +0900 (515dbe068) +++ lib/expr.c 2017-10-18 11:54:40 +0900 (ce67ef5f3) @@ -7458,18 +7458,35 @@ parse_query(grn_ctx *ctx, efs_info *q) if (q->cur >= q->str_end) { goto exit; } if (*q->cur == '\0') { goto exit; } - only_first_and = GRN_FALSE; switch (*q->cur) { case GRN_QUERY_PARENR : - if (q->paren_depth == 0 && q->flags & GRN_EXPR_QUERY_NO_SYNTAX_ERROR) { - const char parenr = GRN_QUERY_PARENR; - parse_query_flush_pending_token(ctx, q); - parse_query_accept_string(ctx, q, &parenr, 1); - } else { - parse_query_flush_pending_token(ctx, q); - PARSE(GRN_EXPR_TOKEN_PARENR); - q->paren_depth--; + if (q->flags & GRN_EXPR_QUERY_NO_SYNTAX_ERROR) { + if (q->paren_depth == 0) { + const char parenr = GRN_QUERY_PARENR; + parse_query_flush_pending_token(ctx, q); + parse_query_accept_string(ctx, q, &parenr, 1); + q->cur++; + break; + } + if (first_token) { + const char parenl = GRN_QUERY_PARENL; + const char parenr = GRN_QUERY_PARENR; + parse_query_flush_pending_token(ctx, q); + parse_query_accept_string(ctx, q, &parenl, 1); + parse_query_accept_string(ctx, q, &parenr, 1); + } + if (only_first_and) { + const char query_and[] = {GRN_QUERY_AND}; + parse_query_flush_pending_token(ctx, q); + parse_query_accept_string(ctx, + q, + query_and, + 1); + } } + parse_query_flush_pending_token(ctx, q); + PARSE(GRN_EXPR_TOKEN_PARENR); + q->paren_depth--; q->cur++; break; case GRN_QUERY_QUOTEL : @@ -7634,6 +7651,9 @@ parse_query(grn_ctx *ctx, efs_info *q) parse_query_word(ctx, q); break; } + if (!first_token) { + only_first_and = GRN_FALSE; + } first_token = block_started; block_started = GRN_FALSE; } Added: test/command/suite/select/query_flags/query_no_syntax_error/and_only_block.expected (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/query_flags/query_no_syntax_error/and_only_block.expected 2017-10-18 11:54:40 +0900 (31a4f68ff) @@ -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_block.test (+17 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/query_flags/query_no_syntax_error/and_only_block.test 2017-10-18 11:54:40 +0900 (80db87e3a) @@ -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 Added: test/command/suite/select/query_flags/query_no_syntax_error/empty_block.expected (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/query_flags/query_no_syntax_error/empty_block.expected 2017-10-18 11:54:40 +0900 (49fce9954) @@ -0,0 +1,16 @@ +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 "}, +{"_key": "name x y)"}, +{"_key": "name x y "} +] +[[0,0.0,0.0],4] +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/empty_block.test (+19 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/query_flags/query_no_syntax_error/empty_block.test 2017-10-18 11:54:40 +0900 (baea4baa9) @@ -0,0 +1,19 @@ +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 "}, +{"_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/20171018/61cc8c29/attachment-0001.htm