mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-17 21:18:37 +02:00
Add Regexp FILTER operator (#558)
This commit is contained in:
parent
c0f8421eaf
commit
9988ebde6f
@ -46,6 +46,41 @@ func TestForFilter(t *testing.T) {
|
||||
So(string(out), ShouldEqual, `[2,3,3]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with a regexp FILTER statement", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
p, err := c.Compile(`
|
||||
LET users = [
|
||||
{
|
||||
age: 31,
|
||||
gender: "m",
|
||||
name: "Josh"
|
||||
},
|
||||
{
|
||||
age: 29,
|
||||
gender: "f",
|
||||
name: "Mary"
|
||||
},
|
||||
{
|
||||
age: 36,
|
||||
gender: "m",
|
||||
name: "Peter"
|
||||
}
|
||||
]
|
||||
FOR u IN users
|
||||
FILTER u.name =~ "r"
|
||||
RETURN u
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := p.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[{"age":29,"gender":"f","name":"Mary"},{"age":36,"gender":"m","name":"Peter"}]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with multiple FILTER statements", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
|
@ -434,6 +434,12 @@ func (v *visitor) doVisitFilterClause(ctx *fql.FilterClauseContext, scope *scope
|
||||
return operators.NewEqualityOperator(v.getSourceMap(ctx), left, right, equalityOp.GetText())
|
||||
}
|
||||
|
||||
regexpOp := exp.RegexpOperator()
|
||||
|
||||
if regexpOp != nil {
|
||||
return operators.NewRegexpOperator(v.getSourceMap(ctx), left, right, regexpOp.GetText())
|
||||
}
|
||||
|
||||
logicalAndOp := exp.LogicalAndOperator()
|
||||
|
||||
if logicalAndOp != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user