[英]How to list all the objects in response to a query using cloudant java client?
I am using cloudant-client 2.17.0. 我正在使用cloudant-client 2.17.0。 I have a partitioned db and want to make a query to get all the documents which match it. 我有一个分区的数据库,想要查询以获取与其匹配的所有文档。
com.cloudant.client.api.Database class's query methods returns a QueryResult object, which has bookmark field in it. com.cloudant.client.api.Database类的查询方法返回一个QueryResult对象,该对象中具有书签字段。 I cannot find any query method which takes this bookmark as argument. 我找不到任何使用此书签作为参数的查询方法。 So do all the query methods (of com.cloudant.client.api.Database) by default return all the documents or is there a query method somewhere which takes this bookmark as argument? 那么,默认情况下,(com.cloudant.client.api.Database的)所有查询方法是否都返回所有文档,或者某个地方是否存在使用此书签作为参数的查询方法? If there is such method, how do I get the page size? 如果有这种方法,如何获取页面大小? Cloudant doc mentions, right way to check if a certain page is the last page of result is to check if the result size < page size. Cloudant文档提到,检查某个页面是否是结果的最后一页的正确方法是检查结果大小是否小于页面大小。
You can set the bookmark in QueryBuilder
helper class and pass that to the Database query
method. 您可以在QueryBuilder
帮助器类中设置书签,并将其传递给数据库query
方法。 Here's a QueryBuilder example from the java-cloudant API documentation : 这是java-cloudant API文档中的QueryBuilder示例:
QueryBuilder queryBuilder = db.query(new QueryBuilder(and(
gt("Movie_year", 1960),
eq("Person_name", "Alec Guinness"))).
sort(Sort.desc("Movie_year")).
fields("Movie_name", "Movie_year").
bookmark("some-bookmark").
limit(2);
Then you'd pass the query
variable to db.query
where db
is com.cloudant.client.api.Database
然后将query
变量传递给db.query
,其中db
是com.cloudant.client.api.Database
QueryResult<Movie> moviesPage = db.query(queryBuilder.build(), Movie.class);
This test case shows how to use bookmark
to get all docs per page: https://github.com/cloudant/java-cloudant/blob/master/cloudant-client/src/test/java/com/cloudant/tests/IndexTests.java#L254-L278 . 这个测试案例展示了如何使用bookmark
获取每页的所有文档: https : //github.com/cloudant/java-cloudant/blob/master/cloudant-client/src/test/java/com/cloudant/tests/IndexTests .java#L254-L278
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.