// 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.*;
                if (!stateFile.getName().startsWith("global-")) {
                    continue;
                }
                files.add(stateFile);
                try {
                    long version = Long.parseLong(stateFile.getName().substring("global-".length()));
                    if (version > highestVersion) {
                        byte[] data = Streams.copyToByteArray(new FileInputStream(stateFile));
                        if (data.length == 0) {
                            continue;
                        }
                        XContentParser parser = null;
                        try {
                            parser = XContentHelper.createParser(data, 0, data.length);
                            metaData = MetaData.Builder.fromXContent(parser);
                            highestVersion = version;
                        } finally {
                            if (parser != null) {
                                parser.close();
                            }
                        }
                    }
                } catch (Exception e) {
                    continue;
                }
            }
        }
        return metaData;
    }

// 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.*;

                if (!stateFile.getName().startsWith("global-")) {
                    continue;
                }
                files.add(stateFile);
                try {
                    long version = Long.parseLong(stateFile.getName().substring("global-".length()));
                    if (version > highestVersion) {
                        byte[] data = Streams.copyToByteArray(new FileInputStream(stateFile));
                        if (data.length == 0) {
                            continue;
                        }
                        XContentParser parser = null;
                        try {
                            parser = XContentHelper.createParser(data, 0, data.length);
                            metaData = MetaData.Builder.fromXContent(parser);
                            highestVersion = version;
                        } finally {
                            if (parser != null) {
                                parser.close();
                            }
                        }
                    }
                } catch (Exception e) {
                    continue;
                }
            }
        }
        return metaData;
    }

    public Set<FieldTermCount> getFieldTermCounts() throws IOException {