Search in sources :

Example 1 with TermStatsQueue

use of org.xbib.elasticsearch.skywalker.stats.TermStatsQueue in project elasticsearch-skywalker by jprante.

the class Skywalker method getHighFreqTerms.

public TermStats[] getHighFreqTerms(int numTerms, String[] fieldNames) {
    TermStatsQueue tiq = new TermStatsQueue(numTerms);
    TermsEnum te = null;
    try {
        if (fieldNames != null) {
            Fields fields = MultiFields.getFields(reader);
            if (fields == null) {
                return EMPTY_STATS;
            }
            for (String field : fieldNames) {
                Terms terms = fields.terms(field);
                if (terms != null) {
                    te = terms.iterator(te);
                    fillQueue(te, tiq, field);
                }
            }
        } else {
            Fields fields = MultiFields.getFields(reader);
            if (fields == null) {
                return EMPTY_STATS;
            }
            for (String field : fields) {
                Terms terms = fields.terms(field);
                te = terms.iterator(te);
                fillQueue(te, tiq, field);
            }
        }
    } catch (IOException e) {
    // ignore
    }
    TermStats[] result = new TermStats[tiq.size()];
    // we want highest first so we read the queue and populate the array
    // starting at the end and work backwards
    int count = tiq.size() - 1;
    while (tiq.size() != 0) {
        result[count] = tiq.pop();
        count--;
    }
    return result;
}
Also used : TermStats(org.xbib.elasticsearch.skywalker.stats.TermStats) IOException(java.io.IOException) TermStatsQueue(org.xbib.elasticsearch.skywalker.stats.TermStatsQueue)

Aggregations

IOException (java.io.IOException)1 TermStats (org.xbib.elasticsearch.skywalker.stats.TermStats)1 TermStatsQueue (org.xbib.elasticsearch.skywalker.stats.TermStatsQueue)1