XPath statement in eXist xquery - some advice please
I admit this is not so much a 'problem', or that it is purely eXist related. Still I would appreciate some comments to help me understand a) what it actually means and b) is it the most efficient xpath, especially regarding how xquery in eXist handles xpath selections?
To me it means, get all orders where an order has a child node 'customer' of one found from the full text search .... perhaps ?
The requirement in principle I guess, is to pick out all parent nodes where a parent node has a child node belonging to a set returned from a full text search.
The above xpath appears to 'work' as such!
I realise there may be xquery scripts to 'do this better', but I am interested in a xpath statement in this case.
Re: XPath statement in eXist xquery - some advice please
> To me it means, get all orders where an order has a child node 'customer'
> of one found from the full text search .... perhaps ?
The statement looks perfectly fine and should be efficient. From an xpath perspective, the ft:query function works like any other function (e.g. a standard contains), though internally eXist tries to optimize the entire statement. Instead of scanning all customer nodes and checking each for matching text content, eXist will do a single index lookup on customer/"searchtext" and map the result on the context order elements.
Technically, ft:query implements the Optimizable interface and is thus subject to query rewriting. eXist will thus try to evaluate the full text lookup up front, assuming that it will limit the node set to be processed.
If you find that the expression needs further optimization, a frequently applied trick is to do the customer lookup first and then use a reverse axis step to get at the corresponding order parents. This can save a lot of time, but I would only use it if there's really a bottleneck: