|
29 | 29 | import javax.xml.bind.JAXBException; |
30 | 30 |
|
31 | 31 | import static org.junit.Assert.assertEquals; |
| 32 | +import static org.junit.Assert.assertFalse; |
32 | 33 | import static org.junit.Assert.assertNotNull; |
33 | 34 | import static org.junit.Assert.assertTrue; |
34 | 35 |
|
|
60 | 61 | import com.marklogic.client.io.SearchHandle; |
61 | 62 | import com.marklogic.client.io.StringHandle; |
62 | 63 | import com.marklogic.client.query.DeleteQueryDefinition; |
| 64 | +import com.marklogic.client.query.MatchDocumentSummary; |
63 | 65 | import com.marklogic.client.query.QueryDefinition; |
64 | 66 | import com.marklogic.client.query.QueryManager; |
| 67 | +import com.marklogic.client.query.StringQueryDefinition; |
65 | 68 | import com.marklogic.client.query.StructuredQueryBuilder; |
| 69 | +import com.marklogic.client.query.QueryManager.QueryView; |
66 | 70 |
|
67 | 71 | /** Loads data from cities15000.txt which contains every city above 15000 people, and adds |
68 | 72 | * data from countryInfo.txt. |
@@ -426,6 +430,84 @@ public void testF_DefaultMetadata() { |
426 | 430 | } |
427 | 431 | } |
428 | 432 |
|
| 433 | + @Test |
| 434 | + public void test_78() { |
| 435 | + String DIRECTORY ="/test_78/"; |
| 436 | + int BATCH_SIZE=10; |
| 437 | + int count =1; |
| 438 | + TextDocumentManager docMgr = Common.client.newTextDocumentManager(); |
| 439 | + DocumentWriteSet writeset =docMgr.newWriteSet(); |
| 440 | + for(int i =0;i<11;i++){ |
| 441 | + writeset.add(DIRECTORY+"Textfoo"+i+".txt", new StringHandle().with("bar can be foo"+i)); |
| 442 | + if(count%BATCH_SIZE == 0){ |
| 443 | + docMgr.write(writeset); |
| 444 | + writeset = docMgr.newWriteSet(); |
| 445 | + } |
| 446 | + count++; |
| 447 | + } |
| 448 | + if(count%BATCH_SIZE > 0){ |
| 449 | + docMgr.write(writeset); |
| 450 | + } |
| 451 | + //using QueryManger for query definition and set the search criteria |
| 452 | + QueryManager queryMgr = Common.client.newQueryManager(); |
| 453 | + try { |
| 454 | + StringQueryDefinition qd = queryMgr.newStringDefinition(); |
| 455 | + qd.setCriteria("bar"); |
| 456 | + qd.setDirectory(DIRECTORY); |
| 457 | + // set document manager level settings for search response |
| 458 | + System.out.println("Default Page length setting on docMgr :"+docMgr.getPageLength()); |
| 459 | + docMgr.setPageLength(1); |
| 460 | + docMgr.setSearchView(QueryView.RESULTS); |
| 461 | + docMgr.setNonDocumentFormat(Format.XML); |
| 462 | + assertEquals("format set on document manager","XML",docMgr.getNonDocumentFormat().toString()); |
| 463 | + assertEquals("Queryview set on document manager ","RESULTS" ,docMgr.getSearchView().toString()); |
| 464 | + assertEquals("Page length ",1,docMgr.getPageLength()); |
| 465 | + // Search for documents where content has bar and get first result record, get search handle on it |
| 466 | + SearchHandle sh = new SearchHandle(); |
| 467 | + DocumentPage page= docMgr.search(qd, 1); |
| 468 | + // test for page methods |
| 469 | + assertEquals("Number of records",1,page.size()); |
| 470 | + assertEquals("Starting record in first page ",1,page.getStart()); |
| 471 | + assertEquals("Total number of estimated results:",11,page.getTotalSize()); |
| 472 | + assertEquals("Total number of estimated pages :",11,page.getTotalPages()); |
| 473 | + assertTrue("Is this First page :",page.isFirstPage()); |
| 474 | + assertFalse("Is this Last page :",page.isLastPage()); |
| 475 | + assertTrue("Is this First page has content:",page.hasContent()); |
| 476 | + assertFalse("Is first page has previous page ?",page.hasPreviousPage()); |
| 477 | + // |
| 478 | + long start=1; |
| 479 | + do{ |
| 480 | + count=0; |
| 481 | + page = docMgr.search(qd, start,sh); |
| 482 | + if(start >1){ |
| 483 | + assertFalse("Is this first Page", page.isFirstPage()); |
| 484 | + assertTrue("Is page has previous page ?",page.hasPreviousPage()); |
| 485 | + } |
| 486 | + while(page.hasNext()){ |
| 487 | + page.next(); |
| 488 | + count++; |
| 489 | + } |
| 490 | + MatchDocumentSummary[] mds= sh.getMatchResults(); |
| 491 | + assertEquals("Matched document count",1,mds.length); |
| 492 | + //since we set the query view to get only results, facet count supposed be 0 |
| 493 | + assertEquals("Matched Facet count",0,sh.getFacetNames().length); |
| 494 | + |
| 495 | + assertEquals("document count", page.size(),count); |
| 496 | + if (!page.isLastPage()) start = start + page.getPageSize(); |
| 497 | + }while(!page.isLastPage()); |
| 498 | + assertEquals("page count is 11 ",start, page.getTotalPages()); |
| 499 | + assertTrue("Page has previous page ?",page.hasPreviousPage()); |
| 500 | + assertEquals("page size", 1,page.getPageSize()); |
| 501 | + assertEquals("document count", 11,page.getTotalSize()); |
| 502 | + page= docMgr.search(qd, 12); |
| 503 | + assertFalse("Page has any records ?",page.hasContent()); |
| 504 | + } finally { |
| 505 | + DeleteQueryDefinition deleteQuery = queryMgr.newDeleteDefinition(); |
| 506 | + deleteQuery.setDirectory(DIRECTORY); |
| 507 | + queryMgr.delete(deleteQuery); |
| 508 | + } |
| 509 | + } |
| 510 | + |
429 | 511 | @Test |
430 | 512 | public void test_171() throws Exception{ |
431 | 513 | DatabaseClient client = DatabaseClientFactory.newClient( |
|
0 commit comments