}
public PieStatisticBean generateFacetFieldView(String key1, String key2,
String key3, Integer hitsNumber)
{
PieStatisticBean pieStatisticBean = new PieStatisticBean(key1, key2,
key3);
pieStatisticBean.setName(key2);
Collection<StatisticDatasBeanRow> fullData = new ArrayList<StatisticDatasBeanRow>();
Collection<StatisticDatasBeanRow> limitedData = new ArrayList<StatisticDatasBeanRow>();
try
{
NamedList result = (NamedList) ((SimpleOrderedMap) ((SimpleOrderedMap) solrResponse
.getResponse().get("facet_counts")).get("facet_fields"))
.get(key3);
int limit = result.size();
if (key3.equals(_CONTINENT) && hitsNumber != null && hitsNumber > 0)
{
limit = hitsNumber;
}
else if (key3.equals(_COUNTRY_CODE) && hitsNumber != null
&& hitsNumber > 0)
{
limit = hitsNumber;
}
if (key3.equals(_CITY) && hitsNumber != null && hitsNumber > 0)
{
limit = hitsNumber;
}
Integer other = 0;
for (int i = 0; i < result.size(); i++)
{
try
{
if (result.getVal(i).getClass().equals(Integer.class))
{
String name = (String) result.getName(i);
if (StringUtils.isEmpty(name))
name = "Unknown";
// if (i<limit && (Integer)result.getVal(i)>0){
if (i < limit && !name.equals("Unknown"))
{
limitedData.add(new StatisticDatasBeanRow(name,
result.getVal(i)));
}
else
{
other += (Integer) result.getVal(i);
}
fullData.add(new StatisticDatasBeanRow(name, result
.getVal(i)));
}
}
catch (Exception e)
{
fullData.add(new StatisticDatasBeanRow(_NotAvailable, null));
limitedData.add(new StatisticDatasBeanRow(_NotAvailable,
null));
e.printStackTrace();
}
}
if (result.size() > limit && other > 0)
{
limitedData.add(new StatisticDatasBeanRow(_OTHER, other));
}
pieStatisticBean.setHits(result.size());
pieStatisticBean.setDataTable(fullData);
pieStatisticBean.setLimitedDataTable(limitedData);
try
{
pieStatisticBean.setPercentages();
}
catch (Exception e)
{
e.printStackTrace();
}