Search code examples
marklogicmarklogic-8marklogic-9

Retrieve All Document Count Varies in MarkLogic 9


I Recently Upgraded from MarkLogic-8 to MarkLogic-9, and i am having following set of Documents in MarkLogic-8,

Collection - System, User
Document URI - /user.xml

Collection - System, Role
Document URI - /role.xml

Collection - System, Admin
Document URI - 1.   /systemadmin.xml
               2.   /accountadmin.xml

Following is Sample java code snippet that i am using to retrieve all the documents from collections

String[] collections = {"System", "Admin"};
QueryManager queryMgr = client.newQueryManager();
SearchHandle resultsHandle = new SearchHandle();

StringQueryDefinition query = queryMgr.newStringDefinition();
query.setCollections(collections);
queryMgr.setPageLength(Long.parseLong(UIParam.PAGINATION_PAGE_LENGTH));
queryMgr.search(query, resultsHandle);

When I execute above java code snippet on MarkLogic-8, i got /systemadmin.xml and accountadmin.xml as result and this is correct result,

but now when i am executing above code against MarkLogic-9 i am getting all the documents /user.xml, /role.xml, /systemadmin.xml, /accountadmin.xml and this is wrong result.

<dependency>
  <groupId>com.marklogic</groupId>
  <artifactId>marklogic-client-api</artifactId>
  <version>4.1.0</version>
</dependency>

Maven dependency for MarkLogic-9

I am confused that why there is difference between MarkLogic-8 and MarkLogic-9 result.

Please help me to Resolve this issue.


Solution

  • MarkLogic 9 fixed a bug that changed the semantics of collection lists from AND-related to OR-related:

    http://docs.marklogic.com/guide/relnotes/chap4#id_76507

    To get AND-related semantics in the Java API, you can use the StructuredQueryBuilder to specify an AndQuery over a CollectionQuery array. Replacing the existing query with something similar to the follow sketch should work:

    StructuredQueryBuilder qb = StructuredQueryBuilder();
    StructuredQueryDefinition query = qb.and(qb.collection("System"), qb.collection("Admin"));
    queryMgr.setPageLength(Long.parseLong(UIParam.PAGINATION_PAGE_LENGTH));
    queryMgr.search(query, resultsHandle);
    

    For more information about the collection() query builder, see:

    http://docs.marklogic.com/javadoc/client/com/marklogic/client/query/StructuredQueryBuilder.html#containerQuery-com.marklogic.client.query.StructuredQueryBuilder.ContainerIndex-com.marklogic.client.query.StructuredQueryDefinition-

    Hoping that helps,