You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Alexander Klimetschek <ak...@day.com> on 2009/01/06 09:39:17 UTC

Re: Jcr search syntax

On Tue, Jan 6, 2009 at 7:11 AM, yanshaozhiGmail <ya...@gmail.com> wrote:
> HI:
>      Is there any method can select specified properties I want,
>
> "//element(*,rep:Group )//(@rep:principalName|@jcr:score) "
>
> as the statement up , I only want to query the properties rep:principalName and jcr:score,
>
> however it doesn't work ,why?
>
>      How can I realize it?

A JCR query will always return nodes (also accessible as "rows"). See
the QueryResult.getNodes() and QueryResult.getRows() method.

Your query could look like this; it will return all nodes that have a
rep:principalName property with a value:

//element(*,rep:Group )//*[@rep:principalName]

(BTW, @jcr:score is not a standard property, it is used for ordering,
so you could append " order by @jcr:score" to the query above).

Now you would retrieve the property through the QueryResult, for example:

NodeIterator nodes = queryResult.getNodes();
while (nodes.hasNext()) {
    String name = nodes.nextNode().getProperty("rep:principalName").getString();
}


Hope that helps,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com