diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2025-07-28 01:20:01 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2025-07-28 01:20:01 -0400 |
| commit | 3b8dcd30f5aca7624a22cff85a2f767d8d1fb583 (patch) | |
| tree | db01e57776ef9a8bc104403cd038e303c6831500 /pkg/query/compiler.go | |
| parent | 7b5cd075161bd4e1a05070d51cc64b38882ae74b (diff) | |
Add regex operator
Implemented regex operator using go flavored regular expressions.
Added optimization to combine regex's in `OR` clauses.
Diffstat (limited to 'pkg/query/compiler.go')
| -rw-r--r-- | pkg/query/compiler.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/query/compiler.go b/pkg/query/compiler.go index 1e946a6..7000544 100644 --- a/pkg/query/compiler.go +++ b/pkg/query/compiler.go @@ -93,6 +93,8 @@ func (s Statements) buildCompile(b *strings.Builder, delim string) ([]any, error case OP_LT: // NOTE: doesn't raise compiler error if operator used on invalid category opStr = "< " + case OP_RE: + opStr = "REGEXP " case OP_NE: if cat.IsSet() { opStr = "NOT IN " @@ -164,6 +166,30 @@ func (s Statements) buildCompile(b *strings.Builder, delim string) ([]any, error idx++ sCount++ } + } else if op == OP_RE { + idx := 0 + for _, stmt := range opStmts { + b.WriteString("( ") + b.WriteString(catStr) + b.WriteString("IS NOT NULL AND ") + if stmt.Negated { + b.WriteString("NOT ") + } + b.WriteString(catStr) + b.WriteString(opStr) + arg, ok := stmt.Value.buildCompile(b) + b.WriteString(" )") + if ok { + args = append(args, arg) + } + b.WriteByte(' ') + if idx != len(opStmts)-1 { + b.WriteString(delim) + b.WriteByte(' ') + } + idx++ + sCount++ + } } else { idx := 0 for _, stmt := range opStmts { |
