Skip to content

Commit 8587d1e

Browse files
llingllinggit
authored andcommitted
code and unit test for #1196
1 parent 66d639f commit 8587d1e

File tree

5 files changed

+155
-20
lines changed

5 files changed

+155
-20
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/document/DocumentManager.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,19 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
593593
*/
594594
DocumentPage search(QueryDefinition querydef, long start);
595595

596+
/**
597+
* Just like {@link QueryManager#search(QueryDefinition, SearchReadHandle, long) QueryManager.search}
598+
* but return complete documents via iterable DocumentPage. Retrieves up to getPageLength()
599+
* documents in each DocumentPage. If setMetadataCategories has
600+
* been called, populates metadata for each result in the format specified by
601+
* {@link #setNonDocumentFormat setNonDocumentFormat}.
602+
* @param querydef the definition of query criteria and query options
603+
* @param start the offset of the first document in the page (where 1 is the first result)
604+
* @param forestName a forest to limit this search
605+
* @return the DocumentPage of matching documents and metadata
606+
*/
607+
DocumentPage search(QueryDefinition querydef, long start, String forestName);
608+
596609
/**
597610
* Just like {@link QueryManager#search(QueryDefinition, SearchReadHandle, long) QueryManager.search}
598611
* but return complete documents via iterable DocumentPage. Retrieves up to getPageLength()
@@ -623,6 +636,20 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
623636
*/
624637
DocumentPage search(QueryDefinition querydef, long start, Transaction transaction);
625638

639+
/**
640+
* Just like {@link QueryManager#search(QueryDefinition, SearchReadHandle, long, Transaction) QueryManager.search}
641+
* but return complete documents via iterable DocumentPage. Retrieves up to getPageLength()
642+
* documents in each DocumentPage. If setMetadataCategories has
643+
* been called, populates metadata for each result in the format specified by
644+
* {@link #setNonDocumentFormat setNonDocumentFormat}.
645+
* @param querydef the definition of query criteria and query options
646+
* @param start the offset of the first document in the page (where 1 is the first result)
647+
* @param transaction an open transaction for matching documents
648+
* @param forestName a forest to limit this search
649+
* @return the DocumentPage of matching documents and metadata
650+
*/
651+
DocumentPage search(QueryDefinition querydef, long start, Transaction transaction, String forestName);
652+
626653
/**
627654
* Just like {@link QueryManager#search(QueryDefinition, SearchReadHandle, long, Transaction) QueryManager.search}
628655
* but return complete documents via iterable DocumentPage. Retrieves up to getPageLength()
@@ -657,6 +684,23 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
657684
*/
658685
DocumentPage search(QueryDefinition querydef, long start, SearchReadHandle searchHandle);
659686

687+
/**
688+
* Just like {@link QueryManager#search(QueryDefinition, SearchReadHandle, long) QueryManager.search}
689+
* but return complete documents via iterable DocumentPage. Retrieves up to getPageLength()
690+
* documents in each DocumentPage. If searchHandle is not null,
691+
* requests a search response and populates searchHandle with it. If setMetadataCategories has
692+
* been called, populates metadata for each result in the format specified by
693+
* {@link #setNonDocumentFormat setNonDocumentFormat}.
694+
* @param querydef the definition of query criteria and query options
695+
* @param start the offset of the first document in the page (where 1 is the first result)
696+
* @param searchHandle a handle for reading the search response which will include view types
697+
* specified by {@link #setSearchView setSearchView} and format specified by
698+
* {@link #setNonDocumentFormat setNonDocumentFormat}
699+
* @param forestName a forest to limit this search
700+
* @return the DocumentPage of matching documents and metadata
701+
*/
702+
DocumentPage search(QueryDefinition querydef, long start, SearchReadHandle searchHandle, String forestName);
703+
660704
/**
661705
* Just like {@link QueryManager#search(QueryDefinition, SearchReadHandle, long, Transaction)}
662706
* but return complete documents via iterable DocumentPage. Retrieves up to getPageLength()
@@ -674,6 +718,24 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
674718
*/
675719
DocumentPage search(QueryDefinition querydef, long start, SearchReadHandle searchHandle, Transaction transaction);
676720

