Skip to content

Commit

Permalink
Facets: Remove redundant data returned as part of facet response (for…
Browse files Browse the repository at this point in the history
… example, the field name being faceted), closes #655.
  • Loading branch information
kimchy committed Jan 29, 2011
1 parent 7fa5b0c commit 0b09fd0
Show file tree
Hide file tree
Showing 42 changed files with 62 additions and 558 deletions.
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.search.facet.geodistance;

import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.search.facet.Facet;

import java.util.List;
Expand All @@ -34,18 +33,6 @@ public interface GeoDistanceFacet extends Facet, Iterable<GeoDistanceFacet.Entry
*/
public static final String TYPE = "geo_distance";

String fieldName();

String getFieldName();

String valueFieldName();

String getValueFieldName();

DistanceUnit unit();

DistanceUnit getUnit();

/**
* An ordered list of geo distance facet entries.
*/
Expand Down
Expand Up @@ -38,8 +38,6 @@
*/
public class GeoDistanceFacetCollector extends AbstractFacetCollector {

protected final String fieldName;

protected final String indexFieldName;

protected final double lat;
Expand All @@ -59,7 +57,6 @@ public class GeoDistanceFacetCollector extends AbstractFacetCollector {
public GeoDistanceFacetCollector(String facetName, String fieldName, double lat, double lon, DistanceUnit unit, GeoDistance geoDistance,
GeoDistanceFacet.Entry[] entries, SearchContext context) {
super(facetName);
this.fieldName = fieldName;
this.lat = lat;
this.lon = lon;
this.unit = unit;
Expand Down Expand Up @@ -116,6 +113,6 @@ public GeoDistanceFacetCollector(String facetName, String fieldName, double lat,
}

@Override public Facet facet() {
return new InternalGeoDistanceFacet(facetName, fieldName, fieldName, unit, entries);
return new InternalGeoDistanceFacet(facetName, entries);
}
}
Expand Up @@ -22,7 +22,6 @@
import org.elasticsearch.common.collect.ImmutableList;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.search.facet.Facet;
Expand Down Expand Up @@ -55,22 +54,13 @@ public static void registerStreams() {

private String name;

private String fieldName;

private String valueFieldName;

private DistanceUnit unit;

Entry[] entries;

InternalGeoDistanceFacet() {
}

public InternalGeoDistanceFacet(String name, String fieldName, String valueFieldName, DistanceUnit unit, Entry[] entries) {
public InternalGeoDistanceFacet(String name, Entry[] entries) {
this.name = name;
this.fieldName = fieldName;
this.valueFieldName = valueFieldName;
this.unit = unit;
this.entries = entries;
}

Expand All @@ -90,30 +80,6 @@ public InternalGeoDistanceFacet(String name, String fieldName, String valueField
return type();
}

@Override public String fieldName() {
return this.fieldName;
}

@Override public String getFieldName() {
return fieldName();
}

@Override public String valueFieldName() {
return this.valueFieldName;
}

@Override public String getValueFieldName() {
return valueFieldName();
}

@Override public DistanceUnit unit() {
return this.unit;
}

@Override public DistanceUnit getUnit() {
return unit();
}

@Override public List<Entry> entries() {
return ImmutableList.copyOf(entries);
}
Expand All @@ -134,9 +100,6 @@ public static InternalGeoDistanceFacet readGeoDistanceFacet(StreamInput in) thro

@Override public void readFrom(StreamInput in) throws IOException {
name = in.readUTF();
fieldName = in.readUTF();
valueFieldName = in.readUTF();
unit = DistanceUnit.readDistanceUnit(in);
entries = new Entry[in.readVInt()];
for (int i = 0; i < entries.length; i++) {
entries[i] = new Entry(in.readDouble(), in.readDouble(), in.readVLong(), in.readDouble());
Expand All @@ -145,9 +108,6 @@ public static InternalGeoDistanceFacet readGeoDistanceFacet(StreamInput in) thro

@Override public void writeTo(StreamOutput out) throws IOException {
out.writeUTF(name);
out.writeUTF(fieldName);
out.writeUTF(valueFieldName);
DistanceUnit.writeDistanceUnit(out, unit);
out.writeVInt(entries.length);
for (Entry entry : entries) {
out.writeDouble(entry.from);
Expand All @@ -160,9 +120,6 @@ public static InternalGeoDistanceFacet readGeoDistanceFacet(StreamInput in) thro

static final class Fields {
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
static final XContentBuilderString _FIELD = new XContentBuilderString("_field");
static final XContentBuilderString _VALUE_FIELD = new XContentBuilderString("_value_field");
static final XContentBuilderString _UNIT = new XContentBuilderString("_unit");
static final XContentBuilderString RANGES = new XContentBuilderString("ranges");
static final XContentBuilderString FROM = new XContentBuilderString("from");
static final XContentBuilderString TO = new XContentBuilderString("to");
Expand All @@ -174,9 +131,6 @@ static final class Fields {
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(name);
builder.field(Fields._TYPE, GeoDistanceFacet.TYPE);
builder.field(Fields._FIELD, fieldName);
builder.field(Fields._VALUE_FIELD, valueFieldName);
builder.field(Fields._UNIT, unit);
builder.startArray(Fields.RANGES);
for (Entry entry : entries) {
builder.startObject();
Expand Down
Expand Up @@ -37,8 +37,6 @@
*/
public class ValueGeoDistanceFacetCollector extends GeoDistanceFacetCollector {

private final String valueFieldName;

private final String indexValueFieldName;

private final FieldDataType valueFieldDataType;
Expand All @@ -48,7 +46,6 @@ public class ValueGeoDistanceFacetCollector extends GeoDistanceFacetCollector {
public ValueGeoDistanceFacetCollector(String facetName, String fieldName, double lat, double lon, DistanceUnit unit, GeoDistance geoDistance,
GeoDistanceFacet.Entry[] entries, SearchContext context, String valueFieldName) {
super(facetName, fieldName, lat, lon, unit, geoDistance, entries, context);
this.valueFieldName = valueFieldName;

FieldMapper mapper = context.mapperService().smartNameFieldMapper(valueFieldName);
if (mapper == null) {
Expand Down Expand Up @@ -106,6 +103,6 @@ public ValueGeoDistanceFacetCollector(String facetName, String fieldName, double
}

@Override public Facet facet() {
return new InternalGeoDistanceFacet(facetName, fieldName, valueFieldName, unit, entries);
return new InternalGeoDistanceFacet(facetName, entries);
}
}
Expand Up @@ -42,12 +42,8 @@
*/
public class CountAndTotalHistogramFacetCollector extends AbstractFacetCollector {

private final String fieldName;

private final String indexFieldName;

private final long interval;

private final HistogramFacet.ComparatorType comparatorType;

private final FieldDataCache fieldDataCache;
Expand All @@ -60,8 +56,6 @@ public class CountAndTotalHistogramFacetCollector extends AbstractFacetCollector

public CountAndTotalHistogramFacetCollector(String facetName, String fieldName, long interval, HistogramFacet.ComparatorType comparatorType, SearchContext context) {
super(facetName);
this.fieldName = fieldName;
this.interval = interval;
this.comparatorType = comparatorType;
this.fieldDataCache = context.fieldDataCache();

Expand Down Expand Up @@ -92,7 +86,7 @@ public CountAndTotalHistogramFacetCollector(String facetName, String fieldName,
}

@Override public Facet facet() {
return new InternalCountAndTotalHistogramFacet(facetName, fieldName, fieldName, interval, comparatorType, histoProc.counts(), histoProc.totals());
return new InternalCountAndTotalHistogramFacet(facetName, comparatorType, histoProc.counts(), histoProc.totals());
}

public static long bucket(double value, long interval) {
Expand Down
Expand Up @@ -41,12 +41,8 @@
*/
public class CountHistogramFacetCollector extends AbstractFacetCollector {

private final String fieldName;

private final String indexFieldName;

private final long interval;

private final HistogramFacet.ComparatorType comparatorType;

private final FieldDataCache fieldDataCache;
Expand All @@ -59,8 +55,6 @@ public class CountHistogramFacetCollector extends AbstractFacetCollector {

public CountHistogramFacetCollector(String facetName, String fieldName, long interval, HistogramFacet.ComparatorType comparatorType, SearchContext context) {
super(facetName);
this.fieldName = fieldName;
this.interval = interval;
this.comparatorType = comparatorType;
this.fieldDataCache = context.fieldDataCache();

Expand Down Expand Up @@ -91,7 +85,7 @@ public CountHistogramFacetCollector(String facetName, String fieldName, long int
}

@Override public Facet facet() {
return new InternalCountHistogramFacet(facetName, fieldName, fieldName, interval, comparatorType, histoProc.counts());
return new InternalCountHistogramFacet(facetName, comparatorType, histoProc.counts());
}

public static long bucket(double value, long interval) {
Expand Down
Expand Up @@ -37,26 +37,6 @@ public interface HistogramFacet extends Facet, Iterable<HistogramFacet.Entry> {
*/
public static final String TYPE = "histogram";

/**
* The key field name used with this facet.
*/
String keyFieldName();

/**
* The key field name used with this facet.
*/
String getKeyFieldName();

/**
* The value field name used with this facet.
*/
String valueFieldName();

/**
* The value field name used with this facet.
*/
String getValueFieldName();

/**
* An ordered list of histogram facet entries.
*/
Expand Down
Expand Up @@ -131,11 +131,6 @@ public double getMean() {

private String name;

private String keyFieldName;
private String valueFieldName;

private long interval;

private ComparatorType comparatorType;

TLongLongHashMap counts;
Expand All @@ -147,11 +142,8 @@ public double getMean() {
private InternalCountAndTotalHistogramFacet() {
}

public InternalCountAndTotalHistogramFacet(String name, String keyFieldName, String valueFieldName, long interval, ComparatorType comparatorType, TLongLongHashMap counts, TLongDoubleHashMap totals) {
public InternalCountAndTotalHistogramFacet(String name, ComparatorType comparatorType, TLongLongHashMap counts, TLongDoubleHashMap totals) {
this.name = name;
this.keyFieldName = keyFieldName;
this.valueFieldName = valueFieldName;
this.interval = interval;
this.comparatorType = comparatorType;
this.counts = counts;
this.totals = totals;
Expand All @@ -165,22 +157,6 @@ public InternalCountAndTotalHistogramFacet(String name, String keyFieldName, Str
return name();
}

@Override public String keyFieldName() {
return this.keyFieldName;
}

@Override public String getKeyFieldName() {
return keyFieldName();
}

@Override public String valueFieldName() {
return this.valueFieldName;
}

@Override public String getValueFieldName() {
return valueFieldName();
}

@Override public String type() {
return TYPE;
}
Expand Down Expand Up @@ -264,10 +240,6 @@ private Collection<CountAndTotalEntry> computeEntries() {

static final class Fields {
static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
static final XContentBuilderString _KEY_FIELD = new XContentBuilderString("_key_field");
static final XContentBuilderString _VALUE_FIELD = new XContentBuilderString("_value_field");
static final XContentBuilderString _COMPARATOR = new XContentBuilderString("_comparator");
static final XContentBuilderString _INTERVAL = new XContentBuilderString("_interval");
static final XContentBuilderString ENTRIES = new XContentBuilderString("entries");
static final XContentBuilderString KEY = new XContentBuilderString("key");
static final XContentBuilderString COUNT = new XContentBuilderString("count");
Expand All @@ -278,10 +250,6 @@ static final class Fields {
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(name);
builder.field(Fields._TYPE, HistogramFacet.TYPE);
builder.field(Fields._KEY_FIELD, keyFieldName);
builder.field(Fields._VALUE_FIELD, valueFieldName);
builder.field(Fields._COMPARATOR, comparatorType.description());
builder.field(Fields._INTERVAL, interval);
builder.startArray(Fields.ENTRIES);
for (Entry entry : computeEntries()) {
builder.startObject();
Expand All @@ -304,9 +272,6 @@ public static InternalCountAndTotalHistogramFacet readHistogramFacet(StreamInput

@Override public void readFrom(StreamInput in) throws IOException {
name = in.readUTF();
keyFieldName = in.readUTF();
valueFieldName = in.readUTF();
interval = in.readVLong();
comparatorType = ComparatorType.fromId(in.readByte());

int size = in.readVInt();
Expand All @@ -326,9 +291,6 @@ public static InternalCountAndTotalHistogramFacet readHistogramFacet(StreamInput

@Override public void writeTo(StreamOutput out) throws IOException {
out.writeUTF(name);
out.writeUTF(keyFieldName);
out.writeUTF(valueFieldName);
out.writeVLong(interval);
out.writeByte(comparatorType.id());
// optimize the write, since we know we have the same buckets as keys
out.writeVInt(counts.size());
Expand Down

0 comments on commit 0b09fd0

Please sign in to comment.