mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-24 13:55:57 +00:00
Add 'other_terms' option for terms facet, closes #1029.
This commit is contained in:
parent
e498dc3ba8
commit
f6beebf34c
@ -154,6 +154,26 @@ public interface TermsFacet extends Facet, Iterable<TermsFacet.Entry> {
|
||||
*/
|
||||
long getMissingCount();
|
||||
|
||||
/**
|
||||
* The total count of terms.
|
||||
*/
|
||||
long totalCount();
|
||||
|
||||
/**
|
||||
* The total count of terms.
|
||||
*/
|
||||
long getTotalCount();
|
||||
|
||||
/**
|
||||
* The count of terms other than the one provided by the entries.
|
||||
*/
|
||||
long otherCount();
|
||||
|
||||
/**
|
||||
* The count of terms other than the one provided by the entries.
|
||||
*/
|
||||
long getOtherCount();
|
||||
|
||||
/**
|
||||
* The terms and counts.
|
||||
*/
|
||||
|
@ -111,6 +111,7 @@ public class InternalByteTermsFacet extends InternalTermsFacet {
|
||||
int requiredSize;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
Collection<ByteEntry> entries = ImmutableList.of();
|
||||
|
||||
@ -119,12 +120,13 @@ public class InternalByteTermsFacet extends InternalTermsFacet {
|
||||
InternalByteTermsFacet() {
|
||||
}
|
||||
|
||||
public InternalByteTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<ByteEntry> entries, long missing) {
|
||||
public InternalByteTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<ByteEntry> entries, long missing, long total) {
|
||||
this.name = name;
|
||||
this.comparatorType = comparatorType;
|
||||
this.requiredSize = requiredSize;
|
||||
this.entries = entries;
|
||||
this.missing = missing;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
@ -151,6 +153,27 @@ public class InternalByteTermsFacet extends InternalTermsFacet {
|
||||
return missingCount();
|
||||
}
|
||||
|
||||
@Override public long totalCount() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
@Override public long getTotalCount() {
|
||||
return totalCount();
|
||||
}
|
||||
|
||||
@Override public long otherCount() {
|
||||
long other = total;
|
||||
for (Entry entry : entries) {
|
||||
other -= entry.count();
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override public long getOtherCount() {
|
||||
return otherCount();
|
||||
}
|
||||
|
||||
|
||||
@Override public List<ByteEntry> entries() {
|
||||
if (!(entries instanceof List)) {
|
||||
entries = ImmutableList.copyOf(entries);
|
||||
@ -175,21 +198,24 @@ public class InternalByteTermsFacet extends InternalTermsFacet {
|
||||
TByteIntHashMap aggregated = CacheRecycler.popByteIntMap();
|
||||
|
||||
long missing = 0;
|
||||
long total = 0;
|
||||
for (Facet facet : facets) {
|
||||
InternalByteTermsFacet mFacet = (InternalByteTermsFacet) facet;
|
||||
missing += mFacet.missingCount();
|
||||
total += mFacet.totalCount();
|
||||
for (ByteEntry entry : mFacet.entries) {
|
||||
aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
|
||||
}
|
||||
}
|
||||
|
||||
BoundedTreeSet<ByteEntry> ordered = new BoundedTreeSet<ByteEntry>(first.comparatorType.comparator(), first.requiredSize);
|
||||
for (TByteIntIterator it = aggregated.iterator(); it.hasNext();) {
|
||||
for (TByteIntIterator it = aggregated.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new ByteEntry(it.key(), it.value()));
|
||||
}
|
||||
first.entries = ordered;
|
||||
first.missing = missing;
|
||||
first.total = total;
|
||||
|
||||
CacheRecycler.pushByteIntMap(aggregated);
|
||||
|
||||
@ -199,6 +225,8 @@ public class InternalByteTermsFacet extends InternalTermsFacet {
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString MISSING = new XContentBuilderString("missing");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString OTHER = new XContentBuilderString("other");
|
||||
static final XContentBuilderString TERMS = new XContentBuilderString("terms");
|
||||
static final XContentBuilderString TERM = new XContentBuilderString("term");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
@ -208,6 +236,8 @@ public class InternalByteTermsFacet extends InternalTermsFacet {
|
||||
builder.startObject(name);
|
||||
builder.field(Fields._TYPE, TermsFacet.TYPE);
|
||||
builder.field(Fields.MISSING, missing);
|
||||
builder.field(Fields.TOTAL, total);
|
||||
builder.field(Fields.OTHER, otherCount());
|
||||
builder.startArray(Fields.TERMS);
|
||||
for (ByteEntry entry : entries) {
|
||||
builder.startObject();
|
||||
@ -231,6 +261,7 @@ public class InternalByteTermsFacet extends InternalTermsFacet {
|
||||
comparatorType = ComparatorType.fromId(in.readByte());
|
||||
requiredSize = in.readVInt();
|
||||
missing = in.readVLong();
|
||||
total = in.readVLong();
|
||||
|
||||
int size = in.readVInt();
|
||||
entries = new ArrayList<ByteEntry>(size);
|
||||
@ -245,6 +276,7 @@ public class InternalByteTermsFacet extends InternalTermsFacet {
|
||||
|
||||
out.writeVInt(requiredSize);
|
||||
out.writeVLong(missing);
|
||||
out.writeVLong(total);
|
||||
|
||||
out.writeVInt(entries.size());
|
||||
for (ByteEntry entry : entries) {
|
||||
|
@ -139,11 +139,11 @@ public class TermsByteFacetCollector extends AbstractFacetCollector {
|
||||
TByteIntHashMap facets = aggregator.facets();
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushByteIntMap(facets);
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalByteTermsFacet.ByteEntry>of(), aggregator.missing());
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalByteTermsFacet.ByteEntry>of(), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TByteIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TByteIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalByteTermsFacet.ByteEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -152,15 +152,15 @@ public class TermsByteFacetCollector extends AbstractFacetCollector {
|
||||
list[i] = (InternalByteTermsFacet.ByteEntry) ordered.pop();
|
||||
}
|
||||
CacheRecycler.pushByteIntMap(facets);
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing());
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
BoundedTreeSet<InternalByteTermsFacet.ByteEntry> ordered = new BoundedTreeSet<InternalByteTermsFacet.ByteEntry>(comparatorType.comparator(), size);
|
||||
for (TByteIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TByteIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalByteTermsFacet.ByteEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushByteIntMap(facets);
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing());
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,6 +212,7 @@ public class TermsByteFacetCollector extends AbstractFacetCollector {
|
||||
private final TByteIntHashMap facets;
|
||||
|
||||
private int missing;
|
||||
private int total;
|
||||
|
||||
public StaticAggregatorValueProc(TByteIntHashMap facets) {
|
||||
this.facets = facets;
|
||||
@ -223,6 +224,7 @@ public class TermsByteFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onValue(int docId, byte value) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docID) {
|
||||
@ -236,5 +238,9 @@ public class TermsByteFacetCollector extends AbstractFacetCollector {
|
||||
public final int missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public final int total() {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class TermsByteOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
private ReaderAggregator current;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
private final TByteHashSet excluded;
|
||||
|
||||
@ -118,6 +119,7 @@ public class TermsByteOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override protected void doSetNextReader(IndexReader reader, int docBase) throws IOException {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
}
|
||||
@ -133,6 +135,7 @@ public class TermsByteOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override public Facet facet() {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
// if we have values for this one, add it
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
@ -183,7 +186,7 @@ public class TermsByteOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing);
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
|
||||
}
|
||||
|
||||
BoundedTreeSet<InternalByteTermsFacet.ByteEntry> ordered = new BoundedTreeSet<InternalByteTermsFacet.ByteEntry>(comparatorType.comparator(), size);
|
||||
@ -215,7 +218,7 @@ public class TermsByteOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, ordered, missing);
|
||||
return new InternalByteTermsFacet(facetName, comparatorType, size, ordered, missing, total);
|
||||
}
|
||||
|
||||
public static class ReaderAggregator implements FieldData.OrdinalInDocProc {
|
||||
@ -225,6 +228,7 @@ public class TermsByteOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
int position = 0;
|
||||
byte current;
|
||||
int total;
|
||||
|
||||
public ReaderAggregator(ByteFieldData fieldData) {
|
||||
this.values = fieldData.values();
|
||||
@ -233,6 +237,7 @@ public class TermsByteOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onOrdinal(int docId, int ordinal) {
|
||||
counts[ordinal]++;
|
||||
total++;
|
||||
}
|
||||
|
||||
public boolean nextPosition() {
|
||||
|
@ -114,6 +114,7 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
||||
int requiredSize;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
Collection<DoubleEntry> entries = ImmutableList.of();
|
||||
|
||||
@ -122,12 +123,13 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
||||
InternalDoubleTermsFacet() {
|
||||
}
|
||||
|
||||
public InternalDoubleTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<DoubleEntry> entries, long missing) {
|
||||
public InternalDoubleTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<DoubleEntry> entries, long missing, long total) {
|
||||
this.name = name;
|
||||
this.comparatorType = comparatorType;
|
||||
this.requiredSize = requiredSize;
|
||||
this.entries = entries;
|
||||
this.missing = missing;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
@ -169,6 +171,26 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
||||
return missingCount();
|
||||
}
|
||||
|
||||
@Override public long totalCount() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
@Override public long getTotalCount() {
|
||||
return totalCount();
|
||||
}
|
||||
|
||||
@Override public long otherCount() {
|
||||
long other = total;
|
||||
for (Entry entry : entries) {
|
||||
other -= entry.count();
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override public long getOtherCount() {
|
||||
return otherCount();
|
||||
}
|
||||
|
||||
@Override public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
@ -176,21 +198,24 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
||||
InternalDoubleTermsFacet first = (InternalDoubleTermsFacet) facets.get(0);
|
||||
TDoubleIntHashMap aggregated = CacheRecycler.popDoubleIntMap();
|
||||
long missing = 0;
|
||||
long total = 0;
|
||||
for (Facet facet : facets) {
|
||||
InternalDoubleTermsFacet mFacet = (InternalDoubleTermsFacet) facet;
|
||||
missing += mFacet.missingCount();
|
||||
total += mFacet.totalCount();
|
||||
for (DoubleEntry entry : mFacet.entries) {
|
||||
aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
|
||||
}
|
||||
}
|
||||
|
||||
BoundedTreeSet<DoubleEntry> ordered = new BoundedTreeSet<DoubleEntry>(first.comparatorType.comparator(), first.requiredSize);
|
||||
for (TDoubleIntIterator it = aggregated.iterator(); it.hasNext();) {
|
||||
for (TDoubleIntIterator it = aggregated.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new DoubleEntry(it.key(), it.value()));
|
||||
}
|
||||
first.entries = ordered;
|
||||
first.missing = missing;
|
||||
first.total = total;
|
||||
|
||||
CacheRecycler.pushDoubleIntMap(aggregated);
|
||||
|
||||
@ -200,6 +225,8 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString MISSING = new XContentBuilderString("missing");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString OTHER = new XContentBuilderString("other");
|
||||
static final XContentBuilderString TERMS = new XContentBuilderString("terms");
|
||||
static final XContentBuilderString TERM = new XContentBuilderString("term");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
@ -209,6 +236,8 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
||||
builder.startObject(name);
|
||||
builder.field(Fields._TYPE, TermsFacet.TYPE);
|
||||
builder.field(Fields.MISSING, missing);
|
||||
builder.field(Fields.TOTAL, total);
|
||||
builder.field(Fields.OTHER, otherCount());
|
||||
builder.startArray(Fields.TERMS);
|
||||
for (DoubleEntry entry : entries) {
|
||||
builder.startObject();
|
||||
@ -232,6 +261,7 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
||||
comparatorType = ComparatorType.fromId(in.readByte());
|
||||
requiredSize = in.readVInt();
|
||||
missing = in.readVLong();
|
||||
total = in.readVLong();
|
||||
|
||||
int size = in.readVInt();
|
||||
entries = new ArrayList<DoubleEntry>(size);
|
||||
@ -245,6 +275,7 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
||||
out.writeByte(comparatorType.id());
|
||||
out.writeVInt(requiredSize);
|
||||
out.writeVLong(missing);
|
||||
out.writeVLong(total);
|
||||
|
||||
out.writeVInt(entries.size());
|
||||
for (DoubleEntry entry : entries) {
|
||||
|
@ -139,11 +139,11 @@ public class TermsDoubleFacetCollector extends AbstractFacetCollector {
|
||||
TDoubleIntHashMap facets = aggregator.facets();
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushDoubleIntMap(facets);
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalDoubleTermsFacet.DoubleEntry>of(), aggregator.missing());
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalDoubleTermsFacet.DoubleEntry>of(), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TDoubleIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TDoubleIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalDoubleTermsFacet.DoubleEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -152,15 +152,15 @@ public class TermsDoubleFacetCollector extends AbstractFacetCollector {
|
||||
list[i] = (InternalDoubleTermsFacet.DoubleEntry) ordered.pop();
|
||||
}
|
||||
CacheRecycler.pushDoubleIntMap(facets);
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing());
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
BoundedTreeSet<InternalDoubleTermsFacet.DoubleEntry> ordered = new BoundedTreeSet<InternalDoubleTermsFacet.DoubleEntry>(comparatorType.comparator(), size);
|
||||
for (TDoubleIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TDoubleIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalDoubleTermsFacet.DoubleEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushDoubleIntMap(facets);
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing());
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,6 +212,7 @@ public class TermsDoubleFacetCollector extends AbstractFacetCollector {
|
||||
private final TDoubleIntHashMap facets;
|
||||
|
||||
private int missing;
|
||||
private int total;
|
||||
|
||||
public StaticAggregatorValueProc(TDoubleIntHashMap facets) {
|
||||
this.facets = facets;
|
||||
@ -223,6 +224,7 @@ public class TermsDoubleFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onValue(int docId, double value) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
@ -236,5 +238,9 @@ public class TermsDoubleFacetCollector extends AbstractFacetCollector {
|
||||
public final int missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public int total() {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class TermsDoubleOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
private ReaderAggregator current;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
private final TDoubleHashSet excluded;
|
||||
|
||||
@ -118,6 +119,7 @@ public class TermsDoubleOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override protected void doSetNextReader(IndexReader reader, int docBase) throws IOException {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
}
|
||||
@ -133,6 +135,7 @@ public class TermsDoubleOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override public Facet facet() {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
// if we have values for this one, add it
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
@ -183,7 +186,7 @@ public class TermsDoubleOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing);
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
|
||||
}
|
||||
|
||||
BoundedTreeSet<InternalDoubleTermsFacet.DoubleEntry> ordered = new BoundedTreeSet<InternalDoubleTermsFacet.DoubleEntry>(comparatorType.comparator(), size);
|
||||
@ -215,7 +218,7 @@ public class TermsDoubleOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, ordered, missing);
|
||||
return new InternalDoubleTermsFacet(facetName, comparatorType, size, ordered, missing, total);
|
||||
}
|
||||
|
||||
public static class ReaderAggregator implements FieldData.OrdinalInDocProc {
|
||||
@ -225,6 +228,7 @@ public class TermsDoubleOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
int position = 0;
|
||||
double current;
|
||||
int total;
|
||||
|
||||
public ReaderAggregator(DoubleFieldData fieldData) {
|
||||
this.values = fieldData.values();
|
||||
@ -233,6 +237,7 @@ public class TermsDoubleOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onOrdinal(int docId, int ordinal) {
|
||||
counts[ordinal]++;
|
||||
total++;
|
||||
}
|
||||
|
||||
public boolean nextPosition() {
|
||||
|
@ -114,6 +114,7 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||
int requiredSize;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
Collection<FloatEntry> entries = ImmutableList.of();
|
||||
|
||||
@ -122,12 +123,13 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||
InternalFloatTermsFacet() {
|
||||
}
|
||||
|
||||
public InternalFloatTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<FloatEntry> entries, long missing) {
|
||||
public InternalFloatTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<FloatEntry> entries, long missing, long total) {
|
||||
this.name = name;
|
||||
this.comparatorType = comparatorType;
|
||||
this.requiredSize = requiredSize;
|
||||
this.entries = entries;
|
||||
this.missing = missing;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
@ -169,6 +171,26 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||
return missingCount();
|
||||
}
|
||||
|
||||
@Override public long totalCount() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
@Override public long getTotalCount() {
|
||||
return totalCount();
|
||||
}
|
||||
|
||||
@Override public long otherCount() {
|
||||
long other = total;
|
||||
for (Entry entry : entries) {
|
||||
other -= entry.count();
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override public long getOtherCount() {
|
||||
return otherCount();
|
||||
}
|
||||
|
||||
@Override public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
@ -176,22 +198,24 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||
InternalFloatTermsFacet first = (InternalFloatTermsFacet) facets.get(0);
|
||||
TFloatIntHashMap aggregated = CacheRecycler.popFloatIntMap();
|
||||
long missing = 0;
|
||||
|
||||
long total = 0;
|
||||
for (Facet facet : facets) {
|
||||
InternalFloatTermsFacet mFacet = (InternalFloatTermsFacet) facet;
|
||||
missing += mFacet.missingCount();
|
||||
total += mFacet.totalCount();
|
||||
for (FloatEntry entry : mFacet.entries) {
|
||||
aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
|
||||
}
|
||||
}
|
||||
|
||||
BoundedTreeSet<FloatEntry> ordered = new BoundedTreeSet<FloatEntry>(first.comparatorType.comparator(), first.requiredSize);
|
||||
for (TFloatIntIterator it = aggregated.iterator(); it.hasNext();) {
|
||||
for (TFloatIntIterator it = aggregated.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new FloatEntry(it.key(), it.value()));
|
||||
}
|
||||
first.entries = ordered;
|
||||
first.missing = missing;
|
||||
first.total = total;
|
||||
|
||||
CacheRecycler.pushFloatIntMap(aggregated);
|
||||
|
||||
@ -201,6 +225,8 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString MISSING = new XContentBuilderString("missing");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString OTHER = new XContentBuilderString("other");
|
||||
static final XContentBuilderString TERMS = new XContentBuilderString("terms");
|
||||
static final XContentBuilderString TERM = new XContentBuilderString("term");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
@ -210,6 +236,8 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||
builder.startObject(name);
|
||||
builder.field(Fields._TYPE, TermsFacet.TYPE);
|
||||
builder.field(Fields.MISSING, missing);
|
||||
builder.field(Fields.TOTAL, total);
|
||||
builder.field(Fields.OTHER, otherCount());
|
||||
builder.startArray(Fields.TERMS);
|
||||
for (FloatEntry entry : entries) {
|
||||
builder.startObject();
|
||||
@ -233,6 +261,7 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||
comparatorType = ComparatorType.fromId(in.readByte());
|
||||
requiredSize = in.readVInt();
|
||||
missing = in.readVLong();
|
||||
total = in.readVLong();
|
||||
|
||||
int size = in.readVInt();
|
||||
entries = new ArrayList<FloatEntry>(size);
|
||||
@ -246,6 +275,7 @@ public class InternalFloatTermsFacet extends InternalTermsFacet {
|
||||
out.writeByte(comparatorType.id());
|
||||
out.writeVInt(requiredSize);
|
||||
out.writeVLong(missing);
|
||||
out.writeVLong(total);
|
||||
|
||||
out.writeVInt(entries.size());
|
||||
for (FloatEntry entry : entries) {
|
||||
|
@ -139,11 +139,11 @@ public class TermsFloatFacetCollector extends AbstractFacetCollector {
|
||||
TFloatIntHashMap facets = aggregator.facets();
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushFloatIntMap(facets);
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalFloatTermsFacet.FloatEntry>of(), aggregator.missing());
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalFloatTermsFacet.FloatEntry>of(), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TFloatIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TFloatIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalFloatTermsFacet.FloatEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -152,15 +152,15 @@ public class TermsFloatFacetCollector extends AbstractFacetCollector {
|
||||
list[i] = (InternalFloatTermsFacet.FloatEntry) ordered.pop();
|
||||
}
|
||||
CacheRecycler.pushFloatIntMap(facets);
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing());
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
BoundedTreeSet<InternalFloatTermsFacet.FloatEntry> ordered = new BoundedTreeSet<InternalFloatTermsFacet.FloatEntry>(comparatorType.comparator(), size);
|
||||
for (TFloatIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TFloatIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalFloatTermsFacet.FloatEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushFloatIntMap(facets);
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing());
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,6 +212,7 @@ public class TermsFloatFacetCollector extends AbstractFacetCollector {
|
||||
private final TFloatIntHashMap facets;
|
||||
|
||||
private int missing;
|
||||
private int total;
|
||||
|
||||
public StaticAggregatorValueProc(TFloatIntHashMap facets) {
|
||||
this.facets = facets;
|
||||
@ -223,6 +224,7 @@ public class TermsFloatFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onValue(int docId, float value) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
@ -236,5 +238,9 @@ public class TermsFloatFacetCollector extends AbstractFacetCollector {
|
||||
public final int missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public final int total() {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class TermsFloatOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
private ReaderAggregator current;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
private final TFloatHashSet excluded;
|
||||
|
||||
@ -118,6 +119,7 @@ public class TermsFloatOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override protected void doSetNextReader(IndexReader reader, int docBase) throws IOException {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
}
|
||||
@ -133,6 +135,7 @@ public class TermsFloatOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override public Facet facet() {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
// if we have values for this one, add it
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
@ -183,7 +186,7 @@ public class TermsFloatOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing);
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
|
||||
}
|
||||
|
||||
BoundedTreeSet<InternalFloatTermsFacet.FloatEntry> ordered = new BoundedTreeSet<InternalFloatTermsFacet.FloatEntry>(comparatorType.comparator(), size);
|
||||
@ -215,7 +218,7 @@ public class TermsFloatOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, ordered, missing);
|
||||
return new InternalFloatTermsFacet(facetName, comparatorType, size, ordered, missing, total);
|
||||
}
|
||||
|
||||
public static class ReaderAggregator implements FieldData.OrdinalInDocProc {
|
||||
@ -225,6 +228,7 @@ public class TermsFloatOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
int position = 0;
|
||||
float current;
|
||||
int total;
|
||||
|
||||
public ReaderAggregator(FloatFieldData fieldData) {
|
||||
this.values = fieldData.values();
|
||||
@ -233,6 +237,7 @@ public class TermsFloatOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onOrdinal(int docId, int ordinal) {
|
||||
counts[ordinal]++;
|
||||
total++;
|
||||
}
|
||||
|
||||
public boolean nextPosition() {
|
||||
|
@ -56,6 +56,6 @@ public class IndexNameFacetCollector extends AbstractFacetCollector {
|
||||
}
|
||||
|
||||
@Override public Facet facet() {
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Sets.newHashSet(new InternalStringTermsFacet.StringEntry(indexName, count)), 0);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Sets.newHashSet(new InternalStringTermsFacet.StringEntry(indexName, count)), 0, count);
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||
int requiredSize;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
Collection<IntEntry> entries = ImmutableList.of();
|
||||
|
||||
@ -119,12 +120,13 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||
InternalIntTermsFacet() {
|
||||
}
|
||||
|
||||
public InternalIntTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<IntEntry> entries, long missing) {
|
||||
public InternalIntTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<IntEntry> entries, long missing, long total) {
|
||||
this.name = name;
|
||||
this.comparatorType = comparatorType;
|
||||
this.requiredSize = requiredSize;
|
||||
this.entries = entries;
|
||||
this.missing = missing;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
@ -166,6 +168,26 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||
return missingCount();
|
||||
}
|
||||
|
||||
@Override public long totalCount() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
@Override public long getTotalCount() {
|
||||
return totalCount();
|
||||
}
|
||||
|
||||
@Override public long otherCount() {
|
||||
long other = total;
|
||||
for (Entry entry : entries) {
|
||||
other -= entry.count();
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override public long getOtherCount() {
|
||||
return otherCount();
|
||||
}
|
||||
|
||||
@Override public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
@ -173,22 +195,24 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||
InternalIntTermsFacet first = (InternalIntTermsFacet) facets.get(0);
|
||||
TIntIntHashMap aggregated = CacheRecycler.popIntIntMap();
|
||||
long missing = 0;
|
||||
|
||||
long total = 0;
|
||||
for (Facet facet : facets) {
|
||||
InternalIntTermsFacet mFacet = (InternalIntTermsFacet) facet;
|
||||
missing += mFacet.missingCount();
|
||||
total += mFacet.totalCount();
|
||||
for (IntEntry entry : mFacet.entries) {
|
||||
aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
|
||||
}
|
||||
}
|
||||
|
||||
BoundedTreeSet<IntEntry> ordered = new BoundedTreeSet<IntEntry>(first.comparatorType.comparator(), first.requiredSize);
|
||||
for (TIntIntIterator it = aggregated.iterator(); it.hasNext();) {
|
||||
for (TIntIntIterator it = aggregated.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new IntEntry(it.key(), it.value()));
|
||||
}
|
||||
first.entries = ordered;
|
||||
first.missing = missing;
|
||||
first.total = total;
|
||||
|
||||
CacheRecycler.pushIntIntMap(aggregated);
|
||||
|
||||
@ -198,6 +222,8 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString MISSING = new XContentBuilderString("missing");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString OTHER = new XContentBuilderString("other");
|
||||
static final XContentBuilderString TERMS = new XContentBuilderString("terms");
|
||||
static final XContentBuilderString TERM = new XContentBuilderString("term");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
@ -207,6 +233,8 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||
builder.startObject(name);
|
||||
builder.field(Fields._TYPE, TermsFacet.TYPE);
|
||||
builder.field(Fields.MISSING, missing);
|
||||
builder.field(Fields.TOTAL, total);
|
||||
builder.field(Fields.OTHER, otherCount());
|
||||
builder.startArray(Fields.TERMS);
|
||||
for (IntEntry entry : entries) {
|
||||
builder.startObject();
|
||||
@ -230,6 +258,7 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||
comparatorType = ComparatorType.fromId(in.readByte());
|
||||
requiredSize = in.readVInt();
|
||||
missing = in.readVLong();
|
||||
total = in.readVLong();
|
||||
|
||||
int size = in.readVInt();
|
||||
entries = new ArrayList<IntEntry>(size);
|
||||
@ -243,6 +272,7 @@ public class InternalIntTermsFacet extends InternalTermsFacet {
|
||||
out.writeByte(comparatorType.id());
|
||||
out.writeVInt(requiredSize);
|
||||
out.writeVLong(missing);
|
||||
out.writeVLong(total);
|
||||
|
||||
out.writeVInt(entries.size());
|
||||
for (IntEntry entry : entries) {
|
||||
|
@ -139,11 +139,11 @@ public class TermsIntFacetCollector extends AbstractFacetCollector {
|
||||
TIntIntHashMap facets = aggregator.facets();
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushIntIntMap(facets);
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalIntTermsFacet.IntEntry>of(), aggregator.missing());
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalIntTermsFacet.IntEntry>of(), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TIntIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TIntIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalIntTermsFacet.IntEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -152,15 +152,15 @@ public class TermsIntFacetCollector extends AbstractFacetCollector {
|
||||
list[i] = (InternalIntTermsFacet.IntEntry) ordered.pop();
|
||||
}
|
||||
CacheRecycler.pushIntIntMap(facets);
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing());
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
BoundedTreeSet<InternalIntTermsFacet.IntEntry> ordered = new BoundedTreeSet<InternalIntTermsFacet.IntEntry>(comparatorType.comparator(), size);
|
||||
for (TIntIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TIntIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalIntTermsFacet.IntEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushIntIntMap(facets);
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing());
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,6 +212,7 @@ public class TermsIntFacetCollector extends AbstractFacetCollector {
|
||||
private final TIntIntHashMap facets;
|
||||
|
||||
private int missing;
|
||||
private int total;
|
||||
|
||||
public StaticAggregatorValueProc(TIntIntHashMap facets) {
|
||||
this.facets = facets;
|
||||
@ -223,6 +224,7 @@ public class TermsIntFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onValue(int docId, int value) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
@ -236,5 +238,9 @@ public class TermsIntFacetCollector extends AbstractFacetCollector {
|
||||
public final int missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public final int total() {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class TermsIntOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
private ReaderAggregator current;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
private final TIntHashSet excluded;
|
||||
|
||||
@ -118,6 +119,7 @@ public class TermsIntOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override protected void doSetNextReader(IndexReader reader, int docBase) throws IOException {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
}
|
||||
@ -133,6 +135,7 @@ public class TermsIntOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override public Facet facet() {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
// if we have values for this one, add it
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
@ -183,7 +186,7 @@ public class TermsIntOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing);
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
|
||||
}
|
||||
|
||||
BoundedTreeSet<InternalIntTermsFacet.IntEntry> ordered = new BoundedTreeSet<InternalIntTermsFacet.IntEntry>(comparatorType.comparator(), size);
|
||||
@ -215,7 +218,7 @@ public class TermsIntOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, ordered, missing);
|
||||
return new InternalIntTermsFacet(facetName, comparatorType, size, ordered, missing, total);
|
||||
}
|
||||
|
||||
public static class ReaderAggregator implements FieldData.OrdinalInDocProc {
|
||||
@ -225,6 +228,7 @@ public class TermsIntOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
int position = 0;
|
||||
int current;
|
||||
int total = 0;
|
||||
|
||||
public ReaderAggregator(IntFieldData fieldData) {
|
||||
this.values = fieldData.values();
|
||||
@ -233,6 +237,7 @@ public class TermsIntOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onOrdinal(int docId, int ordinal) {
|
||||
counts[ordinal]++;
|
||||
total++;
|
||||
}
|
||||
|
||||
public boolean nextPosition() {
|
||||
|
@ -115,6 +115,7 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||
int requiredSize;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
Collection<LongEntry> entries = ImmutableList.of();
|
||||
|
||||
@ -123,12 +124,13 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||
InternalIpTermsFacet() {
|
||||
}
|
||||
|
||||
public InternalIpTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<LongEntry> entries, long missing) {
|
||||
public InternalIpTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<LongEntry> entries, long missing, long total) {
|
||||
this.name = name;
|
||||
this.comparatorType = comparatorType;
|
||||
this.requiredSize = requiredSize;
|
||||
this.entries = entries;
|
||||
this.missing = missing;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
@ -170,6 +172,27 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||
return missingCount();
|
||||
}
|
||||
|
||||
|
||||
@Override public long totalCount() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
@Override public long getTotalCount() {
|
||||
return totalCount();
|
||||
}
|
||||
|
||||
@Override public long otherCount() {
|
||||
long other = total;
|
||||
for (Entry entry : entries) {
|
||||
other -= entry.count();
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override public long getOtherCount() {
|
||||
return otherCount();
|
||||
}
|
||||
|
||||
@Override public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
@ -177,10 +200,11 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||
InternalIpTermsFacet first = (InternalIpTermsFacet) facets.get(0);
|
||||
TLongIntHashMap aggregated = CacheRecycler.popLongIntMap();
|
||||
long missing = 0;
|
||||
|
||||
long total = 0;
|
||||
for (Facet facet : facets) {
|
||||
InternalIpTermsFacet mFacet = (InternalIpTermsFacet) facet;
|
||||
missing += mFacet.missingCount();
|
||||
total += mFacet.totalCount();
|
||||
for (LongEntry entry : mFacet.entries) {
|
||||
aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
|
||||
}
|
||||
@ -193,6 +217,7 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||
}
|
||||
first.entries = ordered;
|
||||
first.missing = missing;
|
||||
first.total = total;
|
||||
|
||||
CacheRecycler.pushLongIntMap(aggregated);
|
||||
|
||||
@ -202,6 +227,8 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString MISSING = new XContentBuilderString("missing");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString OTHER = new XContentBuilderString("other");
|
||||
static final XContentBuilderString TERMS = new XContentBuilderString("terms");
|
||||
static final XContentBuilderString TERM = new XContentBuilderString("term");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
@ -211,6 +238,8 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||
builder.startObject(name);
|
||||
builder.field(Fields._TYPE, TermsFacet.TYPE);
|
||||
builder.field(Fields.MISSING, missing);
|
||||
builder.field(Fields.TOTAL, total);
|
||||
builder.field(Fields.OTHER, otherCount());
|
||||
builder.startArray(Fields.TERMS);
|
||||
for (LongEntry entry : entries) {
|
||||
builder.startObject();
|
||||
@ -234,6 +263,7 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||
comparatorType = ComparatorType.fromId(in.readByte());
|
||||
requiredSize = in.readVInt();
|
||||
missing = in.readVLong();
|
||||
total = in.readVLong();
|
||||
|
||||
int size = in.readVInt();
|
||||
entries = new ArrayList<LongEntry>(size);
|
||||
@ -247,6 +277,7 @@ public class InternalIpTermsFacet extends InternalTermsFacet {
|
||||
out.writeByte(comparatorType.id());
|
||||
out.writeVInt(requiredSize);
|
||||
out.writeVLong(missing);
|
||||
out.writeVLong(total);
|
||||
|
||||
out.writeVInt(entries.size());
|
||||
for (LongEntry entry : entries) {
|
||||
|
@ -136,11 +136,11 @@ public class TermsIpFacetCollector extends AbstractFacetCollector {
|
||||
TLongIntHashMap facets = aggregator.facets();
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushLongIntMap(facets);
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalIpTermsFacet.LongEntry>of(), aggregator.missing());
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalIpTermsFacet.LongEntry>of(), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TLongIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TLongIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalIpTermsFacet.LongEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -149,15 +149,15 @@ public class TermsIpFacetCollector extends AbstractFacetCollector {
|
||||
list[i] = (InternalIpTermsFacet.LongEntry) ordered.pop();
|
||||
}
|
||||
CacheRecycler.pushLongIntMap(facets);
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing());
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
BoundedTreeSet<InternalIpTermsFacet.LongEntry> ordered = new BoundedTreeSet<InternalIpTermsFacet.LongEntry>(comparatorType.comparator(), size);
|
||||
for (TLongIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TLongIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalIpTermsFacet.LongEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushLongIntMap(facets);
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing());
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -196,6 +196,7 @@ public class TermsIpFacetCollector extends AbstractFacetCollector {
|
||||
private final TLongIntHashMap facets;
|
||||
|
||||
private int missing;
|
||||
private int total;
|
||||
|
||||
public StaticAggregatorValueProc(TLongIntHashMap facets) {
|
||||
this.facets = facets;
|
||||
@ -207,6 +208,7 @@ public class TermsIpFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onValue(int docId, long value) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
@ -220,5 +222,9 @@ public class TermsIpFacetCollector extends AbstractFacetCollector {
|
||||
public final int missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public final int total() {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class TermsIpOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
private ReaderAggregator current;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
private final TLongHashSet excluded;
|
||||
|
||||
@ -118,6 +119,7 @@ public class TermsIpOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override protected void doSetNextReader(IndexReader reader, int docBase) throws IOException {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
}
|
||||
@ -133,6 +135,7 @@ public class TermsIpOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override public Facet facet() {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
// if we have values for this one, add it
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
@ -183,7 +186,7 @@ public class TermsIpOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing);
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
|
||||
}
|
||||
|
||||
BoundedTreeSet<InternalIpTermsFacet.LongEntry> ordered = new BoundedTreeSet<InternalIpTermsFacet.LongEntry>(comparatorType.comparator(), size);
|
||||
@ -215,7 +218,7 @@ public class TermsIpOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, ordered, missing);
|
||||
return new InternalIpTermsFacet(facetName, comparatorType, size, ordered, missing, total);
|
||||
}
|
||||
|
||||
public static class ReaderAggregator implements FieldData.OrdinalInDocProc {
|
||||
@ -225,6 +228,7 @@ public class TermsIpOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
int position = 0;
|
||||
long current = Integer.MIN_VALUE;
|
||||
int total;
|
||||
|
||||
public ReaderAggregator(LongFieldData fieldData) {
|
||||
this.values = fieldData.values();
|
||||
@ -233,6 +237,7 @@ public class TermsIpOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onOrdinal(int docId, int ordinal) {
|
||||
counts[ordinal]++;
|
||||
total++;
|
||||
}
|
||||
|
||||
public boolean nextPosition() {
|
||||
|
@ -114,6 +114,7 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||
int requiredSize;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
Collection<LongEntry> entries = ImmutableList.of();
|
||||
|
||||
@ -122,12 +123,13 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||
InternalLongTermsFacet() {
|
||||
}
|
||||
|
||||
public InternalLongTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<LongEntry> entries, long missing) {
|
||||
public InternalLongTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<LongEntry> entries, long missing, long total) {
|
||||
this.name = name;
|
||||
this.comparatorType = comparatorType;
|
||||
this.requiredSize = requiredSize;
|
||||
this.entries = entries;
|
||||
this.missing = missing;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
@ -169,6 +171,26 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||
return missingCount();
|
||||
}
|
||||
|
||||
@Override public long totalCount() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
@Override public long getTotalCount() {
|
||||
return totalCount();
|
||||
}
|
||||
|
||||
@Override public long otherCount() {
|
||||
long other = total;
|
||||
for (Entry entry : entries) {
|
||||
other -= entry.count();
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override public long getOtherCount() {
|
||||
return otherCount();
|
||||
}
|
||||
|
||||
@Override public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
@ -176,22 +198,24 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||
InternalLongTermsFacet first = (InternalLongTermsFacet) facets.get(0);
|
||||
TLongIntHashMap aggregated = CacheRecycler.popLongIntMap();
|
||||
long missing = 0;
|
||||
|
||||
long total = 0;
|
||||
for (Facet facet : facets) {
|
||||
InternalLongTermsFacet mFacet = (InternalLongTermsFacet) facet;
|
||||
missing += mFacet.missingCount();
|
||||
total += mFacet.totalCount();
|
||||
for (LongEntry entry : mFacet.entries) {
|
||||
aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
|
||||
}
|
||||
}
|
||||
|
||||
BoundedTreeSet<LongEntry> ordered = new BoundedTreeSet<LongEntry>(first.comparatorType.comparator(), first.requiredSize);
|
||||
for (TLongIntIterator it = aggregated.iterator(); it.hasNext();) {
|
||||
for (TLongIntIterator it = aggregated.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new LongEntry(it.key(), it.value()));
|
||||
}
|
||||
first.entries = ordered;
|
||||
first.missing = missing;
|
||||
first.total = total;
|
||||
|
||||
CacheRecycler.pushLongIntMap(aggregated);
|
||||
|
||||
@ -201,6 +225,8 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString MISSING = new XContentBuilderString("missing");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString OTHER = new XContentBuilderString("other");
|
||||
static final XContentBuilderString TERMS = new XContentBuilderString("terms");
|
||||
static final XContentBuilderString TERM = new XContentBuilderString("term");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
@ -210,6 +236,8 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||
builder.startObject(name);
|
||||
builder.field(Fields._TYPE, TermsFacet.TYPE);
|
||||
builder.field(Fields.MISSING, missing);
|
||||
builder.field(Fields.TOTAL, total);
|
||||
builder.field(Fields.OTHER, otherCount());
|
||||
builder.startArray(Fields.TERMS);
|
||||
for (LongEntry entry : entries) {
|
||||
builder.startObject();
|
||||
@ -233,6 +261,7 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||
comparatorType = ComparatorType.fromId(in.readByte());
|
||||
requiredSize = in.readVInt();
|
||||
missing = in.readVLong();
|
||||
total = in.readVLong();
|
||||
|
||||
int size = in.readVInt();
|
||||
entries = new ArrayList<LongEntry>(size);
|
||||
@ -246,6 +275,7 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
||||
out.writeByte(comparatorType.id());
|
||||
out.writeVInt(requiredSize);
|
||||
out.writeVLong(missing);
|
||||
out.writeVLong(total);
|
||||
|
||||
out.writeVInt(entries.size());
|
||||
for (LongEntry entry : entries) {
|
||||
|
@ -43,7 +43,11 @@ import org.elasticsearch.search.facet.terms.support.EntryPriorityQueue;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
@ -145,11 +149,11 @@ public class TermsLongFacetCollector extends AbstractFacetCollector {
|
||||
TLongIntHashMap facets = aggregator.facets();
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushLongIntMap(facets);
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalLongTermsFacet.LongEntry>of(), aggregator.missing());
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalLongTermsFacet.LongEntry>of(), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TLongIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TLongIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalLongTermsFacet.LongEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -158,15 +162,15 @@ public class TermsLongFacetCollector extends AbstractFacetCollector {
|
||||
list[i] = (InternalLongTermsFacet.LongEntry) ordered.pop();
|
||||
}
|
||||
CacheRecycler.pushLongIntMap(facets);
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing());
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
BoundedTreeSet<InternalLongTermsFacet.LongEntry> ordered = new BoundedTreeSet<InternalLongTermsFacet.LongEntry>(comparatorType.comparator(), size);
|
||||
for (TLongIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TLongIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalLongTermsFacet.LongEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushLongIntMap(facets);
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing());
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,6 +222,7 @@ public class TermsLongFacetCollector extends AbstractFacetCollector {
|
||||
private final TLongIntHashMap facets;
|
||||
|
||||
private int missing;
|
||||
private int total;
|
||||
|
||||
public StaticAggregatorValueProc(TLongIntHashMap facets) {
|
||||
this.facets = facets;
|
||||
@ -229,6 +234,7 @@ public class TermsLongFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onValue(int docId, long value) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
@ -242,5 +248,9 @@ public class TermsLongFacetCollector extends AbstractFacetCollector {
|
||||
public final int missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public final int total() {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class TermsLongOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
private ReaderAggregator current;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
private final TLongHashSet excluded;
|
||||
|
||||
@ -118,6 +119,7 @@ public class TermsLongOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override protected void doSetNextReader(IndexReader reader, int docBase) throws IOException {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
}
|
||||
@ -133,6 +135,7 @@ public class TermsLongOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override public Facet facet() {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
// if we have values for this one, add it
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
@ -183,7 +186,7 @@ public class TermsLongOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing);
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
|
||||
}
|
||||
|
||||
BoundedTreeSet<InternalLongTermsFacet.LongEntry> ordered = new BoundedTreeSet<InternalLongTermsFacet.LongEntry>(comparatorType.comparator(), size);
|
||||
@ -215,7 +218,7 @@ public class TermsLongOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, ordered, missing);
|
||||
return new InternalLongTermsFacet(facetName, comparatorType, size, ordered, missing, total);
|
||||
}
|
||||
|
||||
public static class ReaderAggregator implements FieldData.OrdinalInDocProc {
|
||||
@ -225,6 +228,7 @@ public class TermsLongOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
int position = 0;
|
||||
long current = Integer.MIN_VALUE;
|
||||
int total;
|
||||
|
||||
public ReaderAggregator(LongFieldData fieldData) {
|
||||
this.values = fieldData.values();
|
||||
@ -233,6 +237,7 @@ public class TermsLongOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onOrdinal(int docId, int ordinal) {
|
||||
counts[ordinal]++;
|
||||
total++;
|
||||
}
|
||||
|
||||
public boolean nextPosition() {
|
||||
|
@ -111,6 +111,7 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||
int requiredSize;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
Collection<ShortEntry> entries = ImmutableList.of();
|
||||
|
||||
@ -119,12 +120,13 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||
InternalShortTermsFacet() {
|
||||
}
|
||||
|
||||
public InternalShortTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<ShortEntry> entries, long missing) {
|
||||
public InternalShortTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<ShortEntry> entries, long missing, long total) {
|
||||
this.name = name;
|
||||
this.comparatorType = comparatorType;
|
||||
this.requiredSize = requiredSize;
|
||||
this.entries = entries;
|
||||
this.missing = missing;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
@ -166,6 +168,26 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||
return missingCount();
|
||||
}
|
||||
|
||||
@Override public long totalCount() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
@Override public long getTotalCount() {
|
||||
return totalCount();
|
||||
}
|
||||
|
||||
@Override public long otherCount() {
|
||||
long other = total;
|
||||
for (Entry entry : entries) {
|
||||
other -= entry.count();
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override public long getOtherCount() {
|
||||
return otherCount();
|
||||
}
|
||||
|
||||
@Override public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
@ -173,21 +195,24 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||
InternalShortTermsFacet first = (InternalShortTermsFacet) facets.get(0);
|
||||
TShortIntHashMap aggregated = CacheRecycler.popShortIntMap();
|
||||
long missing = 0;
|
||||
long total = 0;
|
||||
for (Facet facet : facets) {
|
||||
InternalShortTermsFacet mFacet = (InternalShortTermsFacet) facet;
|
||||
missing += mFacet.missingCount();
|
||||
total += mFacet.totalCount();
|
||||
for (ShortEntry entry : mFacet.entries) {
|
||||
aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
|
||||
}
|
||||
}
|
||||
|
||||
BoundedTreeSet<ShortEntry> ordered = new BoundedTreeSet<ShortEntry>(first.comparatorType.comparator(), first.requiredSize);
|
||||
for (TShortIntIterator it = aggregated.iterator(); it.hasNext();) {
|
||||
for (TShortIntIterator it = aggregated.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new ShortEntry(it.key(), it.value()));
|
||||
}
|
||||
first.entries = ordered;
|
||||
first.missing = missing;
|
||||
first.total = total;
|
||||
|
||||
CacheRecycler.pushShortIntMap(aggregated);
|
||||
|
||||
@ -197,6 +222,8 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString MISSING = new XContentBuilderString("missing");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString OTHER = new XContentBuilderString("other");
|
||||
static final XContentBuilderString TERMS = new XContentBuilderString("terms");
|
||||
static final XContentBuilderString TERM = new XContentBuilderString("term");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
@ -206,6 +233,8 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||
builder.startObject(name);
|
||||
builder.field(Fields._TYPE, TermsFacet.TYPE);
|
||||
builder.field(Fields.MISSING, missing);
|
||||
builder.field(Fields.TOTAL, total);
|
||||
builder.field(Fields.OTHER, otherCount());
|
||||
builder.startArray(Fields.TERMS);
|
||||
for (ShortEntry entry : entries) {
|
||||
builder.startObject();
|
||||
@ -229,6 +258,7 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||
comparatorType = ComparatorType.fromId(in.readByte());
|
||||
requiredSize = in.readVInt();
|
||||
missing = in.readVLong();
|
||||
total = in.readVLong();
|
||||
|
||||
int size = in.readVInt();
|
||||
entries = new ArrayList<ShortEntry>(size);
|
||||
@ -242,6 +272,7 @@ public class InternalShortTermsFacet extends InternalTermsFacet {
|
||||
out.writeByte(comparatorType.id());
|
||||
out.writeVInt(requiredSize);
|
||||
out.writeVLong(missing);
|
||||
out.writeVLong(total);
|
||||
|
||||
out.writeVInt(entries.size());
|
||||
for (ShortEntry entry : entries) {
|
||||
|
@ -139,11 +139,11 @@ public class TermsShortFacetCollector extends AbstractFacetCollector {
|
||||
TShortIntHashMap facets = aggregator.facets();
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushShortIntMap(facets);
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalShortTermsFacet.ShortEntry>of(), aggregator.missing());
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalShortTermsFacet.ShortEntry>of(), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TShortIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TShortIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalShortTermsFacet.ShortEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -152,15 +152,15 @@ public class TermsShortFacetCollector extends AbstractFacetCollector {
|
||||
list[i] = (InternalShortTermsFacet.ShortEntry) ordered.pop();
|
||||
}
|
||||
CacheRecycler.pushShortIntMap(facets);
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing());
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
BoundedTreeSet<InternalShortTermsFacet.ShortEntry> ordered = new BoundedTreeSet<InternalShortTermsFacet.ShortEntry>(comparatorType.comparator(), size);
|
||||
for (TShortIntIterator it = facets.iterator(); it.hasNext();) {
|
||||
for (TShortIntIterator it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalShortTermsFacet.ShortEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushShortIntMap(facets);
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing());
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -213,6 +213,8 @@ public class TermsShortFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
private int missing;
|
||||
|
||||
private int total;
|
||||
|
||||
public StaticAggregatorValueProc(TShortIntHashMap facets) {
|
||||
this.facets = facets;
|
||||
}
|
||||
@ -223,6 +225,7 @@ public class TermsShortFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onValue(int docId, short value) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
@ -236,5 +239,9 @@ public class TermsShortFacetCollector extends AbstractFacetCollector {
|
||||
public final int missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public final int total() {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class TermsShortOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
private ReaderAggregator current;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
private final TShortHashSet excluded;
|
||||
|
||||
@ -118,6 +119,7 @@ public class TermsShortOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override protected void doSetNextReader(IndexReader reader, int docBase) throws IOException {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
}
|
||||
@ -133,6 +135,7 @@ public class TermsShortOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override public Facet facet() {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
// if we have values for this one, add it
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
@ -183,7 +186,7 @@ public class TermsShortOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing);
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
|
||||
}
|
||||
|
||||
BoundedTreeSet<InternalShortTermsFacet.ShortEntry> ordered = new BoundedTreeSet<InternalShortTermsFacet.ShortEntry>(comparatorType.comparator(), size);
|
||||
@ -215,7 +218,7 @@ public class TermsShortOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, ordered, missing);
|
||||
return new InternalShortTermsFacet(facetName, comparatorType, size, ordered, missing, total);
|
||||
}
|
||||
|
||||
public static class ReaderAggregator implements FieldData.OrdinalInDocProc {
|
||||
@ -225,6 +228,7 @@ public class TermsShortOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
int position = 0;
|
||||
short current;
|
||||
int total;
|
||||
|
||||
public ReaderAggregator(ShortFieldData fieldData) {
|
||||
this.values = fieldData.values();
|
||||
@ -233,6 +237,7 @@ public class TermsShortOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onOrdinal(int docId, int ordinal) {
|
||||
counts[ordinal]++;
|
||||
total++;
|
||||
}
|
||||
|
||||
public boolean nextPosition() {
|
||||
|
@ -142,11 +142,11 @@ public class FieldsTermsStringFacetCollector extends AbstractFacetCollector {
|
||||
TObjectIntHashMap<String> facets = aggregator.facets();
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushObjectIntMap(facets);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalStringTermsFacet.StringEntry>of(), aggregator.missing());
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalStringTermsFacet.StringEntry>of(), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext();) {
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalStringTermsFacet.StringEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -155,15 +155,15 @@ public class FieldsTermsStringFacetCollector extends AbstractFacetCollector {
|
||||
list[i] = ((InternalStringTermsFacet.StringEntry) ordered.pop());
|
||||
}
|
||||
CacheRecycler.pushObjectIntMap(facets);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing());
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
BoundedTreeSet<InternalStringTermsFacet.StringEntry> ordered = new BoundedTreeSet<InternalStringTermsFacet.StringEntry>(comparatorType.comparator(), size);
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext();) {
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalStringTermsFacet.StringEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushObjectIntMap(facets);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing());
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -214,6 +214,7 @@ public class FieldsTermsStringFacetCollector extends AbstractFacetCollector {
|
||||
private final TObjectIntHashMap<String> facets;
|
||||
|
||||
private int missing;
|
||||
private int total;
|
||||
|
||||
public StaticAggregatorValueProc(TObjectIntHashMap<String> facets) {
|
||||
this.facets = facets;
|
||||
@ -225,6 +226,7 @@ public class FieldsTermsStringFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onValue(int docId, String value) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
@ -238,5 +240,9 @@ public class FieldsTermsStringFacetCollector extends AbstractFacetCollector {
|
||||
public final int missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public final int total() {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,8 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||
|
||||
long missing;
|
||||
|
||||
long total;
|
||||
|
||||
Collection<StringEntry> entries = ImmutableList.of();
|
||||
|
||||
ComparatorType comparatorType;
|
||||
@ -118,12 +120,13 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||
InternalStringTermsFacet() {
|
||||
}
|
||||
|
||||
public InternalStringTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<StringEntry> entries, long missing) {
|
||||
public InternalStringTermsFacet(String name, ComparatorType comparatorType, int requiredSize, Collection<StringEntry> entries, long missing, long total) {
|
||||
this.name = name;
|
||||
this.comparatorType = comparatorType;
|
||||
this.requiredSize = requiredSize;
|
||||
this.entries = entries;
|
||||
this.missing = missing;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
@ -165,6 +168,26 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||
return missingCount();
|
||||
}
|
||||
|
||||
@Override public long totalCount() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
@Override public long getTotalCount() {
|
||||
return totalCount();
|
||||
}
|
||||
|
||||
@Override public long otherCount() {
|
||||
long other = total;
|
||||
for (Entry entry : entries) {
|
||||
other -= entry.count();
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override public long getOtherCount() {
|
||||
return otherCount();
|
||||
}
|
||||
|
||||
private static ThreadLocal<ThreadLocals.CleanableValue<TObjectIntHashMap<String>>> aggregateCache = new ThreadLocal<ThreadLocals.CleanableValue<TObjectIntHashMap<String>>>() {
|
||||
@Override protected ThreadLocals.CleanableValue<TObjectIntHashMap<String>> initialValue() {
|
||||
return new ThreadLocals.CleanableValue<TObjectIntHashMap<String>>(new TObjectIntHashMap<String>());
|
||||
@ -180,27 +203,32 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||
TObjectIntHashMap<String> aggregated = aggregateCache.get().get();
|
||||
aggregated.clear();
|
||||
long missing = 0;
|
||||
long total = 0;
|
||||
for (Facet facet : facets) {
|
||||
InternalStringTermsFacet mFacet = (InternalStringTermsFacet) facet;
|
||||
missing += mFacet.missingCount();
|
||||
total += mFacet.totalCount();
|
||||
for (InternalStringTermsFacet.StringEntry entry : mFacet.entries) {
|
||||
aggregated.adjustOrPutValue(entry.term(), entry.count(), entry.count());
|
||||
}
|
||||
}
|
||||
|
||||
BoundedTreeSet<StringEntry> ordered = new BoundedTreeSet<StringEntry>(first.comparatorType.comparator(), first.requiredSize);
|
||||
for (TObjectIntIterator<String> it = aggregated.iterator(); it.hasNext();) {
|
||||
for (TObjectIntIterator<String> it = aggregated.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new StringEntry(it.key(), it.value()));
|
||||
}
|
||||
first.entries = ordered;
|
||||
first.missing = missing;
|
||||
first.total = total;
|
||||
return first;
|
||||
}
|
||||
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString MISSING = new XContentBuilderString("missing");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString OTHER = new XContentBuilderString("other");
|
||||
static final XContentBuilderString TERMS = new XContentBuilderString("terms");
|
||||
static final XContentBuilderString TERM = new XContentBuilderString("term");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
@ -210,6 +238,8 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||
builder.startObject(name);
|
||||
builder.field(Fields._TYPE, TermsFacet.TYPE);
|
||||
builder.field(Fields.MISSING, missing);
|
||||
builder.field(Fields.TOTAL, total);
|
||||
builder.field(Fields.OTHER, otherCount());
|
||||
builder.startArray(Fields.TERMS);
|
||||
for (Entry entry : entries) {
|
||||
builder.startObject();
|
||||
@ -233,6 +263,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||
comparatorType = ComparatorType.fromId(in.readByte());
|
||||
requiredSize = in.readVInt();
|
||||
missing = in.readVLong();
|
||||
total = in.readVLong();
|
||||
|
||||
int size = in.readVInt();
|
||||
entries = new ArrayList<StringEntry>(size);
|
||||
@ -246,6 +277,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
||||
out.writeByte(comparatorType.id());
|
||||
out.writeVInt(requiredSize);
|
||||
out.writeVLong(missing);
|
||||
out.writeVLong(total);
|
||||
|
||||
out.writeVInt(entries.size());
|
||||
for (Entry entry : entries) {
|
||||
|
@ -59,6 +59,7 @@ public class ScriptTermsStringFieldFacetCollector extends AbstractFacetCollector
|
||||
private final TObjectIntHashMap<String> facets;
|
||||
|
||||
private int missing;
|
||||
private int total;
|
||||
|
||||
public ScriptTermsStringFieldFacetCollector(String facetName, int size, InternalStringTermsFacet.ComparatorType comparatorType, SearchContext context,
|
||||
ImmutableSet<String> excluded, Pattern pattern, String scriptLang, String script, Map<String, Object> params) {
|
||||
@ -96,6 +97,7 @@ public class ScriptTermsStringFieldFacetCollector extends AbstractFacetCollector
|
||||
if (match(value)) {
|
||||
found = true;
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
@ -108,6 +110,7 @@ public class ScriptTermsStringFieldFacetCollector extends AbstractFacetCollector
|
||||
if (match(value)) {
|
||||
found = true;
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
@ -117,6 +120,7 @@ public class ScriptTermsStringFieldFacetCollector extends AbstractFacetCollector
|
||||
String value = o.toString();
|
||||
if (match(value)) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
} else {
|
||||
missing++;
|
||||
}
|
||||
@ -136,11 +140,11 @@ public class ScriptTermsStringFieldFacetCollector extends AbstractFacetCollector
|
||||
@Override public Facet facet() {
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushObjectIntMap(facets);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalStringTermsFacet.StringEntry>of(), missing);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalStringTermsFacet.StringEntry>of(), missing, total);
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext();) {
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalStringTermsFacet.StringEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -149,15 +153,15 @@ public class ScriptTermsStringFieldFacetCollector extends AbstractFacetCollector
|
||||
list[i] = ((InternalStringTermsFacet.StringEntry) ordered.pop());
|
||||
}
|
||||
CacheRecycler.pushObjectIntMap(facets);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
|
||||
} else {
|
||||
BoundedTreeSet<InternalStringTermsFacet.StringEntry> ordered = new BoundedTreeSet<InternalStringTermsFacet.StringEntry>(comparatorType.comparator(), size);
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext();) {
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalStringTermsFacet.StringEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushObjectIntMap(facets);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, missing);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, missing, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,11 +145,11 @@ public class TermsStringFacetCollector extends AbstractFacetCollector {
|
||||
TObjectIntHashMap<String> facets = aggregator.facets();
|
||||
if (facets.isEmpty()) {
|
||||
CacheRecycler.pushObjectIntMap(facets);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalStringTermsFacet.StringEntry>of(), aggregator.missing());
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalStringTermsFacet.StringEntry>of(), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
if (size < EntryPriorityQueue.LIMIT) {
|
||||
EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext();) {
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.insertWithOverflow(new InternalStringTermsFacet.StringEntry(it.key(), it.value()));
|
||||
}
|
||||
@ -158,15 +158,15 @@ public class TermsStringFacetCollector extends AbstractFacetCollector {
|
||||
list[i] = ((InternalStringTermsFacet.StringEntry) ordered.pop());
|
||||
}
|
||||
CacheRecycler.pushObjectIntMap(facets);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing());
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
|
||||
} else {
|
||||
BoundedTreeSet<InternalStringTermsFacet.StringEntry> ordered = new BoundedTreeSet<InternalStringTermsFacet.StringEntry>(comparatorType.comparator(), size);
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext();) {
|
||||
for (TObjectIntIterator<String> it = facets.iterator(); it.hasNext(); ) {
|
||||
it.advance();
|
||||
ordered.add(new InternalStringTermsFacet.StringEntry(it.key(), it.value()));
|
||||
}
|
||||
CacheRecycler.pushObjectIntMap(facets);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing());
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -217,6 +217,7 @@ public class TermsStringFacetCollector extends AbstractFacetCollector {
|
||||
private final TObjectIntHashMap<String> facets;
|
||||
|
||||
private int missing = 0;
|
||||
private int total = 0;
|
||||
|
||||
public StaticAggregatorValueProc(TObjectIntHashMap<String> facets) {
|
||||
this.facets = facets;
|
||||
@ -228,6 +229,7 @@ public class TermsStringFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onValue(int docId, String value) {
|
||||
facets.adjustOrPutValue(value, 1, 1);
|
||||
total++;
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
@ -241,5 +243,9 @@ public class TermsStringFacetCollector extends AbstractFacetCollector {
|
||||
public final int missing() {
|
||||
return this.missing;
|
||||
}
|
||||
|
||||
public int total() {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
private ReaderAggregator current;
|
||||
|
||||
long missing;
|
||||
long total;
|
||||
|
||||
private final ImmutableSet<String> excluded;
|
||||
|
||||
@ -119,6 +120,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override protected void doSetNextReader(IndexReader reader, int docBase) throws IOException {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
}
|
||||
@ -134,6 +136,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
@Override public Facet facet() {
|
||||
if (current != null) {
|
||||
missing += current.counts[0];
|
||||
total += current.total - current.counts[0];
|
||||
// if we have values for this one, add it
|
||||
if (current.values.length > 1) {
|
||||
aggregators.add(current);
|
||||
@ -188,7 +191,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
|
||||
}
|
||||
|
||||
BoundedTreeSet<InternalStringTermsFacet.StringEntry> ordered = new BoundedTreeSet<InternalStringTermsFacet.StringEntry>(comparatorType.comparator(), size);
|
||||
@ -221,7 +224,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
CacheRecycler.pushIntArray(aggregator.counts);
|
||||
}
|
||||
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, missing);
|
||||
return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, missing, total);
|
||||
}
|
||||
|
||||
public static class ReaderAggregator implements FieldData.OrdinalInDocProc {
|
||||
@ -231,6 +234,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
int position = 0;
|
||||
String current;
|
||||
int total;
|
||||
|
||||
public ReaderAggregator(StringFieldData fieldData) {
|
||||
this.values = fieldData.values();
|
||||
@ -239,6 +243,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
|
||||
|
||||
@Override public void onOrdinal(int docId, int ordinal) {
|
||||
counts[ordinal]++;
|
||||
total++;
|
||||
}
|
||||
|
||||
public boolean nextPosition() {
|
||||
|
@ -448,6 +448,8 @@ public class SimpleFacetsTests extends AbstractNodesTests {
|
||||
|
||||
TermsFacet facet = searchResponse.facets().facet("facet1");
|
||||
assertThat(facet.name(), equalTo("facet1"));
|
||||
assertThat(facet.getTotalCount(), equalTo(2l));
|
||||
assertThat(facet.getOtherCount(), equalTo(0l));
|
||||
assertThat(facet.entries().size(), equalTo(1));
|
||||
assertThat(facet.entries().get(0).term(), equalTo("111"));
|
||||
assertThat(facet.entries().get(0).count(), equalTo(2));
|
||||
|
Loading…
x
Reference in New Issue
Block a user