java: 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;}
C#: public static TermStats[] GetHighFreqTerms(IndexReader reader, int numTerms, string field, IComparer<TermStats> comparer){TermStatsQueue tiq = null;if (field != null){Fields fields = MultiFields.GetFields(reader);if (fields == null){throw new Exception("field " + field + " not found");}Terms terms = fields.GetTerms(field);if (terms != null){TermsEnum termsEnum = terms.GetIterator(null);tiq = new TermStatsQueue(numTerms, comparer);tiq.Fill(field, termsEnum);}}else{Fields fields = MultiFields.GetFields(reader);if (fields == null){throw new Exception("no fields found for this index");}tiq = new TermStatsQueue(numTerms, comparer);foreach (string fieldName in fields){Terms terms = fields.GetTerms(fieldName);if (terms != null){tiq.Fill(fieldName, terms.GetIterator(null));}}}TermStats[] result = new TermStats[tiq.Count];int count = tiq.Count - 1;while (tiq.Count != 0){result[count] = tiq.Pop();count--;}return result;}