721+
/**
722+
* Just like {@link QueryManager#search(QueryDefinition, SearchReadHandle, long, Transaction)}
723+
* but return complete documents via iterable DocumentPage. Retrieves up to getPageLength()
724+
* documents in each DocumentPage. If searchHandle is not null,
725+
* requests a search response and populates searchHandle with it. If setMetadataCategories has
726+
* been called, populates metadata for each result in the format specified by
727+
* {@link #setNonDocumentFormat setNonDocumentFormat}.
728+
* @param querydef the definition of query criteria and query options
729+
* @param start the offset of the first document in the page (where 1 is the first result)
730+
* @param searchHandle a handle for reading the search response which will include view types
731+
* specified by {@link #setSearchView setSearchView} and format specified by
732+
* {@link #setNonDocumentFormat setNonDocumentFormat}
733+
* @param transaction an open transaction for matching documents
734+
* @param forestName a forest to limit this search
735+
* @return the DocumentPage of matching documents and metadata
736+
*/
737+
DocumentPage search(QueryDefinition querydef, long start, SearchReadHandle searchHandle, Transaction transaction, String forestName);
738+
677739
/** Get the maximum number of records to return in a page from calls to {@link #search search}
678740
* @return the maximum number of records to return in a page from calls to
679741
* {@link #search search} */

