Skip to content

Commit

Permalink
NO_SYNTAX_ERROR: support "+" query
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Sep 8, 2017
1 parent e81d8b9 commit dbf02a5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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)"]]]]
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dbf02a5

Please sign in to comment.