Count() function in the new API

Hi,

I looked at the new TResponse object and couldn’t find anything that tells me how many documents were retrieved in a query.

The old TaminoResult used to have a method getTotalCount() that I remember using.

Maybe it’s in here somewhere and I missed it.

Anyone?

Hi Amir,

if you expect to get a number of documents back, you would use the TXMLObjectIterator to retrieve the documents. It also offers the means to navigate over the document set.

However as far as I know, there is no direct count() available. There might be other means to get this information, I’ll try to get a better answer for you.

Best regards,
Christian.

“The old TaminoResult used to have a method getTotalCount() that I remember using.

In TaminoResult the getTotalCount() is suppossed gives you the number of nodes that the query gives back and comes from the cursoring information. If you use a page size in the query it still tells you the grand total even if the page size is much smaller (the default is 5).
The whole system is supposed to work like Altavista does - A total - results a page at a time, next previous etc.

In Tamino 2.+ this value is not terribly reliable as it (I think) doesn’t account for nodes removed by the post processor. Also if you page on through the result set the total may change depending on the locking and what else is going on in the system

If you are really interested in an exact value
you should use a count query.

count( )

I’d be interested to know what you get with the new API with a query like

count(Description[@about=“…/Tamino/concepts/cfadmin.htm”])

I can’t figure how to get the numeric value out
of the new API

In the Jscript API it is something like
r=c.query(“count(Description[@about=”…/Tamino/concepts/cfadmin.htm"])"
if (!r.errorNo &)
count=new Number
(r.getResult().firstChild.nodeValue);

[This message was edited by Nigel Hutchison on 20 Sep 2001 at 07:50.]

Here’s one way to get count() using the new TaminoAPI4J. This code does it for me:

code:

TQuery xpath = TQuery.newInstance(“count(” + DATABASE_DOCTYPE + “)”);
try {
TResponse response = xmlObjectAccessor.query(xpath );
System.out.println("Count is: " + response.getQueryContentAsString());

The documentation for the API says about getQueryContentAsString():

quote:
Gets the content for a query related response as a String. Here only the content that is delivered under the xql:result tag is provided. If this is given as a result set of XML documents these are serialzed into the resulting string only with their root elements but without deeper content. The result for a xpath function call such as count(xpath) is delivered as a pure string.


So if you want the count as an int you need to do Integer.parseInt() on it.

The documentation for getQueryContentAsString() as delivered in 3.1.1.1 now reads:

quote

Gets the result of a query as a string. If the result is a set of XML nodes, the string contains the root element of each node without any children elements. Each root node is delivered with its attributes including the ino: attributes. If the result is a value or a set of values, the string returned is the concatenation of these values. In the special case, where the query results in a single value(e.g. count(*)), the string returned represents this value.

unquote

TResponse response = accessor.query(query);
TXMLObject xmlObject = response.getFirstXMLObject();
Element element = (Element)xmlObject.getElement();
int resultsFound = element.getParent().getChildren().size();

The parent of the element object contains all the elements returned from the query. Use getChildren() to receive a java.util.List object which has a size() method. The size() method gives you the number of records found.

Hi Everyone,

I can’t give an easy answer, but maybe I can shed some light on the missing “total count” method.

The default cursoring behaviour with Tamino 3.1 is: don’t do anything.
Tamino 3.1 still supports the former cursoring mechanism: specify a start position and page size after the _xql verb, for example:
 /db/coll?_xql(1,1)=/cd

The ino:response for this query contains the cursor information like this:
   <ino:cursor ino:count=“3”>
      <ino:first ino:href=“?_XQL(1,1)=/cd” />
      <ino:next ino:href=“?_XQL(2,1)=/cd” />
      <ino:last ino:href=“?_XQL(3,1)=/cd” />
   </ino:cursor>

Here the “total count” is given (ino:count).

If one performs the same query using the new cursoring mechanism:
 /db/coll?_connect=*
 /db/coll?_sessionid=11&_sessionkey=10514&_cursor=open&_scroll=yes&_xql=/cd
 /db/coll?_sessionid=11&_sessionkey=19919&_cursor=fetch&_handle=1&_position=1&_quantity=1

The cursor information in the ino:response is different:
   <ino:cursor ino:handle=“1”>
      <ino:current ino:position=“1” ino:quantity=“1” />
      <ino:next ino:position=“2” />
   </ino:cursor>

There is no “total count” information now. The most information that Tamino gives is current, previous and next position.

I don’t know if the intention behind this is to allow for more dynamic handling of results (Tamino updates cursor by adding new instances to it) but it seems to at least allow for that possibility.

The only way that we have found to get a total count is to perform a count query. If the performance of a particular count seems unreasonable, post the query to the forums.

Cheers,
Trevor.

Hello,

I’m afraid I do not understand your question (neither in the context of the thread, nor as a completely new question).

Could you please elaborate on what it is that you are missing in the API?

Thanks,
Trevor.

Sorry, forget it, my questions is then &_count=cheap parameter of _cursor X-Machine command is not support?