better handling of mean computation of some facets to handle division by 0, though, won't happen on most facets

This commit is contained in:
Shay Banon 2011-09-27 00:39:37 +03:00
parent d611182dbf
commit 737589f50d
8 changed files with 52 additions and 4 deletions

View File

@ -28,7 +28,13 @@ import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.search.facet.Facet;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
* @author kimchy (shay.banon)
@ -105,6 +111,9 @@ public class InternalFullDateHistogramFacet extends InternalDateHistogramFacet {
}
@Override public double mean() {
if (totalCount == 0) {
return totalCount;
}
return total / totalCount;
}

View File

@ -118,6 +118,9 @@ public interface GeoDistanceFacet extends Facet, Iterable<GeoDistanceFacet.Entry
* The mean of this facet interval.
*/
public double mean() {
if (totalCount == 0) {
return 0;
}
return total / totalCount;
}

View File

@ -109,6 +109,9 @@ public class InternalBoundedFullHistogramFacet extends InternalHistogramFacet {
}
@Override public double mean() {
if (totalCount == 0) {
return 0;
}
return total / totalCount;
}

View File

@ -134,6 +134,9 @@ public interface RangeFacet extends Facet, Iterable<RangeFacet.Entry> {
* The mean of this facet interval.
*/
public double mean() {
if (totalCount == 0) {
return 0;
}
return total / totalCount;
}

View File

@ -114,6 +114,9 @@ public class InternalStatisticalFacet implements StatisticalFacet, InternalFacet
}
@Override public double mean() {
if (count == 0) {
return 0;
}
return total / count;
}

View File

@ -30,7 +30,13 @@ import org.elasticsearch.search.facet.Facet;
import org.elasticsearch.search.facet.termsstats.InternalTermsStatsFacet;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet {
@ -128,6 +134,9 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet {
}
@Override public double mean() {
if (totalCount == 0) {
return 0;
}
return total / totalCount;
}

View File

@ -30,7 +30,13 @@ import org.elasticsearch.search.facet.Facet;
import org.elasticsearch.search.facet.termsstats.InternalTermsStatsFacet;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet {
@ -127,6 +133,9 @@ public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet {
}
@Override public double mean() {
if (totalCount == 0) {
return 0;
}
return total / totalCount;
}

View File

@ -30,7 +30,13 @@ import org.elasticsearch.search.facet.Facet;
import org.elasticsearch.search.facet.termsstats.InternalTermsStatsFacet;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
@ -128,6 +134,9 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
}
@Override public double mean() {
if (totalCount == 0) {
return 0;
}
return total / totalCount;
}