search with xpath - get Total match Count -- Need Help | Community
Skip to main content
adobecq-venkat
Level 2
December 2, 2015
Solved

search with xpath - get Total match Count -- Need Help

  • December 2, 2015
  • 1 reply
  • 1803 views

I am currently using xpath search for several reasons. However I didn't find TotalMatch Count on QueryResult class like SearchResult object using QueryBuilder.

            QueryManager qm=session.getWorkspace().getQueryManager();
            Query query = qm.createQuery(xpathQuery.toString(), Query.XPATH);

            query.setOffset(100);

            query.setLimit(25);
            QueryResult result = query.execute();

            NodeIterator iterator = result.getNodes();

 

I am searching for results on 4th page with a result limit of 25.

QueryResult class does not have any count method. I have to get NodeIterator or RowIterator to navigate to the result. These iterators will hold only number of rows set in setLimit method.

Can Someone help getting result count even after setting offset and limit on the query?

Thanks for your help!

Venkat

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

You can also try using JCR SQL2 - which give you finer control over iterating through a result set. 

http://www.day.com/specs/jsr170/javadocs/jcr-2.0/javax/jcr/query/QueryResult.html

You can use this method to get size of the result set:

http://www.day.com/specs/jsr170/javadocs/jcr-2.0/javax/jcr/RangeIterator.html#getSize()

1 reply

smacdonald2008
smacdonald2008Accepted solution
Level 10
December 2, 2015

You can also try using JCR SQL2 - which give you finer control over iterating through a result set. 

http://www.day.com/specs/jsr170/javadocs/jcr-2.0/javax/jcr/query/QueryResult.html

You can use this method to get size of the result set:

http://www.day.com/specs/jsr170/javadocs/jcr-2.0/javax/jcr/RangeIterator.html#getSize()