Complex Logical Query



I want to select documents which meets this condition:

 (doc.title == "Hello" || doc.title == "World") && ( == "John" || == "Ken")

How can I perform such query in CBL2.0 ?
I know there’s api for And (IExpression.And) / Or (IExpression.Or)
But I can’t find api for the grouping the condition.

Also, it’s the condition (A or B and C) different from (C and A or B)?
I’m not sure how CBL2.0 handles consecutive logical test.


The Query API is Fluent by design. So you should be able to logically chain together these conditions anyway you like.
So not sure if you attempted that and it failed
Try something like this

            let expr1 ="title").equalTo(Expression.string("Hello")).or("title").equalTo(Expression.string("world")))
            let expr2 ="author").equalTo(Expression.string("john")).or("author").equalTo(Expression.string("ken")))
            let expr = expr1.and(expr2)


It didn’t occur to me that the Expression itself is indeed a group.
Now I know how to do it.

Thanks for the information.