Search in sources :

Example 26 with QueryBuilder

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

the class QueryTests method basicSelector15.

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

Example 27 with QueryBuilder

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

the class QueryTests method basicSelector4.

// "Example selector using an operator to match any document, where the age field has a value
// greater than 20:"
@Test
public void basicSelector4() {
    QueryBuilder qb = new QueryBuilder(gt("year", 2018));
    Assertions.assertEquals("{\"selector\": {\"year\": {\"$gt\": 2018}}}", qb.build());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 28 with QueryBuilder

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

the class QueryTests method complexSelector1.

@Test
public void complexSelector1() {
    QueryBuilder qb = new QueryBuilder(not(and(gt("year", 2009), nin("year", 2010, 2015))));
    Assertions.assertEquals("{\"selector\": {\"$not\": {\"$and\": [{\"year\": {\"$gt\": " + "2009}}, {\"year\": {\"$nin\": [2010, 2015]}}]}}}", qb.build());
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 29 with QueryBuilder

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

the class QueryTests method basicSelector16_single.

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

Example 30 with QueryBuilder

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

the class QueryTests method basicSelector13.

// "$exists operator used with database indexed on the field "year""
@Test
public void basicSelector13() {
    QueryBuilder qb = new QueryBuilder(and(eq("year", 2015), exists("title", true)));
    Assertions.assertEquals("{\"selector\": {\"$and\": [{\"year\": {\"$eq\": 2015}}, " + "{\"title\": {\"$exists\": true}}]}}", 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