Identifying the existence of a document

Hi,

Is there an efficient way to identify the existence of a document.

I have tried something like


HttpURLConnection req = (HttpURLConnection) new URL().openConnection();
req.setRequestMethod(“HEAD”);

req.connect();
exist = req.getResponseCode == 200;


but that only works if you request a document via its document id, e.g. http://hostname/tamino/mydb/mycoll/mydoc/@1.


Another approach I have tried was to use _admin=ino:DisplayIndex(…) on a data index and requesting only one value (and checking if the start value equals the outcome), but during my performance tests I noticed that the performance is worser then using a plain “GET”.

Actually I would like to use a HEAD HTTP request using an _xql request and I want Tamino to respond with HTTP response code 200 indicating that something has been found (that is all I want!).

This will eliminate the overhead of InputStreams that need to be read in order to determine if something exists.

Kind regards,
Rudolf de Grijs

Hi Rudolf,

What are you asking for is not possible with HTTP HEAD because you get back 404. Can I suggest the following. Assume the query is something like a[@name=“a”] in the ino:etc collection and you just want to know if document(s) exist or not, then you could issue something like:

_xql(0,1)=a[@name=“a”]/@ino:id

This will return a body (the tamino response) with the ‘a’ element in this case and the ino:id attribute and non of its descendant children. So if a was a very large document, none of it is returned. So the response from Tamino is small and you can test the existance of the xql:result element. If this exists document(s) exist otherwise the query was negative and there are no documents.

Does this help?

Stuart Fyffe-Collins
Software AG (UK) Ltd.

Thanks Stuart! Your answer is clear.

BTW I thought that the _xql(0,1) would be deprecated in the future (so I guess that the new cursoring mechanism will be more appropriate).

I think that it might be worthwhile to have something like an _exist X-machine command (which could e.g. only be combined with HTTP HEAD request).

Regards,
Rudolf

Hello Guys.

An alternative is to use this query:

  _xql=boolean(a[@name="a"])


This will always return a result of TRUE (if there is a document matching the filter) or FALSE (if there is no match).

Greetings,
Trevor.