SearchResultsDaoImpl extends SolrDaoImpl implements SearchResultsDao { @Override public List<FacetField> getFacets(SolrQuery query) { final QueryResponse response = fireQuery(query); final List<FacetField> facetFields = response.getFacetFields(); if (logger.isDebugEnabled()) { if (facetFields.size() == 1) { final FacetField field = facetFields.get(0); logger.debug("Found facet field '{}' with {} values", field.getName(), field.getValueCount()); } else { logger.debug("Found {} facet fields", facetFields.size()); } } return facetFields; } SearchResultsDaoImpl(SolrClient solrClient, VloConfig config, FieldNameService fieldNameService); @Override List<FacetField> getFacets(SolrQuery query); @Override SolrDocumentList getDocuments(SolrQuery query); @Override QueryResponse getQueryResponse(SolrQuery query);  }
@Test public void testGetFacets() throws Exception { final SolrQuery query = new SolrQuery(); query.setRows(10); query.setStart(0); query.setFields(fieldNameService.getFieldName(FieldKey.NAME), fieldNameService.getFieldName(FieldKey.ID), fieldNameService.getFieldName(FieldKey.DESCRIPTION)); query.setQuery(null); query.setFacet(true); query.setFacetMinCount(1); query.addFacetField(fieldNameService.getFieldName(FieldKey.COLLECTION), fieldNameService.getFieldName(FieldKey.COUNTRY)); List<FacetField> facetFields = instance.getFacets(query); assertNotNull(facetFields); assertEquals(2, facetFields.size()); assertThat(facetFields, Matchers.<FacetField>hasItem(Matchers.allOf( Matchers.<FacetField>hasProperty("name", equalTo(fieldNameService.getFieldName(FieldKey.COLLECTION))), Matchers.<FacetField>hasProperty("valueCount", equalTo(2))))); assertThat(facetFields, Matchers.<FacetField>hasItem(Matchers.allOf( Matchers.<FacetField>hasProperty("name", equalTo(fieldNameService.getFieldName(FieldKey.COUNTRY))), Matchers.<FacetField>hasProperty("valueCount", equalTo(2))))); }