0
votes

We are using XQuery for MarkLogic query before. And we want to replace with Java as it more widely used.

Everything is fine before I meet with the module query.

import module namespace ent = "http://xxx.xx/model/entitlements" at "/Entitlements/entitlements.xqy";

And in the Xquery, we are using below.

let $final-query := ent:query($query, $cvUserId)
let $docs := cts:search(/, $final-query)
return $docs

ent:query(xx,xx) is in our Linux server which we can't get the source code. As the name side, this query will do entitlement check when execute the search.

I have write below Java code to get the result.

QueryManager queryManager = markLogicClient.newQueryManager();
StringQueryDefinition queryDef = queryManager.newStringDefinition("OPTIONS");
queryDef.setCriteria("Title:test");
XMLDocumentManager dManager = markLogicClient.newXMLDocumentManager();
DocumentPage docs = dManager.search(queryDef, 1, new DOMHandle());
dManager.search(queryDef, 1);

It works well for my test, but without the entitlement check.

Is there any to apply my own query ent:query(xx,xx) with Java ?

Marklogic-8 & marklogic-client-api-4.0.4

2

2 Answers

2
votes

Java and XQuery API's in MarkLogic are not comparable, they fill different use cases, and in fact the Java API ends up calling XQuery.

XQuery (and JavaScript) runs within the server, Java API runs outside the server and calls the REST API which then invokes XQuery in the server. If you have perfectly good XQuery it makes little sense to rewrite that with Java -- at best, performance will suffer. Instead, you can invoke your XQuery from Java API either as an 'ad hoc' expression or as a stored module. This allows you to expose a Java API for the parts of your app that benefit from a java API but keep the existing code. For new code, where it makes sense to do so, the Java API is quite good, but for the cases where you find it does not fill you needs you can apply the same technique as above and still provide the the same integration to your app.

You can see some examples of various ways to invoke ML using the Java API as well as performance bench marks here: https://github.com/DALDEI/mlperf

0
votes

Keep your existing XQuery code and create beautiful RESTful Web Services using simple XQRS functions to hook it all up.