public class QueryBuilder
extends java.lang.Object
Helper class for building query selector strings.
Example usage to return the name and year of movies starring Alec Guinness since 1960 with the results sorted by year descending:
String query = db.query(new QueryBuilder(and(
gt("Movie_year", 1960),
eq("Person_name", "Alec Guinness"))).
sort(Sort.desc("Movie_year")).
fields("Movie_name", "Movie_year").
build();
The resulting string can then be used to query the database using either
Database.query(String, Class)
(which deserialises the results)
or CloudantClient.executeRequest(HttpConnection)
(which can
be used to make a "raw" request by POSTing the string to the /_find
endpoint).
Selector
Constructor and Description |
---|
QueryBuilder(Selector selector)
Construct a
QueryBuilder object for use with
Database.query(String, Class) |
Modifier and Type | Method and Description |
---|---|
QueryBuilder |
bookmark(java.lang.String bookmark)
Set the bookmark option for the query builder.
|
java.lang.String |
build()
Build string representation of query for use with
Database.query(String, Class) . |
QueryBuilder |
executionStats(boolean executionStats)
Set the executionStats option for the query builder.
|
QueryBuilder |
fields(java.lang.String... fields)
Set the fields option for the query builder.
|
QueryBuilder |
limit(long limit)
Set the limit option for the query builder.
|
QueryBuilder |
skip(long skip)
Set the skip option for the query builder.
|
QueryBuilder |
sort(Sort... sort)
Set the sort option for the query builder.
|
QueryBuilder |
stable(boolean stable)
Set the stable option for the query builder.
|
QueryBuilder |
update(boolean update)
Set the update option for the query builder.
|
QueryBuilder |
useIndex(java.lang.String designDocument)
Instruct a query to use a specific index.
|
QueryBuilder |
useIndex(java.lang.String designDocument,
java.lang.String indexName)
Instruct a query to use a specific index.
|
public QueryBuilder(Selector selector)
Construct a QueryBuilder
object for use with
Database.query(String, Class)
Obtain a selector from an Operation
or Expression
.
selector
- Selector
object describing criteria used to select
documents.Database.query(String, Class)
,
Selector
public QueryBuilder fields(java.lang.String... fields)
fields
- List specifying which fields of each document should be returned. If it is
omitted, the entire document is returned.QueryBuilder
object for method chaining.public QueryBuilder sort(Sort... sort)
sort
- List specifying sort order of returned documents.QueryBuilder
object for method chaining.public QueryBuilder limit(long limit)
limit
- Maximum number of results returned. Default is 25.QueryBuilder
object for method chaining.public QueryBuilder skip(long skip)
skip
- Skip the first n
results, where n
is the value specified.QueryBuilder
object for method chaining.public QueryBuilder bookmark(java.lang.String bookmark)
bookmark
- A string that enables you to specify which page of results you require.
Used for paging through result sets. Every query returns an opaque string
under the bookmark key that can then be passed back in a query to get the
next page of results. If any part of the selector query changes between
requests, the results are undefined.QueryBuilder
object for method chaining.public QueryBuilder update(boolean update)
update
- Whether to update the index prior to returning the result. Default is true
.QueryBuilder
object for method chaining.public QueryBuilder stable(boolean stable)
stable
- Whether or not the view results should be returned from a "stable" set of shards.QueryBuilder
object for method chaining.public QueryBuilder executionStats(boolean executionStats)
executionStats
- Include execution statistics in the query response. Defailt is
false
QueryBuilder
object for method chaining.public QueryBuilder useIndex(java.lang.String designDocument)
designDocument
- Design document to use.QueryBuilder
object for method chaining.public QueryBuilder useIndex(java.lang.String designDocument, java.lang.String indexName)
designDocument
- Design document to use.indexName
- Index name to use.QueryBuilder
object for method chaining.public java.lang.String build()
Database.query(String, Class)
.