Opcional elements

Hello,

I store documents like:






“Descriptor” element and "TemplateId " attribute are opcional.
“Descriptor” element is indexed using text index.
My database have many “a” documents without “Descriptor” elements.

I query “Descriptor” elements without “TemplateId” attributes:

for $b in input()/a where ($b/Descriptor[not (@TemplateId)])) return $b

the result is correct but the query is very slow when exist many “a” documents.

How could i query for documents that contains opcional indexed elements , and the opposite, query documents without especific elements
in optimal way?

Thanks

Hi,

To query documents holding a certain element you can place the path expression leading to the element into a where clause. For example the following query finds all documents holding the optional Descriptor element:

for $a in input()/a
where $a/Descriptor
return $a

If there is an index defined on the element Tamino 4.2 will perform an index based search. If there is no index defined you have to set the structureIndex property of your doctype to ?full?. Unfortunately the Tamino XQuery processor is not able to do an index based search of documents that don?t contain a certain optional element. If you really need this optimization you have to contact the Tamino support.

Best regards,

Thorsten Fiebig