Jackrabbit - Select node with maximum property value

430 views Asked by At

Let's say I have several file nodes with a property called foo. In Jackrabbit the xpath query I use to find those nodes by a property value is as follows:

/jcr:root/content/*[jcr:uuid='9b3d22fc-2354-49a6-afd0-9b672ae5a553']//file[foo = 10] order by @score

An oversimplified and raw representation of my repository as XML would look like this:

<content>
    <formNode jcrUuid="9b3d22fc-2354-49a6-afd0-9b672ae5a553">
        <year>
            <month>
                <day>
                    <hour>
                        <min>
                            <file foo="4"></file>
                            <file foo="10"></file>
                        </min>
                    </hour>
                </day>
                <day>
                    <hour>
                        <min>
                            <file foo="10"></file>
                        </min>
                        <min>
                            <file foo="5"></file>
                        </min>
                    </hour>
                    <hour>
                        <min>
                            <file foo="6"></file>
                        </min>
                    </hour>
                </day>
            </month>
        </year>
    </formNode>
</content>

Now. How can I find all the file nodes with the maximum value of foo? Does anyone know how to do this either by using xpath or JCR_SQL2?

I've tried the following queries without success:

  1. Returns all the file nodes under the provided jcr:uuid

    /jcr:root/content/*[jcr:uuid='9b3d22fc-2354-49a6-afd0-9b672ae5a553']//file[not(../file/foo > foo)] order by @score
    
  2. Throws an Exception

    jcr:root/content/*[jcr:uuid='9b3d22fc-2354-49a6-afd0-9b672ae5a553']//file[not(//file/foo > foo)] order by @score
    

    Exception:

    javax.jcr.query.InvalidQueryException: Unsupported root level query node: org.apache.jackrabbit.spi.commons.query.RelationQueryNode@8fedc
    

I've also tried the function fn:max. But AFAIK this is a XPATH 2.0 feature, which is not supported by JackRabbit 2.2.13, and I'm forced to use this version of JackRabbit.

0

There are 0 answers