// Path: src/main/java/org/xbib/elasticsearch/skywalker/stats/FieldTermCount.java
// public class FieldTermCount implements Comparable<FieldTermCount> {
// 
//     private String fieldname;
// 
//     private long termCount;
// 
//     public FieldTermCount(String fieldname, long termCount) {
//         this.fieldname = fieldname;
//         this.termCount = termCount;
//     }
// 
//     public String getFieldname() {
//         return fieldname;
//     }
// 
//     public long getTermCount() {
//         return termCount;
//     }
// 
//     public int compareTo(FieldTermCount f2) {
//         if (termCount > f2.termCount) {
//             return -1;
//         } else if (termCount < f2.termCount) {
//             return 1;
//         } else {
//             return 0;
//         }
//     }
// }
// 
// Path: src/main/java/org/xbib/elasticsearch/skywalker/stats/TermStatsQueue.java
// public class TermStatsQueue extends PriorityQueue<TermStats> {
// 
//     public TermStatsQueue(int size) {
//         super(size);
//     }
// 
//     @Override
//     protected boolean lessThan(TermStats termInfoA, TermStats termInfoB) {
//         return termInfoA.docFreq() < termInfoB.docFreq();
//     }
// }


import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.*;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.similarity.SimilarityProvider;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.StoreFileMetaData;
import org.xbib.elasticsearch.skywalker.stats.FieldTermCount;
import org.xbib.elasticsearch.skywalker.stats.TermStats;
import org.xbib.elasticsearch.skywalker.stats.TermStatsQueue;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
                fld = fe.next();
                long termCount = 0L;
                Terms terms = fields.terms(fld);
                if (terms != null) {
                    te = terms.iterator(te);
                    while (te.next() != null) {
                        termCount++;
                        numTerms++;
                    }
                }
                termCounts.add(new FieldTermCount(fld, termCount));
            }
        }
        return termCounts;
    }

    public int getNumTerms() {
        return numTerms;
    }

    public TermStats[] getTopTerms(int num) {
        if (topTerms == null) {
            topTerms = getHighFreqTerms(num, null);
        }
        return topTerms;
    }

    private static final TermStats[] EMPTY_STATS = new TermStats[0];

    public TermStats[] getHighFreqTerms(int numTerms, String[] fieldNames) {
// Path: src/main/java/org/xbib/elasticsearch/skywalker/stats/FieldTermCount.java
// public class FieldTermCount implements Comparable<FieldTermCount> {
// 
//     private String fieldname;
// 
//     private long termCount;
// 
//     public FieldTermCount(String fieldname, long termCount) {
//         this.fieldname = fieldname;
//         this.termCount = termCount;
//     }
// 
//     public String getFieldname() {
//         return fieldname;
//     }
// 
//     public long getTermCount() {
//         return termCount;
//     }
// 
//     public int compareTo(FieldTermCount f2) {
//         if (termCount > f2.termCount) {
//             return -1;
//         } else if (termCount < f2.termCount) {
//             return 1;
//         } else {
//             return 0;
//         }
//     }
// }
// 
// Path: src/main/java/org/xbib/elasticsearch/skywalker/stats/TermStatsQueue.java
// public class TermStatsQueue extends PriorityQueue<TermStats> {
// 
//     public TermStatsQueue(int size) {
//         super(size);
//     }
// 
//     @Override
//     protected boolean lessThan(TermStats termInfoA, TermStats termInfoB) {
//         return termInfoA.docFreq() < termInfoB.docFreq();
//     }
// }


// Path: src/main/java/org/xbib/elasticsearch/skywalker/Skywalker.java
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.*;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.similarity.SimilarityProvider;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.StoreFileMetaData;
import org.xbib.elasticsearch.skywalker.stats.FieldTermCount;
import org.xbib.elasticsearch.skywalker.stats.TermStats;
import org.xbib.elasticsearch.skywalker.stats.TermStatsQueue;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

                fld = fe.next();
                long termCount = 0L;
                Terms terms = fields.terms(fld);
                if (terms != null) {
                    te = terms.iterator(te);
                    while (te.next() != null) {
                        termCount++;
                        numTerms++;
                    }
                }
                termCounts.add(new FieldTermCount(fld, termCount));
            }
        }
        return termCounts;
    }

    public int getNumTerms() {
        return numTerms;
    }

    public TermStats[] getTopTerms(int num) {
        if (topTerms == null) {
            topTerms = getHighFreqTerms(num, null);
        }
        return topTerms;
    }

    private static final TermStats[] EMPTY_STATS = new TermStats[0];

    public TermStats[] getHighFreqTerms(int numTerms, String[] fieldNames) {
        TermStatsQueue tiq = new TermStatsQueue(numTerms);