int counter = 0;
external: for (Count facetElement : facets.getValues())
{
counter++;
log.debug("" + counter + " of " + facets.getValueCount());
ResearcherPage researcher = null;
try
{
String facetValue = facetElement.getName();
Integer realPersistentIdentifier = ResearcherPageUtils
.getRealPersistentIdentifier(facetValue, ResearcherPage.class);
researcher = applicationService
.get(ResearcherPage.class, realPersistentIdentifier);
//researcher.getDynamicField().setAnagraficaLazy(applicationService.getAnagraficaByRP(realPersistentIdentifier));
solrQuery = new SolrQuery();
solrQuery.setQuery("type:" + getType() + " AND entity:" + ConstantNetwork.ENTITY_RP + " AND " + FACET_METRICS + ":\"" + facetValue + "\"");
solrQuery.addFacetField(FACET_SEARCH);
solrQuery.setFacetMinCount(1);
solrQuery.setFacetLimit(Integer.MAX_VALUE);
solrQuery.setRows(0);
rsp = getService().search(solrQuery);
FacetField relations = rsp.getFacetField(FACET_SEARCH);
int i = 0;
int nConnections = 0;
int maxStrength = 0;
int sumStrength = 0;
List<Long> quadraticVarianceArrays = new ArrayList<Long>();
nConnections = Integer.valueOf(relations
.getValueCount() - 1);
internal: for (Count relation : relations.getValues())
{
log.debug("" + counter + " works on " + i + " of "
+ relations.getValueCount());
if (i == 0)
{
i++;
continue internal;
}
else
{
if (i == 1)
{
// max
maxStrength = Integer.valueOf((int) relation
.getCount());
}
sumStrength += Integer.valueOf((int) relation
.getCount());
quadraticVarianceArrays.add(relation
.getCount());
}
i++;
}
RPAdditionalFieldStorage anagraficaObject = researcher.getDynamicField();
setMetadata(String.valueOf(nConnections), anagraficaObject, ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_1
+ getType());
setMetadata(String.valueOf(maxStrength), anagraficaObject, ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_2
+ getType());
double averageStrength = ((double)sumStrength/((double)nConnections));
setMetadata(String.valueOf(df.format(averageStrength)), anagraficaObject, ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_3
+ getType());
double quadraticVariance = 0;
double n = quadraticVarianceArrays.size();
for(Long variance : quadraticVarianceArrays) {
quadraticVariance += ((variance - averageStrength) * (variance - averageStrength));
}
quadraticVariance = Math.sqrt(quadraticVariance/n);
setMetadata(String.valueOf(df.format(quadraticVariance)), anagraficaObject, ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_4
+ getType());
result.add(researcher);
}
catch (Exception e)
{
log.error("Error try to build object to index with ID:" + researcher.getId());
log.error(e.getMessage(), e);
otherError = true;
continue;
}