mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 21:05:54 +08:00
parser updated to support contians operator for other fields
This commit is contained in:
parent
6ac7cb1022
commit
448e14b32f
@ -21,6 +21,10 @@ var operatorMapping = map[string]string{
|
|||||||
"ncontains": "NOT ILIKE",
|
"ncontains": "NOT ILIKE",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
AND = "and"
|
||||||
|
)
|
||||||
|
|
||||||
var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?)?(([\w.-]+ (in|nin) \([\S ]+\))|([\w.]+ (gt|lt|gte|lte) (')?[\S]+(')?)|([\w.]+ (contains|ncontains)) (')?[\S ]+(')?)`)
|
var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?)?(([\w.-]+ (in|nin) \([\S ]+\))|([\w.]+ (gt|lt|gte|lte) (')?[\S]+(')?)|([\w.]+ (contains|ncontains)) (')?[\S ]+(')?)`)
|
||||||
var operatorRegex, _ = regexp.Compile(`(?i)(?: )(in|nin|gt|lt|gte|lte|contains|ncontains)(?: )`)
|
var operatorRegex, _ = regexp.Compile(`(?i)(?: )(in|nin|gt|lt|gte|lte|contains|ncontains)(?: )`)
|
||||||
|
|
||||||
@ -160,8 +164,19 @@ func parseLogQuery(query string) ([]string, error) {
|
|||||||
|
|
||||||
if opLower == "contains" || opLower == "ncontains" {
|
if opLower == "contains" || opLower == "ncontains" {
|
||||||
searchString := strings.TrimSpace(strings.Split(v, op)[1])
|
searchString := strings.TrimSpace(strings.Split(v, op)[1])
|
||||||
f := fmt.Sprintf(`body %s '%%%s%%' `, operatorMapping[opLower], searchString[1:len(searchString)-1])
|
|
||||||
if strings.HasPrefix(strings.ToLower(v), "and") {
|
operatorRemovedTokens := strings.Split(operatorRegex.ReplaceAllString(v, " "), " ")
|
||||||
|
searchCol := strings.ToLower(operatorRemovedTokens[0])
|
||||||
|
if searchCol == AND {
|
||||||
|
searchCol = strings.ToLower(operatorRemovedTokens[1])
|
||||||
|
}
|
||||||
|
col := searchCol
|
||||||
|
if strings.ToLower(searchCol) == "fulltext" {
|
||||||
|
col = "body"
|
||||||
|
}
|
||||||
|
|
||||||
|
f := fmt.Sprintf(`%s %s '%%%s%%' `, col, operatorMapping[opLower], searchString[1:len(searchString)-1])
|
||||||
|
if strings.HasPrefix(strings.ToLower(v), AND) {
|
||||||
f = "AND " + f
|
f = "AND " + f
|
||||||
}
|
}
|
||||||
sqlQueryTokens = append(sqlQueryTokens, f)
|
sqlQueryTokens = append(sqlQueryTokens, f)
|
||||||
@ -185,7 +200,7 @@ func parseColumn(s string) (*string, error) {
|
|||||||
return nil, fmt.Errorf("incorrect filter")
|
return nil, fmt.Errorf("incorrect filter")
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(s, "and") {
|
if strings.HasPrefix(s, AND) {
|
||||||
colName = filter[1]
|
colName = filter[1]
|
||||||
} else {
|
} else {
|
||||||
colName = filter[0]
|
colName = filter[0]
|
||||||
|
@ -27,6 +27,11 @@ var correctQueriesTest = []struct {
|
|||||||
`FULLTEXT contains 'Hello, "World"'`,
|
`FULLTEXT contains 'Hello, "World"'`,
|
||||||
[]string{`body ILIKE '%Hello, "World"%' `},
|
[]string{`body ILIKE '%Hello, "World"%' `},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`contains search with a different attributes`,
|
||||||
|
`resource contains 'Hello, "World"'`,
|
||||||
|
[]string{`resource ILIKE '%Hello, "World"%' `},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
`filters with lt,gt,lte,gte operators`,
|
`filters with lt,gt,lte,gte operators`,
|
||||||
`id lt 100 and id gt 50 and code lte 500 and code gte 400`,
|
`id lt 100 and id gt 50 and code lte 500 and code gte 400`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user