jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Klimetschek <aklim...@adobe.com>
Subject Re: [GQL] Semantics of OR in GQL queries
Date Thu, 09 Jan 2014 03:29:10 GMT
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 <aklimets@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


Mime
View raw message