IndexReader reader = null;
String field = null;
if (args.length == 1) {
reader = IndexReader.open(args[0]);
} else if (args.length == 2) {
reader = IndexReader.open(args[0]);
field = args[1];
} else {
usage();
System.exit(1);
}
TermInfoQueue tiq = new TermInfoQueue(numTerms);
TermEnum terms = reader.terms();
if (field != null) {
while (terms.next()) {
if (terms.term().field().equals(field)) {
tiq.insert(new TermInfo(terms.term(), terms.docFreq()));
}
}
}
else {
while (terms.next()) {
tiq.insert(new TermInfo(terms.term(), terms.docFreq()));
}
}
while (tiq.size() != 0) {
TermInfo termInfo = (TermInfo) tiq.pop();
System.out.println(termInfo.term + " " + termInfo.docFreq);
}
reader.close();