mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 09:59:04 +08:00
fulltext validation updated
This commit is contained in:
parent
5894acdb2d
commit
594bfc256c
@ -32,7 +32,7 @@ const (
|
|||||||
IDEND = "idEnd"
|
IDEND = "idEnd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?|or( )*?)?(([\w.-]+ (in|nin) \([\S ]+\))|([\w.]+ (gt|lt|gte|lte) (')?[\S]+(')?)|([\w.]+ (contains|ncontains)) (')?[^']+(')?)`)
|
var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?|or( )*?)?(([\w.-]+ (in|nin) \([^(]+\))|([\w.]+ (gt|lt|gte|lte) (')?[\S]+(')?)|([\w.]+ (contains|ncontains)) '[^']+')`)
|
||||||
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)(?: )`)
|
||||||
|
|
||||||
func ParseLogFilterParams(r *http.Request) (*model.LogsFilterParams, error) {
|
func ParseLogFilterParams(r *http.Request) (*model.LogsFilterParams, error) {
|
||||||
@ -204,7 +204,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) || strings.HasPrefix(s, OR) {
|
||||||
colName = filter[1]
|
colName = filter[1]
|
||||||
} else {
|
} else {
|
||||||
colName = filter[0]
|
colName = filter[0]
|
||||||
@ -237,7 +237,7 @@ func replaceInterestingFields(allFields *model.GetFieldsResponse, queryTokens []
|
|||||||
if _, ok := selectedFieldsLookup[*col]; !ok && *col != "body" {
|
if _, ok := selectedFieldsLookup[*col]; !ok && *col != "body" {
|
||||||
if field, ok := interestingFieldLookup[*col]; ok {
|
if field, ok := interestingFieldLookup[*col]; ok {
|
||||||
sqlColName = fmt.Sprintf("%s_%s_value[indexOf(%s_%s_key, '%s')]", field.Type, strings.ToLower(field.DataType), field.Type, strings.ToLower(field.DataType), *col)
|
sqlColName = fmt.Sprintf("%s_%s_value[indexOf(%s_%s_key, '%s')]", field.Type, strings.ToLower(field.DataType), field.Type, strings.ToLower(field.DataType), *col)
|
||||||
} else {
|
} else if strings.Compare(strings.ToLower(*col), "fulltext") != 0 {
|
||||||
return nil, fmt.Errorf("field not found for filtering")
|
return nil, fmt.Errorf("field not found for filtering")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,11 @@ var correctQueriesTest = []struct {
|
|||||||
`id in ('2CkBCauK8m3nkyKR19YhCw6WbdY') or fulltext contains 'OPTIONS /api/v1/logs'`,
|
`id in ('2CkBCauK8m3nkyKR19YhCw6WbdY') or fulltext contains 'OPTIONS /api/v1/logs'`,
|
||||||
[]string{`id IN ('2CkBCauK8m3nkyKR19YhCw6WbdY') `, `OR body ILIKE '%OPTIONS /api/v1/logs%' `},
|
[]string{`id IN ('2CkBCauK8m3nkyKR19YhCw6WbdY') `, `OR body ILIKE '%OPTIONS /api/v1/logs%' `},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"mixing and or",
|
||||||
|
`id in ('2CkBCauK8m3nkyKR19YhCw6WbdY') and id in ('2CkBCauK8m3nkyKR19YhCw6WbdY','2CkBCauK8m3nkyKR19YhCw6WbdY') or fulltext contains 'OPTIONS /api/v1/logs'`,
|
||||||
|
[]string{`id IN ('2CkBCauK8m3nkyKR19YhCw6WbdY') `, `and id IN ('2CkBCauK8m3nkyKR19YhCw6WbdY','2CkBCauK8m3nkyKR19YhCw6WbdY') `, `OR body ILIKE '%OPTIONS /api/v1/logs%' `},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
`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