1
0
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:
David BF 2020-10-02 19:35:17 +02:00 committed by GitHub
parent c0f8421eaf
commit 9988ebde6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -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()

View File

@ -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 {