0

If I have to insert a document in MarkLogic, how can I specify in which forest the document should be stored, using the Java API?

Here is an example where I write data to a MarkLogic database :

// create the client
DatabaseClient client = DatabaseClientFactory.newClient(
    props.host, props.port, props.writerUser, props.writerPassword,
    props.authType);

// make use of the client connection
TextDocumentManager docMgr = client.newTextDocumentManager();
String docId = "/example/text.txt";
StringHandle handle = new StringHandle();
handle.set("A simple text document");
docMgr.write(docId, handle);

If I can store the document by specifying the forest, then I also need to fetch the document with the forest specified.

I think it is possible because I have seen storing and searching within a specific forestId in XQuery. Like so:

insert into a specific forest:

xdmp:document-insert(
    $uri as xs:string,$root as node(), 
    [$permissions as element(sec:permission)*], [$collections as xs:string*],      
    [$quality as xs:int?], [$forest-ids as xs:unsignedLong*])
as empty-sequence()

search a specific to forest -

cts:search(
    $expression as node()*, $query as cts:query?,
    [$options as (cts:order|xs:string)*], [$quality-weight as xs:double?], 
    [$forest-ids as xs:unsignedLong*]) as node()*

Please let me know how to do this in the Java API.

Daniel Quinlan
  • 2,639
  • 1
  • 20
  • 23
RCS
  • 1,370
  • 11
  • 27

1 Answers1

1

Today this is not available via Java Client API. It will be available in MarkLogic 9. If you want to try it out in an early access release of MarkLogic 9 you can join the early access program. We would love to hear your feedback after trying out this feature.

In MarkLogic 9 you can do this by specifying the forestName to the DatabaseClientFactory:

DatabaseClient client = DatabaseClientFactory.newClient(
    props.host, props.port, props.writerUser, props.writerPassword,
    props.authType, props.forestName);

Then documents written will be written to that forest and searches will only match within that forest.

Sam Mefford
  • 2,465
  • 10
  • 15