diff --git a/services/search/pkg/query/lexer.go b/services/search/pkg/query/lexer.go index 181b551808c..f540f921ad3 100644 --- a/services/search/pkg/query/lexer.go +++ b/services/search/pkg/query/lexer.go @@ -10,7 +10,8 @@ import ( // Lexer is responsible for lexing the query. type Lexer struct { - r *bufio.Reader + r *bufio.Reader + plain bool } // NewLexer creates a new Lexer @@ -33,6 +34,7 @@ func (l *Lexer) Scan() (Token, string) { } if r == '"' { + l.plain = !l.plain return TQuotationMark, "" } @@ -40,6 +42,10 @@ func (l *Lexer) Scan() (Token, string) { return TNegation, "" } + if r == '+' { + return TAddition, "" + } + if r != ':' { l.unread() return l.scanUnknown(TValue) @@ -68,7 +74,7 @@ func (l *Lexer) scanUnknown(t Token) (Token, string) { break } - if r == ':' { + if r == ':' && !l.plain { return TField, buf.String() } diff --git a/services/search/pkg/query/lexer_test.go b/services/search/pkg/query/lexer_test.go index 6ee6a380c6e..8d2d0bed025 100644 --- a/services/search/pkg/query/lexer_test.go +++ b/services/search/pkg/query/lexer_test.go @@ -317,6 +317,21 @@ func TestLexer(t *testing.T) { {k: TEof}, }, }, + { + input: "+ID:1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51 +Mtime:>=\"2022-10-19T10:35:21.064277496+02:00\"", + exp: []kv[Token, string]{ + {k: TAddition}, + {k: TField, v: "ID"}, + {k: TValue, v: "1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51"}, + {k: TAddition}, + {k: TField, v: "Mtime"}, + {k: TValue, v: ">="}, + {k: TQuotationMark}, + {k: TValue, v: "2022-10-19T10:35:21.064277496+02:00"}, + {k: TQuotationMark}, + {k: TEof}, + }, + }, } for _, c := range cases { diff --git a/services/search/pkg/query/query.go b/services/search/pkg/query/query.go index 30a70033a6b..21288094af3 100644 --- a/services/search/pkg/query/query.go +++ b/services/search/pkg/query/query.go @@ -8,6 +8,8 @@ const ( TEof Token = iota // TUnknown unknown token type TUnknown + // TAddition addition token type + TAddition // TNegation negation token type TNegation // TQuotationMark quotation-mark token type, e.g. not of type - "-"