marklogic-client-api/src/main/java/com/marklogic/client/impl/DocumentManagerImpl.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,38 +484,61 @@ public DocumentPage readMetadata(Transaction transaction, String... uris) {
484484

485485
@Override
486486
public DocumentPage search(QueryDefinition querydef, long start) {
487-
return search(querydef, start, -1, null, null);
487+
return search(querydef, start, -1, null, null, null);
488+
}
489+
490+
@Override
491+
public DocumentPage search(QueryDefinition querydef, long start, String forestName) {
492+
return search(querydef, start, -1, null, null, forestName);
488493
}
489494

490495
public DocumentPage search(QueryDefinition querydef, long start, long serverTimestamp) {
491-
return search(querydef, start, serverTimestamp, null, null);
496+
return search(querydef, start, serverTimestamp, null, null, null);
492497
}
493498

494499
@Override
495500
public DocumentPage search(QueryDefinition querydef, long start,
496501
SearchReadHandle searchHandle) {
497-
return search(querydef, start, -1, searchHandle, null);
502+
return search(querydef, start, -1, searchHandle, null, null);
503+
}
504+
505+
@Override
506+
public DocumentPage search(QueryDefinition querydef, long start,
507+
SearchReadHandle searchHandle, String forestName) {
508+
return search(querydef, start, -1, searchHandle, null, forestName);
498509
}
499510

500511
@Override
501512
public DocumentPage search(QueryDefinition querydef, long start,
502513
Transaction transaction) {
503-
return search(querydef, start, -1, null, transaction);
514+
return search(querydef, start, -1, null, transaction, null);
515+
}
516+
517+
@Override
518+
public DocumentPage search(QueryDefinition querydef, long start,
519+
Transaction transaction, String forestName) {
520+
return search(querydef, start, -1, null, transaction, forestName);
504521
}
505522

506523
public DocumentPage search(QueryDefinition querydef, long start,
507524
long serverTimestamp, Transaction transaction) {
508-
return search(querydef, start, serverTimestamp, null, transaction);
525+
return search(querydef, start, serverTimestamp, null, transaction, null);
509526
}
510527

511528
@Override
512529
public DocumentPage search(QueryDefinition querydef, long start,
513530
SearchReadHandle searchHandle, Transaction transaction) {
514-
return search(querydef, start, -1, searchHandle, transaction);
531+
return search(querydef, start, -1, searchHandle, transaction, null);
532+
}
533+
534+
@Override
535+
public DocumentPage search(QueryDefinition querydef, long start,
536+
SearchReadHandle searchHandle, Transaction transaction, String forestName) {
537+
return search(querydef, start, -1, searchHandle, transaction, forestName);
515538
}
516539

517540
private DocumentPage search(QueryDefinition querydef, long start,
518-
long serverTimestamp, SearchReadHandle searchHandle, Transaction transaction) {
541+
long serverTimestamp, SearchReadHandle searchHandle, Transaction transaction, String forestName) {
519542

520543
if (searchHandle != null) {
521544
HandleImplementation searchBase = HandleAccessor.checkHandle(
@@ -540,7 +563,7 @@ private DocumentPage search(QueryDefinition querydef, long start,
540563
: null;
541564
return services.getBulkDocuments(requestLogger, serverTimestamp, querydef, start,
542565
getPageLength(), transaction, searchHandle, searchView, metadata,
543-
nonDocumentFormat, getReadTransform(), null);
566+
nonDocumentFormat, getReadTransform(), null, forestName);
544567
}
545568

546569
@Override

marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,14 +948,14 @@ public DocumentPage getBulkDocuments(RequestLogger reqlog, long serverTimestamp,
948948
Transaction transaction,
949949
SearchReadHandle searchHandle, QueryView view,
950950
Set<Metadata> categories, Format format, ServerTransform responseTransform,
951-
RequestParameters extraParams)
951+
RequestParameters extraParams, String forestName)
952952
throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException
953953
{
954954
boolean hasMetadata = categories != null && categories.size() > 0;
955955
boolean hasContent = true;
956956
OkHttpResultIterator iterator =
957957
getBulkDocumentsImpl(reqlog, serverTimestamp, querydef, start, pageLength, transaction,
958-
searchHandle, view, categories, format, responseTransform, extraParams);
958+
searchHandle, view, categories, format, responseTransform, extraParams, forestName);
959959
return new OkHttpDocumentPage(iterator, hasContent, hasMetadata);
960960
}
961961

@@ -1066,7 +1066,7 @@ private OkHttpResultIterator getBulkDocumentsImpl(RequestLogger reqlog, long ser
10661066
QueryDefinition querydef, long start, long pageLength,
10671067
Transaction transaction, SearchReadHandle searchHandle, QueryView view,
10681068
Set<Metadata> categories, Format format, ServerTransform responseTransform,
1069-
RequestParameters extraParams)
1069+
RequestParameters extraParams, String forestName)
10701070
throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException
10711071
{
10721072
try {
@@ -1090,7 +1090,7 @@ private OkHttpResultIterator getBulkDocumentsImpl(RequestLogger reqlog, long ser
10901090
}
10911091

10921092
OkHttpSearchRequest request =
1093-
generateSearchRequest(reqlog, querydef, MIMETYPE_MULTIPART_MIXED, transaction, responseTransform, params, null);
1093+
generateSearchRequest(reqlog, querydef, MIMETYPE_MULTIPART_MIXED, transaction, responseTransform, params, forestName);
10941094
Response response = request.getResponse();
10951095
if ( response == null ) return null;
10961096
MimeMultipart entity = null;

marklogic-client-api/src/main/java/com/marklogic/client/impl/RESTServices.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ public DocumentPage getBulkDocuments(RequestLogger logger, long serverTimestamp,
146146
throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException;
147147
public DocumentPage getBulkDocuments(RequestLogger logger, long serverTimestamp, QueryDefinition querydef,
148148
long start, long pageLength, Transaction transaction, SearchReadHandle searchHandle,
149-
QueryView view, Set<Metadata> categories, Format format, ServerTransform responseTransform, RequestParameters extraParams)
149+
QueryView view, Set<Metadata> categories, Format format, ServerTransform responseTransform,
150+
RequestParameters extraParams, String forestName)
150151
throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException;
151152

152153
public void postBulkDocuments(RequestLogger logger, DocumentWriteSet writeSet,
@@ -451,7 +452,7 @@ public int hashCode() {
451452
@Override
452453
public boolean equals(Object arg0) {
453454
CallField callField = (CallField)arg0;
454-
if(this.getParamName()!=null && callField.getParamName()!=null &&
455+
if(this.getParamName()!=null && callField.getParamName()!=null &&
455456
this.getParamName().equals(callField.getParamName()))
456457
return true;
457458
return false;

marklogic-client-api/src/test/java/com/marklogic/client/test/document/DocumentWriteOperationTest.java

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,23 @@
1515
*/
1616
package com.marklogic.client.test.document;
1717

18-
import com.marklogic.client.document.DocumentWriteOperation;
19-
import com.marklogic.client.document.DocumentWriteSet;
20-
import com.marklogic.client.document.TextDocumentManager;
18+
import com.marklogic.client.document.*;
2119
import com.marklogic.client.io.DocumentMetadataHandle;
2220
import com.marklogic.client.io.Format;
2321
import com.marklogic.client.io.StringHandle;
2422
import com.marklogic.client.query.DeleteQueryDefinition;
2523
import com.marklogic.client.query.QueryManager;
24+
import com.marklogic.client.query.StructuredQueryBuilder;
25+
import com.marklogic.client.query.StructuredQueryDefinition;
2626
import com.marklogic.client.test.Common;
2727
import org.junit.AfterClass;
2828
import org.junit.BeforeClass;
2929
import org.junit.Test;
3030

3131
import static org.junit.Assert.assertEquals;
32+
import static org.junit.Assert.assertTrue;
3233

33-
import java.util.ArrayList;
34-
import java.util.Iterator;
35-
import java.util.List;
34+
import java.util.*;
3635

3736
public class DocumentWriteOperationTest {
3837

@@ -309,6 +308,56 @@ public void DocumentWriteSetWithDisableMetadataTest_2() {
309308
textDocumentManager.write(batch);
310309
}
311310

311+
@Test
312+
public void DocumentQueryWithForest() {
313+
DocumentWriteSet batch = textDocumentManager.newWriteSet();
314+
batch.addDefault(defaultMetadata1);
315+
316+
for (int i = 0; i < 30; i++) {
317+
String uri = "doc" + i + ".txt";
318+
StringHandle handle = new StringHandle("Document - " + i).withFormat(Format.TEXT);
319+
batch.add(uri, handle);
320+
}
321+
322+
textDocumentManager.write(batch);
323+
StructuredQueryDefinition query = new StructuredQueryBuilder().collection(collectionName);
324+
325+
DocumentPage documentsF1 = textDocumentManager.search(query, 1, "java-unittest-1");
326+
DocumentPage documentsF2 = textDocumentManager.search(query, 1, "java-unittest-2");
327+
DocumentPage documentsF3 = textDocumentManager.search(query, 1, "java-unittest-3");
328+
329+
long totalCount = documentsF1.getTotalSize() + documentsF2.getTotalSize() + documentsF3.getTotalSize();
330+
assertEquals(30, totalCount);
331+
332+
Set<String> set1 = new HashSet<>();
333+
Set<String> set2 = new HashSet<>();
334+
Set<String> set3 = new HashSet<>();
335+
336+
for (DocumentRecord document : documentsF1) {
337+
set1.add(document.getUri());
338+
}
339+
340+
for (DocumentRecord document : documentsF2) {
341+
set2.add(document.getUri());
342+
}
343+
344+
for (DocumentRecord document : documentsF3) {
345+
set3.add(document.getUri());
346+
}
347+
348+
Set<String> intersectSet = new HashSet<>(set1);
349+
intersectSet.retainAll(set2);
350+
assertTrue(intersectSet.isEmpty());
351+
352+
intersectSet.addAll(set1);
353+
intersectSet.retainAll(set3);
354+
assertTrue(intersectSet.isEmpty());
355+
356+
intersectSet.addAll(set2);
357+
intersectSet.retainAll(set3);
358+
assertTrue(intersectSet.isEmpty());
359+
}
360+
312361
@AfterClass
313362
public static void cleanup() {
314363
QueryManager queryManager = Common.client.newQueryManager();

0 commit comments

Comments
 (0)