public static void main(String[] args) throws Exception {String field = null;int numTerms = DEFAULT_NUMTERMS;if (args.length == 0 || args.length > 4) {usage();System.exit(1);}Directory dir = FSDirectory.open(Paths.get(args[0]));Comparator<TermStats> comparator = new DocFreqComparator();for (int i = 1; i < args.length; i++) {if (args[i].equals("-t")) {comparator = new TotalTermFreqComparator();}else{try {numTerms = Integer.parseInt(args[i]);} catch (NumberFormatException e) {field=args[i];}}}IndexReader reader = DirectoryReader.open(dir);TermStats[] terms = getHighFreqTerms(reader, numTerms, field, comparator);for (int i = 0; i < terms.length; i++) {System.out.printf(Locale.ROOT, "%s:%s \t totalTF = %,d \t docFreq = %,d \n",terms[i].field, terms[i].termtext.utf8ToString(), terms[i].totalTermFreq, terms[i].docFreq);}reader.close();}

public static void Main(string[] args){string field = null;int numTerms = DEFAULT_NUMTERMS;if (args.Length == 0 || args.Length > 4){throw new ArgumentException();}Store.Directory dir = FSDirectory.Open(new DirectoryInfo(args[0]));IComparer<TermStats> comparer = new DocFreqComparer();for (int i = 1; i < args.Length; i++){if (args[i].Equals("-t", StringComparison.Ordinal)){comparer = new TotalTermFreqComparer();}else{if (!int.TryParse(args[i], NumberStyles.Integer, CultureInfo.InvariantCulture, out numTerms))field = args[i];}}using (IndexReader reader = DirectoryReader.Open(dir)){TermStats[] terms = GetHighFreqTerms(reader, numTerms, field, comparer);for (int i = 0; i < terms.Length; i++){Console.WriteLine("{0}:{1} \t totalTF = {2:#,##0} \t doc freq = {3:#,##0} \n", terms[i].Field, terms[i].GetTermText(), terms[i].TotalTermFreq, terms[i].DocFreq);}}}
