Thanks for the response, but this isn't what I wanted. I'm trying to get count of something (like tag-references to the node) for each row of results, or order my result with it. With calling getSize on iterator, I would have to do n+1 queries instead of 1, to get the count. and event that wouldn't get the order right.
On Mon, Jul 19, 2010 at 7:28 PM, Alexander Klimetschek <[email protected]> wrote: > On Mon, Jul 19, 2010 at 16:27, Omid Milani <[email protected]> wrote: >> Hi, >> >> I'm implementing a tag cloud in JCR. I wanted to write a query to >> return tags and number of articles tagged with each, similar to RDBMS >> query >> select tag, count(*) as count from article_tag and tag where >> article_tag.tag=tag.id group by tag order by count >> I expected something like this to do it in jcr >> /tags/tag( node() | >> count(//article/t...@tag-link=node()/@jcr:uuid])) order by count(...) >> It doesn't. I couldn't find a way to do it with sql2 and qom either, >> seems there's no count function defined in any of them. >> >> Now, for tag cloud, I did without that query, by keeping count of >> links in tag's node for each article tagged. But this seems an >> important feature. Is there some way to do this in JCR or Jackrabbit? >> Would it be supported in some point in future? Or should one use >> relational database cases that require such queries? > > The nodes or row iterator in the JCR query result API give you the > number of results found. For example: > > NodeIterator nodes = QueryResult.getNodes(); > int count = nodes.getSize(); > // ... > > Note that RangeIterator.getSize() is allowed to return -1 for > optimizations, where the query engine itself works lazily and doesn't > count the whole result set. Such optimizations are present with > Jackrabbit 2.x now. To work around that, you can force an ordering in > the query: > > //element(*, nt:file) order by @jcr:score descending > > (the default sort order is implicitly "order by @jcr:score > descending", so this doesn't affect the result set) > > Regards, > Alex > > -- > Alexander Klimetschek > [email protected] >
