Execute and know how much documents are returned

Hi,

I’m using the following call to Tamino :

response = ((TXMLObjectAccessor)accessor).query(“”);

I’m expecting that about 10000 documents will be found for the query expression.

First I like to know the number of documents which will be returned. Can I get this value somewhere?

And then I like to have them retrieved in blocks of 10. I suppose I need to use the .query(‘’,10) method call? Is there another way?

Thx

To get the count, do the following:

TResponse response = accessor.query(“count( )”);
String n = response.getQueryContentAsString();
n contains the number as String

To retrieve the documents in chunks of ten, the .query(“query”,10) method is the right way to do it. After you issued the query once, you actually get an iterator from response and use it to process all documents, without calling the query() method again. The Tamino API for Java internally gets the chunks for you, the application does not need to bother about the chunking.

Hi,

When you execute a query inside the Interactive Interface with result sieze set to 16 and in the database 10000 documents exists corresponding to the query, 16 documents are returned and the cursor node indicates 10000, being the number of documents which correspond to the query.

I like to have the same in the new Java API. How can I do this? Or do I have to use the HTTP Client API?

The ino:count that you refer to can be unreliable. The best approach with the Tamino API is to follow Christian’s suggestion:
- issue a query enclosed in the XPath count() function ;
- then issue the query using TAccessor.query(query, batchamount) method.

ok, but when it is a complex query one taking a lot of time, then the Tamino server has to execute the binding twice. It would be nice that it can be done in one step.

Hi,

I’m looking a little bit more on the best way to get the number of documents returned by a certain xquery expression using the new Java API.

When I have 10.000 documents which are the result of a certain xquery expression, and I specified that the data is retuned in blocks of 8 documents. I use this inside a local transaction.

Instead of reading all the data to know the number of documents, I like to have this count in the response of the first data block. I’ve dumped the document returned from Tamino server, but this data isn’t inside the ino:response.

Dump document :
---------------

<?xml version="1.0"?>
<ino:response ino:sessionid=“13” ino:sessionkey=“29534” xmlns:ino=“http://namespaces.softwareag.com/tamino/response2” xmlns:xql=“XQL FAQ (XML Query Language - Frequently Asked Questions)”>xql:query/DAO</xql:query>
<ino:message ino:returnvalue=“0”>ino:messagelinefetching cursor</ino:messageline></ino:message>
xql:result
value_namevalue_addressvalue_zipvalue_cityvalue_namevalue_addressvalue_zipvalue_cityvalue_namevalue_addressvalue_zipvalue_cityvalue_namevalue_addressvalue_zipvalue_cityvalue_namevalue_addressvalue_zipvalue_cityvalue_namevalue_addressvalue_zipvalue_cityvalue_namevalue_addressvalue_zipvalue_cityvalue_namevalue_addressvalue_zipvalue_city
</xql:result>
<ino:cursor ino:handle=“1”><ino:current ino:position=“1” ino:quantity=“8”/><ino:next ino:position=“9”/></ino:cursor>
<ino:message ino:returnvalue=“0”>ino:messagelinecursor fetched</ino:messageline></ino:message>
</ino:response>

It seems that in the HTTP Client API this data is returned, because when you execute a xquery expression in the interactive interface, then ‘result size’ number of documents are returned, but also the total number of documents found for the query.

Is there realy no other way then executing a COUNT expression to get the number of documents to be returned as result of xquery expression instead of reading all the documents first?

Sorry, the answer is no.
The count returned with the HTTP Client API for Java came from the old cursoring mechanism. It is, as Stuart mentions above, unreliable. For this reason the Tamino API for Java does not use the old cursoring (it is also slower). Therefore the information, you would like to have, is not available and the only way I know of is the “count(query)” expression.

Thx