1
votes

I'm using MarkLogic client API, and I want to cache the query like cts:register in XQuery.

In XQuery code, we are using this:

let $query := "title:risk"
let $final-query := 
           cts:register(cts:query(search:parse($query,
               <options xmlns="http://marklogic.com/appservices/search">
                    .......
                </options>)))
return cts:search(/, $final-query)

I know that this code will generate a number like 56933683224713984 , and we can get some benefits from MarkLogic optimizing.

However, MarkLoigc client API can't give an API like register query.

How can I optimize my Java code? I worry that MarkLogic can't handle the original query(not registered) and the performance may not be good.

MarkLogic-8 & client-api-4.04

2

2 Answers

1
votes

In addition to extensions you can use AdHoc query feature from the Java API. https://docs.marklogic.com/guide/java/resourceservices#id_47102

Since ultimately the Java API invokes XQuery 'under the hood - via the REST API', using adhoc invocation provides the best 'transparency' and ability to optimize code while still using the Java API at the expense of less type safety and slightly more verbose code. You may be interested in this set of test cases which enumerates multiple ways of doing the same thing with vastly different performance characteristics. YMMV. https://github.com/DALDEI/mlperf

0
votes

See cts:register. It is supported, but I don't see any way to do that through the Java API, but you could use an extension and write XQuery or JavaScript code to register the query.

If this is something you'd like to see added to the Java API, please file an issue on the Java Client API's GitHub page.