0
votes

I am evaluating MarkLogic to use in a new java application we are building to store complex xml documents. One of the requirements is to allow users to search for documents by entering xpath queries in a gui. I am unable to find a way in MarkLogic to say find all documents where /a/b/c = ‘A’ and /a/d/e = ‘B’. I can see ways of saying find documents where element of name x has value y but not for full xpaths. Any help would be appreciated.

Thanks

Bruce

2
Could you elaborate on the use-case? We don't often see the request to allow end-users to enter XPath queries.. - grtjn
We are creating a database of trades and need to be able to answer questions such as which trades were carried out by user x in the last month or how many commodity trades were carried out in the last week or which trades were carried out by trader x on instrument y. There are many other potential queries. Some element names such as instrument or currency appear at a number of places in the document, so can't just do searches on element name equals a value as we need to search for the currency element at a specific place in the document. - Bruce
It sounds like ordinary facets on trade documents to me, but you'd have to store each trade in a separate document. If you do however, you'll get high performance as well. You can use path range indexes to target currency elements at specific places.. - grtjn

2 Answers

0
votes

An XPath expression like this would work:

collection()[(/a/b/c = 'A') and (/a/d/e = 'B')]

Using cts queries might perform better though, and cts:search allows sorting your documents as well in a highly-performant way too. Sorting with a FLWOR can not always be optimized by MarkLogic causing it to take minutes rather than sub-second.

HTH!

0
votes

On the narrow question of submitting XPaths for search using the Java API ...

The QueryManager executes search requests using the MarkLogic Search API.

You can create combined query XML structure with both the query options and wrap it with RawCombinedQueryDefinition to pass it to QueryManager.search():

http://docs.marklogic.com/javadoc/client/com/marklogic/client/query/RawCombinedQueryDefinition.html

The query options can specify a constrained XPath with a search:searchable-expression element:

http://docs.marklogic.com/guide/search-dev/appendixa#id_60011

All that said, as Geert points out, it would be much better to split out each trade as a separate document so documents can be indexed and retrieved independently -- and so users don't have to understand the document hierarchy.