added empty query checks

This commit is contained in:
ston1th 2017-11-12 15:37:16 +01:00
commit 0e2b25e788
3 changed files with 31 additions and 5 deletions

View file

@ -101,11 +101,12 @@ func NewQuery(s string) (q *Query, err error) {
return
}
qm := make(map[string]struct{})
fields := strings.Split(s, " ")
fields := clearFields(s)
if len(fields) == 0 {
err = errors.New("query is empty")
return
}
for _, v := range fields {
if v == "" {
continue
}
if q.l == undefined {
l, ok := parseLogic(v)
q.l = l
@ -160,8 +161,10 @@ func NewQuery(s string) (q *Query, err error) {
boolFunc(m[1]),
})
}
if len(q.m) == 0 {
if len(q.m) == 0 && q.s.enabled {
q.s.only = true
} else if len(q.m) == 0 {
err = errors.New("query is empty")
}
if len(q.m) == 1 && q.l != not {
q.l = or