From users-return-9455-apmail-jackrabbit-users-archive=jackrabbit.apache.org@jackrabbit.apache.org Tue Oct 28 17:05:34 2008
Return-Path:
Delivered-To: apmail-jackrabbit-users-archive@locus.apache.org
Received: (qmail 89009 invoked from network); 28 Oct 2008 17:05:34 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2)
by minotaur.apache.org with SMTP; 28 Oct 2008 17:05:34 -0000
Received: (qmail 82680 invoked by uid 500); 28 Oct 2008 17:05:38 -0000
Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org
Received: (qmail 82282 invoked by uid 500); 28 Oct 2008 17:05:38 -0000
Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: users@jackrabbit.apache.org
Delivered-To: mailing list users@jackrabbit.apache.org
Received: (qmail 82271 invoked by uid 99); 28 Oct 2008 17:05:38 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Oct 2008 10:05:38 -0700
X-ASF-Spam-Status: No, hits=-0.0 required=10.0
tests=SPF_PASS
X-Spam-Check-By: apache.org
Received-SPF: pass (athena.apache.org: local policy)
Received: from [84.14.163.136] (HELO malachi.anyware-tech.com) (84.14.163.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Oct 2008 17:04:25 +0000
Received: from localhost (localhost [127.0.0.1])
by malachi.anyware-tech.com (Postfix) with ESMTP id 0F6B92FD97
for ; Tue, 28 Oct 2008 18:04:33 +0100 (CET)
X-Virus-Scanned: Debian amavisd-new at malachi.anyware-tech.com
Received: from malachi.anyware-tech.com ([127.0.0.1])
by localhost (malachi.anyware-tech.com [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 2WgqEuMO-DPN for ;
Tue, 28 Oct 2008 18:04:29 +0100 (CET)
Received: from [10.0.1.122] (krusty.anyware [10.0.1.122])
(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
(No client certificate requested)
by malachi.anyware-tech.com (Postfix) with ESMTPSA id DF57D2FD9B
for ; Tue, 28 Oct 2008 18:04:28 +0100 (CET)
Message-ID: <49074621.6010908@anyware-tech.com>
Date: Tue, 28 Oct 2008 18:04:33 +0100
From: =?ISO-8859-1?Q?S=E9bastien_Launay?=
User-Agent: Thunderbird 2.0.0.17 (X11/20080925)
MIME-Version: 1.0
To: users@jackrabbit.apache.org
Subject: Re: Search multiple child properties
References: <20207736.post@talk.nabble.com>
In-Reply-To: <20207736.post@talk.nabble.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Virus-Checked: Checked by ClamAV on apache.org
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
>