use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.
the class IndexTests method testBookmarks.
@Test
public void testBookmarks() {
QueryBuilder queryBuilder = new QueryBuilder(and(gt("Movie_year", 1960), eq("Person_name", "Alec Guinness"))).sort(Sort.desc("Movie_year")).fields("Movie_name", "Movie_year").limit(2);
QueryResult<Movie> moviesPage;
String bookmark = null;
int pageCount = 0;
QueryBuilder queryBuilderBookmarked = queryBuilder;
do {
if (bookmark != null) {
queryBuilderBookmarked = queryBuilder.bookmark(bookmark);
}
moviesPage = db.query(queryBuilderBookmarked.build(), Movie.class);
bookmark = moviesPage.getBookmark();
if (!moviesPage.getDocs().isEmpty()) {
pageCount++;
}
} while (!moviesPage.getDocs().isEmpty());
assertEquals(3, pageCount);
}
use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.
the class QueryTests method basicSelector2.
// "Selector with two fields"
@Test
public void basicSelector2() {
QueryBuilder qb = new QueryBuilder(and(eq("name", "Paul"), eq("location", "Boston")));
Assertions.assertEquals("{\"selector\": {\"$and\": [{\"name\": {\"$eq\": \"Paul\"}}, " + "{\"location\": {\"$eq\": \"Boston\"}}]}}", qb.build());
}
use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.
the class QueryTests method basicSelector5.
// "$and operator used with full text indexing"
@Test
public void basicSelector5() {
QueryBuilder qb = new QueryBuilder(and(eq("$text", "Schwarzenegger"), in("year", 1984, 1991)));
Assertions.assertEquals("{\"selector\": {\"$and\": [{\"$text\": {\"$eq\": " + "\"Schwarzenegger\"}}, {\"year\": {\"$in\": [1984, 1991]}}]}}", qb.build());
}
use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.
the class QueryTests method basicSelector9.
// "$nor operator used with database indexed on the field "year""
@Test
public void basicSelector9() {
QueryBuilder qb = new QueryBuilder(and(gte("year", 1900), lte("year", 1910), nor(eq("year", 1901), eq("year", 1905), eq("year", 1907))));
Assertions.assertEquals("{\"selector\": {\"$and\": [{\"year\": {\"$gte\": 1900}}, " + "{\"year\": {\"$lte\": 1910}}, {\"$nor\": [{\"year\": {\"$eq\": 1901}}, " + "{\"year\": {\"$eq\": 1905}}, {\"year\": {\"$eq\": 1907}}]}]}}", qb.build());
}
use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.
the class QueryTests method basicSelector10.
// "$all operator used with full text indexing"
@Test
public void basicSelector10() {
QueryBuilder qb = new QueryBuilder(all("genre", "Comedy", "Short"));
Assertions.assertEquals("{\"selector\": {\"genre\": {\"$all\": [\"Comedy\", " + "\"Short\"]}}}", qb.build());
}
Aggregations