Search in sources :

Example 6 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class IndexTests method testIndexMovieFindByIndexDesignDocAndName.

@Test
public void testIndexMovieFindByIndexDesignDocAndName() {
    QueryResult<Movie> movies = db.query(new QueryBuilder(and(gt("Movie_year", 1960), eq("Person_name", "Alec Guinness"))).sort(Sort.desc("Movie_year")).fields("Movie_name", "Movie_year").limit(1).skip(1).useIndex("Movie_year", "Movie_year").build(), Movie.class);
    assertNotNull(movies);
    assert (movies.getDocs().size() == 1);
    for (Movie m : movies.getDocs()) {
        assertNotNull(m.getMovie_name());
        assertNotNull(m.getMovie_year());
    }
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class QueryTests method basicSelector1WithAllOptions.

// "Selector basics"
@Test
public void basicSelector1WithAllOptions() {
    QueryBuilder qb = new QueryBuilder(eq("director", "Lars von Trier")).fields("_id", "_rev", "year", "title").sort(Sort.asc("year"), Sort.desc("director")).limit(10).skip(0);
    Assertions.assertEquals("{\"selector\": {\"director\": {\"$eq\": \"Lars von Trier\"}}, " + "\"fields\": [\"_id\", \"_rev\", \"year\", \"title\"], " + "\"sort\": [{\"year\": \"asc\"}, {\"director\": \"desc\"}], \"limit\": 10, " + "\"skip\": 0}", qb.build());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 8 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class QueryTests method basicSelector12.

// "$lt operator used with database indexed on the field "year""
// (similar for all (in)equality tests, so one is representative
@Test
public void basicSelector12() {
    QueryBuilder qb = new QueryBuilder(lt("year", 1900));
    Assertions.assertEquals("{\"selector\": {\"year\": {\"$lt\": 1900}}}", qb.build());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 9 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class QueryTests method basicSelector6.

// "$or operator used with full text indexing"
@Test
public void basicSelector6() {
    QueryBuilder qb = new QueryBuilder(or(eq("director", "George Lucas"), eq("director", "Steven Spielberg")));
    Assertions.assertEquals("{\"selector\": {\"$or\": [{\"director\": {\"$eq\": \"George " + "Lucas\"}}, {\"director\": {\"$eq\": \"Steven Spielberg\"}}]}}", qb.build());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 10 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class QueryTests method basicSelector11.

// "elemMatch operator used with full text indexing"
@Test
public void basicSelector11() {
    QueryBuilder qb = new QueryBuilder(elemMatch("genre", PredicateExpression.eq("Horror")));
    Assertions.assertEquals("{\"selector\": {\"genre\": {\"$elemMatch\": {\"$eq\": " + "\"Horror\"}}}}", 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