Search in sources :

Example 21 with QueryBuilder

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);
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 22 with QueryBuilder

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());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 23 with QueryBuilder

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());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 24 with QueryBuilder

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());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 25 with QueryBuilder

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());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

QueryBuilder (com.cloudant.client.api.query.QueryBuilder)33 Test (org.junit.jupiter.api.Test)33 JsonElement (com.google.gson.JsonElement)3 JsonArray (com.google.gson.JsonArray)1