Reputation: 93
I have started working on the MarkLogic database using the Java Client API. I have two use cases for me :-
JSON is in the form
{
"id" : "12345"
"date" : "2012-12-12",
"messageType" : "dummy_type",
....
}
I am able to do this using the below code :-
val queryMgr = client.newQueryManager();
var rawHandle: StringHandle = new StringHandle
rawHandle.withFormat(Format.JSON).set("{\"$query\": {\"tradingDate\": { \"$le\":\""+ date + "\"}, \"$filtered\": true}}");
var querydef: RawQueryByExampleDefinition = queryMgr.newRawQueryByExampleDefinition(rawHandle);
querydef.setCollections(collectionName);
jsonDocMgr.search(querydef, 1);
Now I have multiple documents in the database, where multiple documents are part of one id but there message types are different. As in I have A, B and C as message types with all have id as 12345. Now depending upon the date parameter in type C, I want to make a decision whether all documents (A, B, and C) need to be fetched or should not be fetched.
Could anyone please suggest whether I can create javascript functions and pass it to the MarkLogic db using the Java Client API or any other thing or any references?
Upvotes: 1
Views: 250
Reputation: 2475
I'd recommend you start by looking at transforming search results. To use them you'll need to follow the instructions to install and test the transform via REST or Java, then add querydef.setResponseTransform(new ServerTransform("yourTransformName")
then call QueryManager.search(querydef, new SearchHandle())
. You can decide what your transform should return for each query match.
Upvotes: 1