You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Pankaj Gupta <pg...@fluent.com> on 2008/10/28 14:58:48 UTC
Search multiple child properties
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
--
View this message in context: http://www.nabble.com/Search-multiple-child-properties-tp20207736p20207736.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
Re: Search multiple child properties
Posted by Sébastien Launay <se...@anyware-tech.com>.
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
>