Doradus Query Language (DQL) : Link Clauses : WHERE Filter

WHERE Filter
Sometimes we need multiple selection clauses for the objects in a link path, but we need the clauses to be “bound” to the same instances. To illustrate this concept, consider this query: Suppose we want to find messages where an internal recipient is within the R&D department and in an office in Kanata. We might try to write the query like this:
// Doesn't do what we want
GET /Email/Message/_query?q=InternalRecipients.Person.Department='R&D' AND
InternalRecipients.Person.Office='Kanata'&range=0
But the problem is that the two InternalRecipients.Person paths are separately quantified with ANY, so the query will return messages that have at least one internal recipient in R&D (but not necessarily in Kanata) while another internal recipient is in Kanata (but not necessarily in R&D). It might be tempting to quantify the two InternalRecipient.Person paths with ALL:
// Still not what we want
GET /Email/Message/_query?q=ALL(InternalRecipients.Person).Department='R&D' AND
ALL(InternalRecipients.Person).Office='Kanata'&range=0
Now the problem is that the query won't select messages that have one or more internal recipients who are not in R&D/Kanata, even though there might be another recipient who is.
What we really need is for the two InternalRecipient.Person clauses to be bound, meaning they apply to the same instances and are not separately quantified.
The WHERE filter can be used for this scenario, as shown below:
GET /Email/Message/_query?q=InternalRecipients.Person.WHERE(Department='R&D' AND Office='Kanata')
&range=0
The WHERE function is appended to the portion of the link path for which we need multiple selection clauses, and the clauses are specified as a parameter. The field names referenced in the WHERE expression are qualified to the object to the left of the WHERE clause. In the example above, Department and Office are qualified to Person, so they must be fields belonging to those objects. Note that implicit quantification takes places in the example above, hence it is identical to the following query:
GET /Email/Message/_query?q=ANY(InternalRecipients.Person).WHERE(Department='R&D' AND Office='Kanata')&range=0