use of com.cloudant.client.api.Search in project java-cloudant by cloudant.
the class SearchTests method rangesTest.
@Test
public void rangesTest() {
// do a faceted search for ranges
Search srch = db.search("views101/animals");
SearchResult<Animal> rslt = srch.includeDocs(true).counts(new String[] { "class", "diet" }).ranges("{ \"min_length\": {\"small\": \"[0 TO 1.0]\"," + "\"medium\": \"[1.1 TO 3.0]\", \"large\": \"[3.1 TO 9999999]\"} }").querySearchResult("class:mammal", Animal.class);
assertNotNull(rslt);
assertNotNull(rslt.getRanges());
assertEquals(1, rslt.getRanges().entrySet().size());
assertEquals(3, rslt.getRanges().get("min_length").entrySet().size());
assertEquals(new Long(3), rslt.getRanges().get("min_length").get("small"));
assertEquals(new Long(3), rslt.getRanges().get("min_length").get("medium"));
assertEquals(new Long(2), rslt.getRanges().get("min_length").get("large"));
}
use of com.cloudant.client.api.Search in project java-cloudant by cloudant.
the class SearchTests method searchCountsTest.
@Test
public void searchCountsTest() {
// do a faceted search for counts
Search srch = db.search("views101/animals");
SearchResult<Animal> rslt = srch.limit(10).includeDocs(true).counts(new String[] { "class", "diet" }).querySearchResult("l*", Animal.class);
assertNotNull(rslt);
assertNotNull(rslt.getCounts());
assertEquals(2, rslt.getCounts().keySet().size());
assertEquals(1, rslt.getCounts().get("class").keySet().size());
assertEquals(new Long(2), rslt.getCounts().get("class").get("mammal"));
assertEquals(2, rslt.getCounts().get("diet").keySet().size());
assertEquals(new Long(1), rslt.getCounts().get("diet").get("herbivore"));
assertEquals(new Long(1), rslt.getCounts().get("diet").get("omnivore"));
assertNotNull(rslt.getBookmark());
assertEquals(0, rslt.getGroups().size());
assertEquals(2, rslt.getRows().size());
for (@SuppressWarnings("rawtypes") SearchResultRow r : rslt.getRows()) {
assertNotNull(r.getDoc());
assertNotNull(r.getFields());
assertNotNull(r.getId());
assertNotNull(r.getOrder());
}
}
use of com.cloudant.client.api.Search in project java-cloudant by cloudant.
the class SearchTests method groupsTest.
@Test
public void groupsTest() {
Search srch = db.search("views101/animals");
Map<String, List<Animal>> groups = srch.limit(10).includeDocs(true).counts(new String[] { "class", "diet" }).groupField("class", false).queryGroups("l*", Animal.class);
assertNotNull(groups);
assertEquals(1, groups.size());
for (Entry<String, List<Animal>> g : groups.entrySet()) {
assertNotNull(g.getKey());
assertEquals(2, g.getValue().size());
for (Animal a : g.getValue()) {
assertNotNull(a);
}
}
}
use of com.cloudant.client.api.Search in project java-cloudant by cloudant.
the class SearchTests method rowsTest.
@Test
public void rowsTest() {
Search srch = db.search("views101/animals");
List<Animal> animals = srch.limit(10).includeDocs(true).counts(new String[] { "class", "diet" }).query("l*", Animal.class);
assertNotNull(animals);
assertEquals(2, animals.size());
for (Animal a : animals) {
assertNotNull(a);
}
}
use of com.cloudant.client.api.Search in project java-cloudant by cloudant.
the class SearchTests method sortTest.
@Test
public void sortTest() {
// do a faceted search for counts
Search srch = db.search("views101/animals");
SearchResult<Animal> rslt = srch.includeDocs(true).sort("[\"diet<string>\"]").querySearchResult("class:mammal", Animal.class);
assertNotNull(rslt);
assertEquals("carnivore", rslt.getRows().get(0).getOrder()[0].toString());
assertEquals("herbivore", rslt.getRows().get(1).getOrder()[0].toString());
assertEquals("omnivore", rslt.getRows().get(5).getOrder()[0].toString());
}
Aggregations