我想使用MarkLogic Java API
运行以下查询cts:search(fn:doc(), cts:and-query((cts:collection-query("/abc/xyz"),
cts:collection-query("/abc/xyz/pqr"))))
答案 0 :(得分:6)
使用StructuredQueryBuilder,and()
和collection()
方法构建等效的结构化查询,以搜索两个集合中的文档。
// create the client -- this will change slightly in Java Client API 4.x
DatabaseClient client =
DatabaseClientFactory.newClient(host, port, user, password, authType);
// create a manager for searching
QueryManager queryMgr = client.newQueryManager();
// create a query builder
StructuredQueryBuilder qb = new StructuredQueryBuilder();
// build a search definition
StructuredQueryDefinition query =
qb.and(
qb.collection("/abc/xyz"),
qb.collection("/abc/xyz/pqr"));
// run the search
queryMgr.search(query, resultsHandle);
答案 1 :(得分:2)
您需要使用结构化查询,而不是cts:query。他们的表现力非常相似。 Java Client API包含用于结构化查询的构建器类com.marklogic.client.query.StructuredQueryBuilder。
有关详细信息,请参阅以下内容: