range facet: from is used in to_str, should be to
This commit is contained in:
parent
a6d84f5942
commit
c0a7dc327c
|
@ -33,7 +33,7 @@ import org.elasticsearch.search.facets.filter.InternalFilterFacet;
|
||||||
import org.elasticsearch.search.facets.geodistance.InternalGeoDistanceFacet;
|
import org.elasticsearch.search.facets.geodistance.InternalGeoDistanceFacet;
|
||||||
import org.elasticsearch.search.facets.histogram.InternalHistogramFacet;
|
import org.elasticsearch.search.facets.histogram.InternalHistogramFacet;
|
||||||
import org.elasticsearch.search.facets.query.InternalQueryFacet;
|
import org.elasticsearch.search.facets.query.InternalQueryFacet;
|
||||||
import org.elasticsearch.search.facets.range.InternalRangeDistanceFacet;
|
import org.elasticsearch.search.facets.range.InternalRangeFacet;
|
||||||
import org.elasticsearch.search.facets.statistical.InternalStatisticalFacet;
|
import org.elasticsearch.search.facets.statistical.InternalStatisticalFacet;
|
||||||
import org.elasticsearch.search.facets.terms.InternalTermsFacet;
|
import org.elasticsearch.search.facets.terms.InternalTermsFacet;
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ public class InternalFacets implements Facets, Streamable, ToXContent, Iterable<
|
||||||
} else if (id == Facet.Type.GEO_DISTANCE.id()) {
|
} else if (id == Facet.Type.GEO_DISTANCE.id()) {
|
||||||
facets.add(InternalGeoDistanceFacet.readGeoDistanceFacet(in));
|
facets.add(InternalGeoDistanceFacet.readGeoDistanceFacet(in));
|
||||||
} else if (id == Facet.Type.RANGE.id()) {
|
} else if (id == Facet.Type.RANGE.id()) {
|
||||||
facets.add(InternalRangeDistanceFacet.readRangeFacet(in));
|
facets.add(InternalRangeFacet.readRangeFacet(in));
|
||||||
} else if (id == Facet.Type.FILTER.id()) {
|
} else if (id == Facet.Type.FILTER.id()) {
|
||||||
facets.add(InternalFilterFacet.readFilterFacet(in));
|
facets.add(InternalFilterFacet.readFilterFacet(in));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -33,7 +33,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* @author kimchy (shay.banon)
|
* @author kimchy (shay.banon)
|
||||||
*/
|
*/
|
||||||
public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
|
public class InternalRangeFacet implements RangeFacet, InternalFacet {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -43,10 +43,10 @@ public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
|
||||||
|
|
||||||
private Entry[] entries;
|
private Entry[] entries;
|
||||||
|
|
||||||
InternalRangeDistanceFacet() {
|
InternalRangeFacet() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public InternalRangeDistanceFacet(String name, String keyFieldName, String valueFieldName, Entry[] entries) {
|
public InternalRangeFacet(String name, String keyFieldName, String valueFieldName, Entry[] entries) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.keyFieldName = keyFieldName;
|
this.keyFieldName = keyFieldName;
|
||||||
this.valueFieldName = valueFieldName;
|
this.valueFieldName = valueFieldName;
|
||||||
|
@ -98,12 +98,12 @@ public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Facet aggregate(Iterable<Facet> facets) {
|
@Override public Facet aggregate(Iterable<Facet> facets) {
|
||||||
InternalRangeDistanceFacet agg = null;
|
InternalRangeFacet agg = null;
|
||||||
for (Facet facet : facets) {
|
for (Facet facet : facets) {
|
||||||
if (!facet.name().equals(name)) {
|
if (!facet.name().equals(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
InternalRangeDistanceFacet geoDistanceFacet = (InternalRangeDistanceFacet) facet;
|
InternalRangeFacet geoDistanceFacet = (InternalRangeFacet) facet;
|
||||||
if (agg == null) {
|
if (agg == null) {
|
||||||
agg = geoDistanceFacet;
|
agg = geoDistanceFacet;
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,8 +116,8 @@ public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
|
||||||
return agg;
|
return agg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InternalRangeDistanceFacet readRangeFacet(StreamInput in) throws IOException {
|
public static InternalRangeFacet readRangeFacet(StreamInput in) throws IOException {
|
||||||
InternalRangeDistanceFacet facet = new InternalRangeDistanceFacet();
|
InternalRangeFacet facet = new InternalRangeFacet();
|
||||||
facet.readFrom(in);
|
facet.readFrom(in);
|
||||||
return facet;
|
return facet;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
|
||||||
builder.field("to", entry.to);
|
builder.field("to", entry.to);
|
||||||
}
|
}
|
||||||
if (entry.toAsString != null) {
|
if (entry.toAsString != null) {
|
||||||
builder.field("to_str", entry.fromAsString);
|
builder.field("to_str", entry.toAsString);
|
||||||
}
|
}
|
||||||
builder.field("count", entry.count());
|
builder.field("count", entry.count());
|
||||||
builder.field("total", entry.total());
|
builder.field("total", entry.total());
|
|
@ -139,6 +139,6 @@ public class KeyValueRangeFacetCollector extends AbstractFacetCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Facet facet() {
|
@Override public Facet facet() {
|
||||||
return new InternalRangeDistanceFacet(facetName, keyFieldName, valueFieldName, entries);
|
return new InternalRangeFacet(facetName, keyFieldName, valueFieldName, entries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class RangeFacetCollector extends AbstractFacetCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Facet facet() {
|
@Override public Facet facet() {
|
||||||
return new InternalRangeDistanceFacet(facetName, fieldName, fieldName, entries);
|
return new InternalRangeFacet(facetName, fieldName, fieldName, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RangeProc implements NumericFieldData.DoubleValueInDocProc {
|
public static class RangeProc implements NumericFieldData.DoubleValueInDocProc {
|
||||||
|
|
|
@ -68,6 +68,6 @@ public class ScriptRangeFacetCollector extends AbstractFacetCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Facet facet() {
|
@Override public Facet facet() {
|
||||||
return new InternalRangeDistanceFacet(facetName, "_na", "_na", entries);
|
return new InternalRangeFacet(facetName, "_na", "_na", entries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -598,10 +598,13 @@ public class SimpleFacetsTests extends AbstractNodesTests {
|
||||||
assertThat(facet.name(), equalTo("range1"));
|
assertThat(facet.name(), equalTo("range1"));
|
||||||
assertThat(facet.entries().size(), equalTo(3));
|
assertThat(facet.entries().size(), equalTo(3));
|
||||||
assertThat(facet.entries().get(0).to(), closeTo(1056, 0.000001));
|
assertThat(facet.entries().get(0).to(), closeTo(1056, 0.000001));
|
||||||
|
assertThat(Double.parseDouble(facet.entries().get(0).toAsString()), closeTo(1056, 0.000001));
|
||||||
assertThat(facet.entries().get(0).count(), equalTo(1l));
|
assertThat(facet.entries().get(0).count(), equalTo(1l));
|
||||||
assertThat(facet.entries().get(0).total(), closeTo(1055, 0.000001));
|
assertThat(facet.entries().get(0).total(), closeTo(1055, 0.000001));
|
||||||
assertThat(facet.entries().get(1).from(), closeTo(1000, 0.000001));
|
assertThat(facet.entries().get(1).from(), closeTo(1000, 0.000001));
|
||||||
|
assertThat(Double.parseDouble(facet.entries().get(1).fromAsString()), closeTo(1000, 0.000001));
|
||||||
assertThat(facet.entries().get(1).to(), closeTo(1170, 0.000001));
|
assertThat(facet.entries().get(1).to(), closeTo(1170, 0.000001));
|
||||||
|
assertThat(Double.parseDouble(facet.entries().get(1).toAsString()), closeTo(1170, 0.000001));
|
||||||
assertThat(facet.entries().get(1).count(), equalTo(2l));
|
assertThat(facet.entries().get(1).count(), equalTo(2l));
|
||||||
assertThat(facet.entries().get(1).total(), closeTo(1055 + 1065, 0.000001));
|
assertThat(facet.entries().get(1).total(), closeTo(1055 + 1065, 0.000001));
|
||||||
assertThat(facet.entries().get(2).from(), closeTo(1170, 0.000001));
|
assertThat(facet.entries().get(2).from(), closeTo(1170, 0.000001));
|
||||||
|
|
Loading…
Reference in New Issue