SolrSearchDao implements SearchDao { protected Map<String, Map<String, Long>> getFacetCounts(List<String> fields, QueryResponse solrResponse) { Map<String, Map<String, Long>> fieldCounts = new HashMap<>(); for (String field : fields) { Map<String, Long> valueCounts = new HashMap<>(); FacetField facetField = solrResponse.getFacetField(field); for (Count facetCount : facetField.getValues()) { valueCounts.put(facetCount.getName(), facetCount.getCount()); } fieldCounts.put(field, valueCounts); } return fieldCounts; } SolrSearchDao(SolrClient client, AccessConfig accessConfig); @Override SearchResponse search(SearchRequest searchRequest); SearchResponse search(SearchRequest searchRequest, String fieldList); @Override GroupResponse group(GroupRequest groupRequest);  }
@Test public void getFacetCountsShouldProperlyReturnFacetCounts() { QueryResponse queryResponse = mock(QueryResponse.class); FacetField facetField1 = new FacetField("field1"); facetField1.add("value1", 1); facetField1.add("value2", 2); FacetField facetField2 = new FacetField("field2"); facetField2.add("value3", 3); facetField2.add("value4", 4); when(queryResponse.getFacetField("field1")).thenReturn(facetField1); when(queryResponse.getFacetField("field2")).thenReturn(facetField2); Map<String, Map<String, Long>> expectedFacetCounts = new HashMap<String, Map<String, Long>>() {{ put("field1", new HashMap<String, Long>() {{ put("value1", 1L); put("value2", 2L); }}); put("field2", new HashMap<String, Long>() {{ put("value3", 3L); put("value4", 4L); }}); }}; assertEquals(expectedFacetCounts, solrSearchDao.getFacetCounts(Arrays.asList("field1", "field2"), queryResponse)); }