jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sébastien Launay <sebastien.lau...@anyware-tech.com>
Subject Re: Search multiple child properties
Date Tue, 28 Oct 2008 17:04:33 GMT
Hi Pankaj,

XPath is a grammar for selecting nodes of an XML document.
It used in JCR for selecting JCR nodes.

The following query:
//element(*, type:A)[@foo='x' and */@bar='y' and */@baz='z']
means retrieve all nodes of nodetype type:A with property @foo = 'x'
and having at least one child with @bar='y' and at least one child
(the same or another) where @baz='z'.

I think the query you want is:
//element(*, type:A)[@foo='x' and */[@bar='y' and @baz='z']]
but this is not supported by Jackrabbit as it contains nested child
predicates.

The solution is to use the query:
//element(*, type:A)[@foo='x']/*[@bar='y' and @baz='z']
which means retrieve all children with @bar='y' and where @baz='z'
whose parent node has nodetype type:A and has @foo='x'.

With this solution, the result nodes will be of type B, so you need to
get the
parent node with node.getParent() and store it into structure like a Set for
avoiding to have the same node multiple times (i.e. if there are multiple
B matches for the same A).

Regards,

--
Sébastien Launay

Pankaj Gupta a écrit :
> Hi,
>
> Suppose I have two types defined: A and B. A can have any number of children
> of type B. The properties of A are: foo and that of B are: bar and baz. Now
> I want to search for all nodes of type A where foo = "x" and that have an
> instance of B with bar="y" and baz="z". If I create the XPath predicate as
> follows:
>
> (@foo="x" and */@bar="y" and */@baz="z") 
>
> I think this will return all instances of A that have foo="x" and atleast
> one instance of B with bar="y" and perhaps another instance of B with
> baz="z"
>
> What I would like to do is something like:
> (@foo="x" and */(@bar="y" and @baz="z"))
>
> Can this be done using XPath or do I have to run separate searches for bar
> and baz properties and then combine the search results programmatically.
>
> Thanks,
> Pankaj
>   

Mime
View raw message