@_Bill , no worries. It takes a while to get the hang of things. I didn’t mention parentheses last night, so as not to complicate this, but now you’ve fixed the basics I will address that aspect.
You are right in the general principle of parentheses. I’d generalise to say they are needed where an OR join, a |
in action code syntax, is needed. By contrast they make no difference to an AND (&
) join.
Why so? Because a query is read left to right, with each term (essentially a yes/no question) being evaluated and only those notes matching the test being passed into the next query term. Thus a succeeding AND-joined term can never increase the number of matches. At most it will be the same number as passed to it. This is because, for example with A & B & C
at the end tests A, B and C will all be matched (as a true
result).
As a result of this additive process writing A & B & C
is functionally/logically the same as (A & B) & C
because the result of A & B
is the same as (A & B)
. Both A and B _must _ be true to match that part of the query. In fact, were you to write A & (B & C)
the result would still be the same due to the nature of AND joins. But, it parentheses help your understanding of the problem you can use them without harm
Parentheses come into play with OR joins. A | B & C
means A and B must both be fully evaluated before can be tested. Let me add another term to the example to make things more clear: A & B | C & D
. More logically to the human eye this might be written as A & (B | C) & D
. Indeed, if you feed the former to Tinderbox, my understanding (@eastgate may correct me here) is Tinderbox reads the query, breaks out the terms and joins and processes the query as if in the second form.
What this means is whereas with AND, the matched list of one term is feed straight to the next term, with OR joins all successive OR-joined terms must be tested against the same input list. Thus in our 4-term example above, both B and C test all the matches to A. As B and C may have different result, the two are merged and the larger list of unique items from both lists forms the input to term D.
Using parentheses helps us as the writers of the query code as much as it helps Tinderbox parse it.
Where I’m less clear is on more complex queries (of the like most of us never need) like (A | B) & ( C | ( D | E ) )
. Here, A and B sample the whole document and the outcome it used as the scope for testing C , D and E although the extra parentheses mean the results combine in a different way.