From f61a4878ef379a2b74495377098fe4fc660afa00 Mon Sep 17 00:00:00 2001 From: baxiry Date: Mon, 22 Jul 2024 22:55:23 +0300 Subject: [PATCH] feat string operations --- engine/filter.go | 52 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/engine/filter.go b/engine/filter.go index 04172cf..b363a2e 100644 --- a/engine/filter.go +++ b/engine/filter.go @@ -96,55 +96,75 @@ func match(filter gjson.Result, data string, ids ...int64) (result bool, err err switch sQueryKey.Str { // compare sQueryKey - case "$gt": - if !(dataVal.Str > sQueryVal.Str) { + + case "$st": // start with .. + if !strings.HasPrefix(dataVal.Str, sQueryVal.Str) { result = false } return result - case "$lt": - if !(dataVal.Str < sQueryVal.Str) { + case "$en": // end with .. + if !strings.HasSuffix(dataVal.Str, sQueryVal.Str) { result = false } return result - case "$gte": - if !(dataVal.Str >= sQueryVal.Str) { + case "$c": // contains .. + if !strings.Contains(dataVal.Str, sQueryVal.Str) { result = false } return result - case "$lte": - if !(dataVal.Str <= sQueryVal.Str) { + case "$nst": // not start with .. + if strings.HasPrefix(dataVal.Str, sQueryVal.Str) { result = false } return result - case "$eq": - if dataVal.Str != sQueryVal.Str { + case "$nen": // not end with .. + if strings.HasSuffix(dataVal.Str, sQueryVal.Str) { result = false } return result + + case "$nc": // not contains .. + if strings.Contains(dataVal.Str, sQueryVal.Str) { + result = false + } + return result + case "$ne": if dataVal.Str == sQueryVal.Str { result = false } return result - case "$st": // start with .. - if !strings.HasPrefix(dataVal.Str, sQueryVal.Str) { + case "$eq": + if dataVal.Str != sQueryVal.Str { result = false } return result - case "$en": // end with .. - if !strings.HasSuffix(dataVal.Str, sQueryVal.Str) { + case "$gt": + if !(dataVal.Str > sQueryVal.Str) { result = false } return result - case "$c": // contains .. - if !strings.Contains(dataVal.Str, sQueryVal.Str) { + case "$lt": + if !(dataVal.Str < sQueryVal.Str) { + result = false + } + return result + + case "$gte": + if !(dataVal.Str >= sQueryVal.Str) { + result = false + } + return result + + case "$lte": + if !(dataVal.Str <= sQueryVal.Str) { result = false } return result