move facet reduce from facet process to the actual facet
this will simplify execution, and actually let the process just be a parser (rename will probably happen)
This commit is contained in:
parent
360d7d9425
commit
9539661d40
|
@ -39,7 +39,7 @@ import org.elasticsearch.search.SearchShardTarget;
|
|||
import org.elasticsearch.search.dfs.AggregatedDfs;
|
||||
import org.elasticsearch.search.dfs.DfsSearchResult;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetProcessors;
|
||||
import org.elasticsearch.search.facet.InternalFacet;
|
||||
import org.elasticsearch.search.facet.InternalFacets;
|
||||
import org.elasticsearch.search.fetch.FetchSearchResult;
|
||||
import org.elasticsearch.search.fetch.FetchSearchResultProvider;
|
||||
|
@ -73,14 +73,11 @@ public class SearchPhaseController extends AbstractComponent {
|
|||
|
||||
private static final ShardDoc[] EMPTY = new ShardDoc[0];
|
||||
|
||||
private final FacetProcessors facetProcessors;
|
||||
|
||||
private final boolean optimizeSingleShard;
|
||||
|
||||
@Inject
|
||||
public SearchPhaseController(Settings settings, FacetProcessors facetProcessors) {
|
||||
public SearchPhaseController(Settings settings) {
|
||||
super(settings);
|
||||
this.facetProcessors = facetProcessors;
|
||||
this.optimizeSingleShard = componentSettings.getAsBoolean("optimize_single_shard", true);
|
||||
}
|
||||
|
||||
|
@ -317,8 +314,10 @@ public class SearchPhaseController extends AbstractComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
Facet aggregatedFacet = facetProcessors.processor(facet.type()).reduce(facet.name(), namedFacets);
|
||||
aggregatedFacets.add(aggregatedFacet);
|
||||
if (!namedFacets.isEmpty()) {
|
||||
Facet aggregatedFacet = ((InternalFacet) namedFacets.get(0)).reduce(namedFacets);
|
||||
aggregatedFacets.add(aggregatedFacet);
|
||||
}
|
||||
}
|
||||
facets = new InternalFacets(aggregatedFacets);
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ package org.elasticsearch.search.facet;
|
|||
|
||||
/**
|
||||
* A search facet.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface Facet {
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -33,6 +32,4 @@ public interface FacetProcessor {
|
|||
String[] types();
|
||||
|
||||
FacetCollector parse(String facetName, XContentParser parser, SearchContext context) throws IOException;
|
||||
|
||||
Facet reduce(String name, List<Facet> facets);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.io.stream.Streamable;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,6 +35,8 @@ public interface InternalFacet extends Facet, Streamable, ToXContent {
|
|||
|
||||
String streamType();
|
||||
|
||||
Facet reduce(List<Facet> facets);
|
||||
|
||||
public static interface Stream {
|
||||
Facet readFacet(String type, StreamInput in) throws IOException;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetCollector;
|
||||
import org.elasticsearch.search.facet.FacetPhaseExecutionException;
|
||||
import org.elasticsearch.search.facet.FacetProcessor;
|
||||
|
@ -42,7 +41,6 @@ import org.joda.time.DateTimeZone;
|
|||
import org.joda.time.chrono.ISOChronology;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -212,12 +210,6 @@ public class DateHistogramFacetProcessor extends AbstractComponent implements Fa
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
InternalDateHistogramFacet first = (InternalDateHistogramFacet) facets.get(0);
|
||||
return first.reduce(name, facets);
|
||||
}
|
||||
|
||||
static interface DateFieldParser {
|
||||
|
||||
DateTimeField parse(Chronology chronology);
|
||||
|
|
|
@ -218,7 +218,7 @@ public class InternalCountDateHistogramFacet extends InternalDateHistogramFacet
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
|
|
|
@ -19,11 +19,8 @@
|
|||
|
||||
package org.elasticsearch.search.facet.datehistogram;
|
||||
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.InternalFacet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -33,6 +30,4 @@ public abstract class InternalDateHistogramFacet implements DateHistogramFacet,
|
|||
InternalCountDateHistogramFacet.registerStreams();
|
||||
InternalFullDateHistogramFacet.registerStreams();
|
||||
}
|
||||
|
||||
public abstract Facet reduce(String name, List<Facet> facets);
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ public class InternalFullDateHistogramFacet extends InternalDateHistogramFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
// we need to sort it
|
||||
InternalFullDateHistogramFacet internalFacet = (InternalFullDateHistogramFacet) facets.get(0);
|
||||
|
|
|
@ -24,13 +24,11 @@ import org.elasticsearch.common.component.AbstractComponent;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetCollector;
|
||||
import org.elasticsearch.search.facet.FacetProcessor;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -53,16 +51,4 @@ public class FilterFacetProcessor extends AbstractComponent implements FacetProc
|
|||
Filter facetFilter = context.queryParserService().parseInnerFilter(parser);
|
||||
return new FilterFacetCollector(facetName, facetFilter, context.filterCache());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
int count = 0;
|
||||
for (Facet facet : facets) {
|
||||
count += ((FilterFacet) facet).count();
|
||||
}
|
||||
return new InternalFilterFacet(name, count);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.search.facet.Facet;
|
|||
import org.elasticsearch.search.facet.InternalFacet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -100,6 +101,18 @@ public class InternalFilterFacet implements FilterFacet, InternalFacet {
|
|||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
int count = 0;
|
||||
for (Facet facet : facets) {
|
||||
count += ((FilterFacet) facet).count();
|
||||
}
|
||||
return new InternalFilterFacet(name, count);
|
||||
}
|
||||
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
|||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetCollector;
|
||||
import org.elasticsearch.search.facet.FacetPhaseExecutionException;
|
||||
import org.elasticsearch.search.facet.FacetProcessor;
|
||||
|
@ -187,30 +186,4 @@ public class GeoDistanceFacetProcessor extends AbstractComponent implements Face
|
|||
return new GeoDistanceFacetCollector(facetName, keyIndexFieldData, point.lat(), point.lon(), unit, geoDistance, entries.toArray(new GeoDistanceFacet.Entry[entries.size()]),
|
||||
context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
InternalGeoDistanceFacet agg = null;
|
||||
for (Facet facet : facets) {
|
||||
InternalGeoDistanceFacet geoDistanceFacet = (InternalGeoDistanceFacet) facet;
|
||||
if (agg == null) {
|
||||
agg = geoDistanceFacet;
|
||||
} else {
|
||||
for (int i = 0; i < geoDistanceFacet.entries.length; i++) {
|
||||
GeoDistanceFacet.Entry aggEntry = agg.entries[i];
|
||||
GeoDistanceFacet.Entry currentEntry = geoDistanceFacet.entries[i];
|
||||
aggEntry.count += currentEntry.count;
|
||||
aggEntry.totalCount += currentEntry.totalCount;
|
||||
aggEntry.total += currentEntry.total;
|
||||
if (currentEntry.min < aggEntry.min) {
|
||||
aggEntry.min = currentEntry.min;
|
||||
}
|
||||
if (currentEntry.max > aggEntry.max) {
|
||||
aggEntry.max = currentEntry.max;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return agg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,6 +101,31 @@ public class InternalGeoDistanceFacet implements GeoDistanceFacet, InternalFacet
|
|||
return entries().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
InternalGeoDistanceFacet agg = (InternalGeoDistanceFacet) facets.get(0);
|
||||
for (int i = 1; i < facets.size(); i++) {
|
||||
InternalGeoDistanceFacet geoDistanceFacet = (InternalGeoDistanceFacet) facets.get(i);
|
||||
for (int j = 0; j < geoDistanceFacet.entries.length; j++) {
|
||||
GeoDistanceFacet.Entry aggEntry = agg.entries[j];
|
||||
GeoDistanceFacet.Entry currentEntry = geoDistanceFacet.entries[j];
|
||||
aggEntry.count += currentEntry.count;
|
||||
aggEntry.totalCount += currentEntry.totalCount;
|
||||
aggEntry.total += currentEntry.total;
|
||||
if (currentEntry.min < aggEntry.min) {
|
||||
aggEntry.min = currentEntry.min;
|
||||
}
|
||||
if (currentEntry.max > aggEntry.max) {
|
||||
aggEntry.max = currentEntry.max;
|
||||
}
|
||||
}
|
||||
}
|
||||
return agg;
|
||||
}
|
||||
|
||||
public static InternalGeoDistanceFacet readGeoDistanceFacet(StreamInput in) throws IOException {
|
||||
InternalGeoDistanceFacet facet = new InternalGeoDistanceFacet();
|
||||
facet.readFrom(in);
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetCollector;
|
||||
import org.elasticsearch.search.facet.FacetPhaseExecutionException;
|
||||
import org.elasticsearch.search.facet.FacetProcessor;
|
||||
|
@ -37,7 +36,6 @@ import org.elasticsearch.search.facet.histogram.unbounded.*;
|
|||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -155,10 +153,4 @@ public class HistogramFacetProcessor extends AbstractComponent implements FacetP
|
|||
return new ValueHistogramFacetCollector(facetName, keyIndexFieldData, valueIndexFieldData, interval, comparatorType, context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
InternalHistogramFacet first = (InternalHistogramFacet) facets.get(0);
|
||||
return first.reduce(name, facets);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,15 +19,12 @@
|
|||
|
||||
package org.elasticsearch.search.facet.histogram;
|
||||
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.InternalFacet;
|
||||
import org.elasticsearch.search.facet.histogram.bounded.InternalBoundedCountHistogramFacet;
|
||||
import org.elasticsearch.search.facet.histogram.bounded.InternalBoundedFullHistogramFacet;
|
||||
import org.elasticsearch.search.facet.histogram.unbounded.InternalCountHistogramFacet;
|
||||
import org.elasticsearch.search.facet.histogram.unbounded.InternalFullHistogramFacet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -39,6 +36,4 @@ public abstract class InternalHistogramFacet implements HistogramFacet, Internal
|
|||
InternalBoundedCountHistogramFacet.registerStreams();
|
||||
InternalBoundedFullHistogramFacet.registerStreams();
|
||||
}
|
||||
|
||||
public abstract Facet reduce(String name, List<Facet> facets);
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ public class InternalBoundedCountHistogramFacet extends InternalHistogramFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
InternalBoundedCountHistogramFacet firstHistoFacet = (InternalBoundedCountHistogramFacet) facets.get(0);
|
||||
if (comparatorType != ComparatorType.KEY) {
|
||||
|
|
|
@ -227,7 +227,7 @@ public class InternalBoundedFullHistogramFacet extends InternalHistogramFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
// we need to sort it
|
||||
InternalBoundedFullHistogramFacet internalFacet = (InternalBoundedFullHistogramFacet) facets.get(0);
|
||||
|
|
|
@ -220,7 +220,7 @@ public class InternalCountHistogramFacet extends InternalHistogramFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ public class InternalFullHistogramFacet extends InternalHistogramFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
// we need to sort it
|
||||
InternalFullHistogramFacet internalFacet = (InternalFullHistogramFacet) facets.get(0);
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.search.facet.Facet;
|
|||
import org.elasticsearch.search.facet.InternalFacet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -100,6 +101,20 @@ public class InternalQueryFacet implements QueryFacet, InternalFacet {
|
|||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
int count = 0;
|
||||
for (Facet facet : facets) {
|
||||
if (facet.name().equals(name)) {
|
||||
count += ((QueryFacet) facet).count();
|
||||
}
|
||||
}
|
||||
return new InternalQueryFacet(name, count);
|
||||
}
|
||||
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
|
|
|
@ -24,13 +24,11 @@ import org.elasticsearch.common.component.AbstractComponent;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetCollector;
|
||||
import org.elasticsearch.search.facet.FacetProcessor;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -53,18 +51,4 @@ public class QueryFacetProcessor extends AbstractComponent implements FacetProce
|
|||
Query facetQuery = context.queryParserService().parse(parser).query();
|
||||
return new QueryFacetCollector(facetName, facetQuery, context.filterCache());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
int count = 0;
|
||||
for (Facet facet : facets) {
|
||||
if (facet.name().equals(name)) {
|
||||
count += ((QueryFacet) facet).count();
|
||||
}
|
||||
}
|
||||
return new InternalQueryFacet(name, count);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,6 +101,35 @@ public class InternalRangeFacet implements RangeFacet, InternalFacet {
|
|||
return entries().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
InternalRangeFacet agg = null;
|
||||
for (Facet facet : facets) {
|
||||
InternalRangeFacet geoDistanceFacet = (InternalRangeFacet) facet;
|
||||
if (agg == null) {
|
||||
agg = geoDistanceFacet;
|
||||
} else {
|
||||
for (int i = 0; i < geoDistanceFacet.entries.length; i++) {
|
||||
RangeFacet.Entry aggEntry = agg.entries[i];
|
||||
RangeFacet.Entry currentEntry = geoDistanceFacet.entries[i];
|
||||
aggEntry.count += currentEntry.count;
|
||||
aggEntry.totalCount += currentEntry.totalCount;
|
||||
aggEntry.total += currentEntry.total;
|
||||
if (currentEntry.min < aggEntry.min) {
|
||||
aggEntry.min = currentEntry.min;
|
||||
}
|
||||
if (currentEntry.max > aggEntry.max) {
|
||||
aggEntry.max = currentEntry.max;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return agg;
|
||||
}
|
||||
|
||||
public static InternalRangeFacet readRangeFacet(StreamInput in) throws IOException {
|
||||
InternalRangeFacet facet = new InternalRangeFacet();
|
||||
facet.readFrom(in);
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetCollector;
|
||||
import org.elasticsearch.search.facet.FacetPhaseExecutionException;
|
||||
import org.elasticsearch.search.facet.FacetProcessor;
|
||||
|
@ -156,33 +155,4 @@ public class RangeFacetProcessor extends AbstractComponent implements FacetProce
|
|||
return new KeyValueRangeFacetCollector(facetName, keyIndexFieldData, valueIndexFieldData, rangeEntries, context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
InternalRangeFacet agg = null;
|
||||
for (Facet facet : facets) {
|
||||
InternalRangeFacet geoDistanceFacet = (InternalRangeFacet) facet;
|
||||
if (agg == null) {
|
||||
agg = geoDistanceFacet;
|
||||
} else {
|
||||
for (int i = 0; i < geoDistanceFacet.entries.length; i++) {
|
||||
RangeFacet.Entry aggEntry = agg.entries[i];
|
||||
RangeFacet.Entry currentEntry = geoDistanceFacet.entries[i];
|
||||
aggEntry.count += currentEntry.count;
|
||||
aggEntry.totalCount += currentEntry.totalCount;
|
||||
aggEntry.total += currentEntry.total;
|
||||
if (currentEntry.min < aggEntry.min) {
|
||||
aggEntry.min = currentEntry.min;
|
||||
}
|
||||
if (currentEntry.max > aggEntry.max) {
|
||||
aggEntry.max = currentEntry.max;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return agg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.search.facet.Facet;
|
|||
import org.elasticsearch.search.facet.InternalFacet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -174,6 +175,36 @@ public class InternalStatisticalFacet implements StatisticalFacet, InternalFacet
|
|||
return stdDeviation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
double min = Double.NaN;
|
||||
double max = Double.NaN;
|
||||
double total = 0;
|
||||
double sumOfSquares = 0;
|
||||
long count = 0;
|
||||
|
||||
for (Facet facet : facets) {
|
||||
if (!facet.name().equals(name)) {
|
||||
continue;
|
||||
}
|
||||
InternalStatisticalFacet statsFacet = (InternalStatisticalFacet) facet;
|
||||
if (statsFacet.min() < min || Double.isNaN(min)) {
|
||||
min = statsFacet.min();
|
||||
}
|
||||
if (statsFacet.max() > max || Double.isNaN(max)) {
|
||||
max = statsFacet.max();
|
||||
}
|
||||
total += statsFacet.total();
|
||||
sumOfSquares += statsFacet.sumOfSquares();
|
||||
count += statsFacet.count();
|
||||
}
|
||||
|
||||
return new InternalStatisticalFacet(name, min, max, total, sumOfSquares, count);
|
||||
}
|
||||
|
||||
static final class Fields {
|
||||
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
|
||||
static final XContentBuilderString COUNT = new XContentBuilderString("count");
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetCollector;
|
||||
import org.elasticsearch.search.facet.FacetPhaseExecutionException;
|
||||
import org.elasticsearch.search.facet.FacetProcessor;
|
||||
|
@ -113,34 +112,4 @@ public class StatisticalFacetProcessor extends AbstractComponent implements Face
|
|||
return new ScriptStatisticalFacetCollector(facetName, scriptLang, script, params, context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
double min = Double.NaN;
|
||||
double max = Double.NaN;
|
||||
double total = 0;
|
||||
double sumOfSquares = 0;
|
||||
long count = 0;
|
||||
|
||||
for (Facet facet : facets) {
|
||||
if (!facet.name().equals(name)) {
|
||||
continue;
|
||||
}
|
||||
InternalStatisticalFacet statsFacet = (InternalStatisticalFacet) facet;
|
||||
if (statsFacet.min() < min || Double.isNaN(min)) {
|
||||
min = statsFacet.min();
|
||||
}
|
||||
if (statsFacet.max() > max || Double.isNaN(max)) {
|
||||
max = statsFacet.max();
|
||||
}
|
||||
total += statsFacet.total();
|
||||
sumOfSquares += statsFacet.sumOfSquares();
|
||||
count += statsFacet.count();
|
||||
}
|
||||
|
||||
return new InternalStatisticalFacet(name, min, max, total, sumOfSquares, count);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,11 @@
|
|||
|
||||
package org.elasticsearch.search.facet.terms;
|
||||
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.InternalFacet;
|
||||
import org.elasticsearch.search.facet.terms.doubles.InternalDoubleTermsFacet;
|
||||
import org.elasticsearch.search.facet.terms.longs.InternalLongTermsFacet;
|
||||
import org.elasticsearch.search.facet.terms.strings.InternalStringTermsFacet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -37,6 +34,4 @@ public abstract class InternalTermsFacet implements TermsFacet, InternalFacet {
|
|||
InternalLongTermsFacet.registerStream();
|
||||
InternalDoubleTermsFacet.registerStream();
|
||||
}
|
||||
|
||||
public abstract Facet reduce(String name, List<Facet> facets);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
|
|||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetCollector;
|
||||
import org.elasticsearch.search.facet.FacetPhaseExecutionException;
|
||||
import org.elasticsearch.search.facet.FacetProcessor;
|
||||
|
@ -173,10 +172,4 @@ public class TermsFacetProcessor extends AbstractComponent implements FacetProce
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
InternalTermsFacet first = (InternalTermsFacet) facets.get(0);
|
||||
return first.reduce(name, facets);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ public class InternalLongTermsFacet extends InternalTermsFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
return facets.get(0);
|
||||
}
|
||||
|
|
|
@ -19,14 +19,11 @@
|
|||
|
||||
package org.elasticsearch.search.facet.termsstats;
|
||||
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.InternalFacet;
|
||||
import org.elasticsearch.search.facet.termsstats.doubles.InternalTermsStatsDoubleFacet;
|
||||
import org.elasticsearch.search.facet.termsstats.longs.InternalTermsStatsLongFacet;
|
||||
import org.elasticsearch.search.facet.termsstats.strings.InternalTermsStatsStringFacet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class InternalTermsStatsFacet implements TermsStatsFacet, InternalFacet {
|
||||
|
||||
public static void registerStreams() {
|
||||
|
@ -34,6 +31,4 @@ public abstract class InternalTermsStatsFacet implements TermsStatsFacet, Intern
|
|||
InternalTermsStatsLongFacet.registerStream();
|
||||
InternalTermsStatsDoubleFacet.registerStream();
|
||||
}
|
||||
|
||||
public abstract Facet reduce(String name, List<Facet> facets);
|
||||
}
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
|
|||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.facet.Facet;
|
||||
import org.elasticsearch.search.facet.FacetCollector;
|
||||
import org.elasticsearch.search.facet.FacetPhaseExecutionException;
|
||||
import org.elasticsearch.search.facet.FacetProcessor;
|
||||
|
@ -37,7 +36,6 @@ import org.elasticsearch.search.facet.termsstats.strings.TermsStatsStringFacetCo
|
|||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TermsStatsFacetProcessor extends AbstractComponent implements FacetProcessor {
|
||||
|
@ -128,10 +126,4 @@ public class TermsStatsFacetProcessor extends AbstractComponent implements Facet
|
|||
}
|
||||
return new TermsStatsStringFacetCollector(facetName, keyIndexFieldData, valueIndexFieldData, valueScript, size, comparatorType, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
InternalTermsStatsFacet first = (InternalTermsStatsFacet) facets.get(0);
|
||||
return first.reduce(name, facets);
|
||||
}
|
||||
}
|
|
@ -240,7 +240,7 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
if (requiredSize == 0) {
|
||||
// we need to sort it here!
|
||||
|
|
|
@ -240,7 +240,7 @@ public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
if (requiredSize == 0) {
|
||||
// we need to sort it here!
|
||||
|
|
|
@ -245,7 +245,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Facet reduce(String name, List<Facet> facets) {
|
||||
public Facet reduce(List<Facet> facets) {
|
||||
if (facets.size() == 1) {
|
||||
if (requiredSize == 0) {
|
||||
// we need to sort it here!
|
||||
|
|
Loading…
Reference in New Issue