Search in sources :

Example 16 with QueryBuilder

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

the class QueryTests method basicSelector7.

// "$or operator used with database indexed on the field "year"
@Test
public void basicSelector7() {
    QueryBuilder qb = new QueryBuilder(and(eq("year", 1977), or(eq("director", "George Lucas"), eq("director", "Steven Spielberg"))));
    Assertions.assertEquals("{\"selector\": {\"$and\": [{\"year\": {\"$eq\": 1977}}, " + "{\"$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 17 with QueryBuilder

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

the class QueryTests method basicSelector1.

// "Selector basics"
@Test
public void basicSelector1() {
    QueryBuilder qb = new QueryBuilder(eq("director", "Lars von Trier"));
    Assertions.assertEquals("{\"selector\": {\"director\": {\"$eq\": \"Lars von Trier\"}}}", qb.build());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 18 with QueryBuilder

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

the class QueryTests method basicSelector3.

// "SUBFIELDS"
@Test
public void basicSelector3() {
    QueryBuilder qb = new QueryBuilder(eq("imdb.rating", 8));
    Assertions.assertEquals("{\"selector\": {\"imdb.rating\": {\"$eq\": 8}}}", qb.build());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 19 with QueryBuilder

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

the class QueryTests method basicSelector5_single.

// "$and operator used with full text indexing"
@Test
public void basicSelector5_single() {
    QueryBuilder qb = new QueryBuilder(and(eq("$text", "Schwarzenegger"), in("year", 1984)));
    Assertions.assertEquals("{\"selector\": {\"$and\": [{\"$text\": {\"$eq\": " + "\"Schwarzenegger\"}}, {\"year\": {\"$in\": [1984]}}]}}", qb.build());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 20 with QueryBuilder

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

the class IndexTests method testNotNullIndexMovieNameAndYear.

/* Current API tests */
@Test
public void testNotNullIndexMovieNameAndYear() {
    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").executionStats(true).build(), Movie.class);
    assertNotNull(movies);
    assert (movies.getDocs().size() > 0);
    // TODO assert order
    for (Movie m : movies.getDocs()) {
        assertNotNull(m.getMovie_name());
        assertNotNull(m.getMovie_year());
    }
    assertTrue(movies.getExecutionStats().getExecutionTimeMs() > 0);
    assertTrue(movies.getExecutionStats().getResultsReturned() > 0);
    assertTrue(movies.getExecutionStats().getTotalDocsExamined() > 0);
}
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