range facet: from is used in to_str, should be to

This commit is contained in:
kimchy 2010-08-11 23:40:42 +03:00
parent a6d84f5942
commit c0a7dc327c
6 changed files with 16 additions and 13 deletions

View File

@ -33,7 +33,7 @@ import org.elasticsearch.search.facets.filter.InternalFilterFacet;
import org.elasticsearch.search.facets.geodistance.InternalGeoDistanceFacet;
import org.elasticsearch.search.facets.histogram.InternalHistogramFacet;
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.terms.InternalTermsFacet;
@ -148,7 +148,7 @@ public class InternalFacets implements Facets, Streamable, ToXContent, Iterable<
} else if (id == Facet.Type.GEO_DISTANCE.id()) {
facets.add(InternalGeoDistanceFacet.readGeoDistanceFacet(in));
} else if (id == Facet.Type.RANGE.id()) {
facets.add(InternalRangeDistanceFacet.readRangeFacet(in));
facets.add(InternalRangeFacet.readRangeFacet(in));
} else if (id == Facet.Type.FILTER.id()) {
facets.add(InternalFilterFacet.readFilterFacet(in));
} else {

View File

@ -33,7 +33,7 @@ import java.util.List;
/**
* @author kimchy (shay.banon)
*/
public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
public class InternalRangeFacet implements RangeFacet, InternalFacet {
private String name;
@ -43,10 +43,10 @@ public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
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.keyFieldName = keyFieldName;
this.valueFieldName = valueFieldName;
@ -98,12 +98,12 @@ public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
}
@Override public Facet aggregate(Iterable<Facet> facets) {
InternalRangeDistanceFacet agg = null;
InternalRangeFacet agg = null;
for (Facet facet : facets) {
if (!facet.name().equals(name)) {
continue;
}
InternalRangeDistanceFacet geoDistanceFacet = (InternalRangeDistanceFacet) facet;
InternalRangeFacet geoDistanceFacet = (InternalRangeFacet) facet;
if (agg == null) {
agg = geoDistanceFacet;
} else {
@ -116,8 +116,8 @@ public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
return agg;
}
public static InternalRangeDistanceFacet readRangeFacet(StreamInput in) throws IOException {
InternalRangeDistanceFacet facet = new InternalRangeDistanceFacet();
public static InternalRangeFacet readRangeFacet(StreamInput in) throws IOException {
InternalRangeFacet facet = new InternalRangeFacet();
facet.readFrom(in);
return facet;
}
@ -186,7 +186,7 @@ public class InternalRangeDistanceFacet implements RangeFacet, InternalFacet {
builder.field("to", entry.to);
}
if (entry.toAsString != null) {
builder.field("to_str", entry.fromAsString);
builder.field("to_str", entry.toAsString);
}
builder.field("count", entry.count());
builder.field("total", entry.total());

View File

@ -139,6 +139,6 @@ public class KeyValueRangeFacetCollector extends AbstractFacetCollector {
}
@Override public Facet facet() {
return new InternalRangeDistanceFacet(facetName, keyFieldName, valueFieldName, entries);
return new InternalRangeFacet(facetName, keyFieldName, valueFieldName, entries);
}
}

View File

@ -81,7 +81,7 @@ public class RangeFacetCollector extends AbstractFacetCollector {
}
@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 {

View File

@ -68,6 +68,6 @@ public class ScriptRangeFacetCollector extends AbstractFacetCollector {
}
@Override public Facet facet() {
return new InternalRangeDistanceFacet(facetName, "_na", "_na", entries);
return new InternalRangeFacet(facetName, "_na", "_na", entries);
}
}

View File

@ -598,10 +598,13 @@ public class SimpleFacetsTests extends AbstractNodesTests {
assertThat(facet.name(), equalTo("range1"));
assertThat(facet.entries().size(), equalTo(3));
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).total(), closeTo(1055, 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(Double.parseDouble(facet.entries().get(1).toAsString()), closeTo(1170, 0.000001));
assertThat(facet.entries().get(1).count(), equalTo(2l));
assertThat(facet.entries().get(1).total(), closeTo(1055 + 1065, 0.000001));
assertThat(facet.entries().get(2).from(), closeTo(1170, 0.000001));