Search in sources :

Example 6 with Search

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

Example 7 with Search

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

Example 8 with Search

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);
        }
    }
}
Also used : Search(com.cloudant.client.api.Search) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 9 with Search

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

Example 10 with Search

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

Aggregations

Search (com.cloudant.client.api.Search)10 Test (org.junit.jupiter.api.Test)10 ArrayList (java.util.ArrayList)3 SearchResultRow (com.cloudant.client.api.model.SearchResult.SearchResultRow)2 List (java.util.List)2