Search in sources :

Example 1 with SearchResultRow

use of com.cloudant.client.api.model.SearchResult.SearchResultRow in project java-cloudant by cloudant.

the class SearchTests method multiValueDrillDownTest.

@Test
public void multiValueDrillDownTest() {
    // do a faceted search for multi-value drilldown
    Search srch = db.search("views101/animals");
    SearchResult<Animal> rslt = srch.includeDocs(true).drillDown("diet", "carnivore", "omnivore").querySearchResult("class:mammal", Animal.class);
    assertNotNull(rslt);
    assertEquals(4, rslt.getTotalRows());
    List<String> ids = new ArrayList<String>();
    for (SearchResultRow row : rslt.getRows()) {
        ids.add(row.getId());
    }
    List<String> expectedIds = Arrays.asList("panda", "aardvark", "badger", "lemur");
    assertTrue(ids.containsAll(expectedIds));
}
Also used : Search(com.cloudant.client.api.Search) ArrayList(java.util.ArrayList) SearchResultRow(com.cloudant.client.api.model.SearchResult.SearchResultRow) Test(org.junit.jupiter.api.Test)

Example 2 with SearchResultRow

use of com.cloudant.client.api.model.SearchResult.SearchResultRow 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)

Aggregations

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