// parse each document in the index
String[] fieldValues;
Collator stringCollator = Collator.getInstance();
stringCollator.setStrength(Collator.PRIMARY);
SortedSet<String> sortedValues = new TreeSet<String>(stringCollator);
ObjectKeyIntOpenHashMap duplicateValues = new ObjectKeyIntOpenHashMap();
for (int j = 0; j < hits.scoreDocs.length; j++) {
DocumentStoredFieldVisitor selector = new DocumentStoredFieldVisitor(fields);
reader.document(hits.scoreDocs[j].doc, selector);
Document doc = selector.getDocument();
// Skip templates and subTemplates
String[] isTemplate = doc.getValues("_isTemplate");
if (isTemplate[0] != null && !isTemplate[0].equals("n"))
continue;
// Get doc values for specified property
fieldValues = doc.getValues(property);
if (fieldValues == null)
continue;
addtoSortedSet(sortedValues, fieldValues, duplicateValues);
}
SummaryComparator valuesComparator = new SummaryComparator(SortOption.FREQUENCY, Type.STRING, context.getLanguage(), null);
TreeSet<SummaryComparator.SummaryElement> sortedValuesFrequency = new TreeSet<SummaryComparator.SummaryElement>(valuesComparator);
ObjectKeyIntMapIterator entries = duplicateValues.entries();
while(entries.hasNext()) {
entries.next();
sortedValuesFrequency.add(new SummaryComparator.SummaryElement(entries));
}