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;
}
Aggregations