OR support added with contains

This commit is contained in:
nityanandagohain 2022-08-01 12:30:11 +05:30
parent 6eb9389e81
commit 5894acdb2d
2 changed files with 9 additions and 1 deletions

View File

@ -23,6 +23,7 @@ var operatorMapping = map[string]string{
const (
AND = "and"
OR = "or"
ORDER = "order"
ORDER_BY = "orderBy"
TIMESTAMP_START = "timestampStart"
@ -168,7 +169,7 @@ func parseLogQuery(query string) ([]string, error) {
operatorRemovedTokens := strings.Split(operatorRegex.ReplaceAllString(v, " "), " ")
searchCol := strings.ToLower(operatorRemovedTokens[0])
if searchCol == AND {
if searchCol == AND || searchCol == OR {
searchCol = strings.ToLower(operatorRemovedTokens[1])
}
col := searchCol
@ -179,6 +180,8 @@ func parseLogQuery(query string) ([]string, error) {
f := fmt.Sprintf(`%s %s '%%%s%%' `, col, operatorMapping[opLower], searchString[1:len(searchString)-1])
if strings.HasPrefix(strings.ToLower(v), AND) {
f = "AND " + f
} else if strings.HasPrefix(strings.ToLower(v), OR) {
f = "OR " + f
}
sqlQueryTokens = append(sqlQueryTokens, f)
} else {

View File

@ -37,6 +37,11 @@ var correctQueriesTest = []struct {
`resource contains 'Hello, "World"' and myresource contains 'abcd'`,
[]string{`resource ILIKE '%Hello, "World"%' `, `AND myresource ILIKE '%abcd%' `},
},
{
"contains with or",
`id in ('2CkBCauK8m3nkyKR19YhCw6WbdY') or fulltext contains 'OPTIONS /api/v1/logs'`,
[]string{`id IN ('2CkBCauK8m3nkyKR19YhCw6WbdY') `, `OR body ILIKE '%OPTIONS /api/v1/logs%' `},
},
{
`filters with lt,gt,lte,gte operators`,
`id lt 100 and id gt 50 and code lte 500 and code gte 400`,