Thanks for taking the time to test my query. In
jcr:contains(cwe:comment/@cwe:body,'banana'), I was under the impression
that cwe:comment was the nodeType that I wanted to search and not the name
of the specific child node. My cwe:comment nodes may all be named
different. Is there a way to query the cwe:body property of any child nodes
of nodeType cwe:comment? If not, is there a syntax I can use to search all
child nodes like jcr:contains(*/@cwe:body,'banana')? Also, does anyone know
when jackrabbit 1.4 will be released. Thanks.
-David
Christoph Kiehl-3 wrote:
>
> bilobag wrote:
>
>> I have the following node structure. I am having issues running an xpath
>> query that searches for a cwe:comment property and returns a cwe:file
>> node.
>> I have read through the forum, but can't figure out if this functionality
>> is
>> supported in version 1.3.1.
>>
>> nodetypes:
>> [cwe:file] > nt:hierarchyNode, mix:referenceable , mix:versionable
>> orderable
>> - cwe:filename (string) mandatory
>> - cwe:filesize (long)
>> + jcr:content (nt:resource) primary mandatory
>> + * (cwe:comment) = cwe:comment ignore multiple
>>
>>
>> [cwe:comment] > nt:hierarchyNode, mix:referenceable
>> - cwe:body (string) mandatory
>> - cwe:createdUser (string) mandatory
>> - cwe:createdDate (date) mandatory
>>
>> query 1:
>> //element(*,cwe:file)[jcr:contains(jcr:content/@jcr:mimeType,
>> 'application/msword')]/rep:excerpt() order by @jcr:score desc
>>
>> query 2:
>> //element(*,cwe:file)[jcr:contains(cwe:comment/@cwe:body,
>> 'banana')]/rep:excerpt() order by @jcr:score desc
>
> I used the following code to reproduce your case using the given CND (I
> only
> omitted the "jcr:content" child node of "cwe:file"):
>
> public class Test {
> public static void main(String[] args) throws Exception {
> TransientRepository repository = new TransientRepository();
> Session session = repository.login(new SimpleCredentials("a",
> "b".toCharArray()));
> try {
> NodeTypeManagerImpl ntm = ((NodeTypeManagerImpl)
> session.getWorkspace().getNodeTypeManager());
> ntm.registerNodeTypes(
> Test.class.getResourceAsStream("nodetypes.cnd"),
> JackrabbitNodeTypeManager.TEXT_X_JCR_CND, true);
>
> Node rootNode = session.getRootNode();
> if (rootNode.hasNode("test")) {
> rootNode.getNode("test").remove();
> }
> Node fileNode = rootNode.addNode("test", "cwe:file");
> fileNode.setProperty("cwe:filename", "filename");
> Node commentNode = fileNode.addNode("cwe:comment");
> commentNode.setProperty("cwe:body", "banana");
> commentNode.setProperty("cwe:createdUser", "banana");
> commentNode.setProperty("cwe:createdDate", Calendar.getInstance());
> session.save();
>
> QueryManager queryManager =
> session.getWorkspace().getQueryManager();
> Query query = queryManager.createQuery(
>
> "//element(*,cwe:file)[jcr:contains(cwe:comment/@cwe:body,'banana')]/rep:exerpt()
>
> order by @jcr:score desc",
> Query.XPATH);
> QueryResult result = query.execute();
> System.out.println(result.getNodes().getSize());
> } finally {
> session.logout();
> }
> }
> }
>
> This outputs the expected result of "1". Are you sure your child nodes
> name is
> "cwe:comment"? In your CND the name of the _node type_ is "cwe:comment"
> but this
> doesn't necessarily mean that the child nodes name is "cwe:comment" as
> well.
> Could you may be show us the code where you create the nodes?
>
> Cheers,
> Christoph
>
>
>
--
View this message in context:
http://www.nabble.com/query-for-child-property-tf4262707.html#a12163332
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.