NamedList<Object> queryFacets = new SimpleOrderedMap<Object>();
// loop though all the facets populating the NamedLists we just created
Iterator<Facet> facetIter = response.facets().iterator();
while (facetIter.hasNext()) {
Facet facet = facetIter.next();
if (facet.type().equals(TermsFacet.TYPE)) {
// we have term facet, create NamedList to store terms
TermsFacet termFacet = (TermsFacet) facet;
NamedList<Object> termFacetObj = new SimpleOrderedMap<Object>();
for (TermsFacet.Entry tfEntry : termFacet.entries()) {
termFacetObj.add(tfEntry.term(), tfEntry.count());
}
termFacets.add(facet.getName(), termFacetObj);
} else if (facet.type().equals(QueryFacet.TYPE)) {
QueryFacet queryFacet = (QueryFacet) facet;
queryFacets.add(queryFacet.getName(), queryFacet.count());
}
}