public static TermStats[] getHighFreqTerms(IndexReader reader, int numTerms, String field, Comparator<TermStats> comparator) throws Exception {TermStatsQueue tiq = null;if (field != null) {Terms terms = MultiTerms.getTerms(reader, field);if (terms == null) {throw new RuntimeException("field " + field + " not found");}TermsEnum termsEnum = terms.iterator();tiq = new TermStatsQueue(numTerms, comparator);tiq.fill(field, termsEnum);} else {Collection<String> fields = FieldInfos.getIndexedFields(reader);if (fields.size() == 0) {throw new RuntimeException("no fields found for this index");}tiq = new TermStatsQueue(numTerms, comparator);for (String fieldName : fields) {Terms terms = MultiTerms.getTerms(reader, fieldName);if (terms != null) {tiq.fill(fieldName, terms.iterator());}}}TermStats[] result = new TermStats[tiq.size()];int count = tiq.size() - 1;while (tiq.size() != 0) {result[count] = tiq.pop();count--;}return result;}