You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Alexander Klimetschek <ak...@adobe.com> on 2013/12/19 01:29:54 UTC
[GQL] Semantics of OR in GQL queries
Hi,
we came up with an undocumented part of the GQL search language:
How are OR statements grouped with the rest? The problem is that there is no grouping concept in GQL, and it is not documented [1]. Take this GQL statement for example:
type:asset path:/content OR property:something
a) Does it mean this (as pseudo query):
(type = asset AND path = /content) OR property = something
b) or this:
type = asset AND (path = /content OR property = something)
[1] http://jackrabbit.apache.org/api/2.4/org/apache/jackrabbit/commons/query/GQL.html
Cheers,
Alex
Re: [GQL] Semantics of OR in GQL queries
Posted by Alexander Klimetschek <ak...@adobe.com>.
On 09.01.2014, at 01:23, Michael Dürig <md...@apache.org> wrote:
>> property:one OR property:two other:alpha OR other:beta
>> =>
>> (property = one OR property = two) AND (other = alpha OR other = beta)
>
> Which would be a rather strange interpretation though. Usually AND has higher precedence than OR.
But it actually makes sense. Otherwise you wouldn't be able to check for different values of a property (common case) - given that there is no concept of brackets/groups in GQL.
Cheers,
Alex
Re: [GQL] Semantics of OR in GQL queries
Posted by Michael Dürig <md...@apache.org>.
On 9.1.14 4:29 , Alexander Klimetschek wrote:
> Refitting the example to avoid the NPE and going through more cases:
>
> type:asset property:one OR property:two
> =>
> (type = asset) AND (property = one OR property = two)
>
> type:asset property:one OR property:two OR property:three
> =>
> (type = asset) AND (property = one OR property = two OR property = three)
>
> property:one OR property:two other:alpha OR other:beta
> =>
> (property = one OR property = two) AND (other = alpha OR other = beta)
Which would be a rather strange interpretation though. Usually AND has
higher precedence than OR.
Michael
Re: [GQL] Semantics of OR in GQL queries
Posted by Alexander Klimetschek <ak...@adobe.com>.
TL;DR
- any sequence of OR statements (including the expression before the first OR) will make up a subgroup
- please check if my understanding is correct
Ok, let's try to understand the implementation:
http://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/GQL.java
I think lines 797ff in #pushExpression() have the important logic:
if (optional) {
Expression last = conditions.get(conditions.size() - 1);
if (last instanceof OptionalExpression) {
((OptionalExpression) last).addOperand(expr);
} else {
OptionalExpression op = new OptionalExpression();
op.addOperand(last);
op.addOperand(expr);
conditions.set(conditions.size() - 1, op);
}
} else {
conditions.add(expr);
}
(Context: If optional = true, that means there was an OR before the current "property:value" expression.)
So:
1) If the last expression was an optional group, we add the current one to it. Otherwise, we replace the last expression with an OptionalExpression group consisting of the last one and the current one.
2) Furthermore, OR does not apply to "path:", "type:", "order:" and "limit:" afaics (if/else beforehand).
Thus my example
type:asset path:/content OR property:something
would result in ... an Exception ;-) => createdJCR-3713 [1]
Refitting the example to avoid the NPE and going through more cases:
type:asset property:one OR property:two
=>
(type = asset) AND (property = one OR property = two)
type:asset property:one OR property:two OR property:three
=>
(type = asset) AND (property = one OR property = two OR property = three)
property:one OR property:two other:alpha OR other:beta
=>
(property = one OR property = two) AND (other = alpha OR other = beta)
Does that make sense?
[1] https://issues.apache.org/jira/browse/JCR-3713
Cheers,
Alex
On 18.12.2013, at 16:29, Alexander Klimetschek <ak...@adobe.com> wrote:
> Hi,
>
> we came up with an undocumented part of the GQL search language:
>
> How are OR statements grouped with the rest? The problem is that there is no grouping concept in GQL, and it is not documented [1]. Take this GQL statement for example:
>
> type:asset path:/content OR property:something
>
> a) Does it mean this (as pseudo query):
>
> (type = asset AND path = /content) OR property = something
>
> b) or this:
>
> type = asset AND (path = /content OR property = something)
>
> [1] http://jackrabbit.apache.org/api/2.4/org/apache/jackrabbit/commons/query/GQL.html
>
> Cheers,
> Alex