jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Kiehl <christ...@sulu3000.de>
Subject Re: query for child property
Date Tue, 14 Aug 2007 21:12:05 GMT
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


Mime
View raw message