public static void ProcessTerms(List<Term> terms, int index, ref Dictionary<string, Dictionary<string, double>> output, bool isGeoHashLinked, string geoHash, ref Dictionary<string, string> fieldNames)
{
while (true)
{
// Check to see if this set of terms will contain geohash data
if (isGeoHashLinked)
{
if (terms.Count != 0)
{
try
{
// if containing geohash data create the dictionary relationship
if(!output.ContainsKey(terms[index].term))
output.Add(terms[index].term, new Dictionary<string, double>());
geoHash = terms[index].term;
}
catch (Exception error)
{
Jarvis.Logger.Error(error);
}
}
}
else
{
// Check to see if the dictionary already contains the key if not then create it.
if (!output[geoHash].ContainsKey(terms[index].term))
{
try
{
output[geoHash].Add(terms[index].term, terms[index].count);
if (!fieldNames.ContainsKey(terms[index].term))
{
var formattedValue = terms[index].term;
formattedValue = CheckName(formattedValue);
// Make sure the field hasn't already been processed.
if (!fieldNames.ContainsKey(terms[index].term))
{
fieldNames.Add(terms[index].term, formattedValue);
}
}
}
catch (Exception error)
{
Jarvis.Logger.Error(error);
}
}
else
{
try
{
// If the dictionary already contains the key then add to the current count.
output[geoHash][terms[index].term] += terms[index].count;
}
catch (Exception error)
{
Jarvis.Logger.Error(error);
}
}
}
if (terms.Count == 0)
{
return;
}
if (terms[index].aggregations != null)
{
// There are still more nested aggregations to search through so get to it.
ProcessAggregations(terms[index].aggregations, 0, ref output, geoHash, false, ref fieldNames);
}
if (index + 1 <= terms.Count - 1)
{
// Move on to the next term to process.
index = index + 1;
continue;
}
break;
}
}