From 668e84a99e75fcd4d6c602c04c0fddf4e2b1fb77 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 9 Jun 2010 23:35:31 +0300 Subject: [PATCH] add specific doc object, DocFieldData and specific types extension to allow in the future for simpler doc level operations --- .../index/field/DocFieldData.java | 58 +++++++++++++++++++ .../elasticsearch/index/field/FieldData.java | 17 +++++- .../index/field/NumericDocFieldData.java | 58 +++++++++++++++++++ .../index/field/NumericFieldData.java | 8 ++- .../field/doubles/DoubleDocFieldData.java | 40 +++++++++++++ .../index/field/doubles/DoubleFieldData.java | 10 +++- .../index/field/floats/FloatDocFieldData.java | 40 +++++++++++++ .../index/field/floats/FloatFieldData.java | 10 +++- .../index/field/ints/IntDocFieldData.java | 40 +++++++++++++ .../index/field/ints/IntFieldData.java | 12 +++- .../index/field/longs/LongDocFieldData.java | 40 +++++++++++++ .../index/field/longs/LongFieldData.java | 12 +++- .../index/field/shorts/ShortDocFieldData.java | 40 +++++++++++++ .../index/field/shorts/ShortFieldData.java | 10 +++- .../field/strings/StringDocFieldData.java | 40 +++++++++++++ .../index/field/strings/StringFieldData.java | 10 +++- .../field/doubles/DoubleFieldDataTests.java | 10 ++++ .../field/floats/FloatFieldDataTests.java | 13 ++++- .../index/field/ints/IntFieldDataTests.java | 5 +- .../index/field/longs/LongFieldDataTests.java | 4 ++ .../field/shorts/ShortFieldDataTests.java | 9 ++- .../field/strings/StringFieldDataTests.java | 3 + 22 files changed, 474 insertions(+), 15 deletions(-) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/field/DocFieldData.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/field/NumericDocFieldData.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/field/doubles/DoubleDocFieldData.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/field/floats/FloatDocFieldData.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/field/ints/IntDocFieldData.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/field/longs/LongDocFieldData.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/field/shorts/ShortDocFieldData.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/field/strings/StringDocFieldData.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/DocFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/DocFieldData.java new file mode 100644 index 00000000000..f3766a026ea --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/DocFieldData.java @@ -0,0 +1,58 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.field; + +/** + * @author kimchy (shay.banon) + */ +public abstract class DocFieldData { + + protected final T fieldData; + + protected int docId; + + protected DocFieldData(T fieldData) { + this.fieldData = fieldData; + } + + void setDocId(int docId) { + this.docId = docId; + } + + public String getFieldName() { + return fieldData.fieldName(); + } + + public boolean isEmpty() { + return !fieldData.hasValue(docId); + } + + public String stringValue() { + return fieldData.stringValue(docId); + } + + public FieldData.Type getType() { + return fieldData.type(); + } + + public boolean isMultiValued() { + return fieldData.multiValued(); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/FieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/FieldData.java index 4ce295f3eb8..eb834a337d2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/FieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/FieldData.java @@ -27,6 +27,7 @@ import org.elasticsearch.index.field.ints.IntFieldData; import org.elasticsearch.index.field.longs.LongFieldData; import org.elasticsearch.index.field.shorts.ShortFieldData; import org.elasticsearch.index.field.strings.StringFieldData; +import org.elasticsearch.util.ThreadLocals; import java.io.IOException; @@ -35,7 +36,7 @@ import java.io.IOException; */ // General TODOs on FieldData // TODO Optimize the order (both int[] and int[][] when they are sparse, create an Order abstraction) -public abstract class FieldData { +public abstract class FieldData { public static enum Type { STRING(StringFieldData.class, false), @@ -59,6 +60,12 @@ public abstract class FieldData { } } + private final ThreadLocal> cachedDocFieldData = new ThreadLocal>() { + @Override protected ThreadLocals.CleanableValue initialValue() { + return new ThreadLocals.CleanableValue(createFieldData()); + } + }; + private final String fieldName; private final FieldDataOptions options; @@ -75,6 +82,14 @@ public abstract class FieldData { return fieldName; } + public Doc docFieldData(int docId) { + Doc docFieldData = cachedDocFieldData.get().get(); + docFieldData.setDocId(docId); + return docFieldData; + } + + protected abstract Doc createFieldData(); + /** * Is the field data a multi valued one (has multiple values / terms per document id) or not. */ diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/NumericDocFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/NumericDocFieldData.java new file mode 100644 index 00000000000..d2b65e9b43f --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/NumericDocFieldData.java @@ -0,0 +1,58 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.field; + +/** + * @author kimchy (shay.banon) + */ +public class NumericDocFieldData extends DocFieldData { + + public NumericDocFieldData(T fieldData) { + super(fieldData); + } + + public int getIntValue() { + return fieldData.intValue(docId); + } + + public long getLongValue() { + return fieldData.longValue(docId); + } + + public float getFloatValue() { + return fieldData.floatValue(docId); + } + + public double getDoubleValue() { + return fieldData.doubleValue(docId); + } + + public short getShortValue() { + return fieldData.shortValue(docId); + } + + public byte getByteValue() { + return fieldData.byteValue(docId); + } + + public double[] getDoubleValues() { + return fieldData.doubleValues(docId); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/NumericFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/NumericFieldData.java index 31ce62ee33d..8918efcc20f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/NumericFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/NumericFieldData.java @@ -20,9 +20,9 @@ package org.elasticsearch.index.field; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ -public abstract class NumericFieldData extends FieldData { +public abstract class NumericFieldData extends FieldData { protected NumericFieldData(String fieldName, FieldDataOptions options) { super(fieldName, options); @@ -86,6 +86,10 @@ public abstract class NumericFieldData extends FieldData { return (short) intValue(docId); } + @Override public Doc docFieldData(int docId) { + return super.docFieldData(docId); + } + public abstract double[] doubleValues(int docId); public abstract void forEachValueInDoc(int docId, DoubleValueInDocProc proc); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/doubles/DoubleDocFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/doubles/DoubleDocFieldData.java new file mode 100644 index 00000000000..79ef18e935d --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/doubles/DoubleDocFieldData.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.field.doubles; + +import org.elasticsearch.index.field.NumericDocFieldData; + +/** + * @author kimchy (shay.banon) + */ +public class DoubleDocFieldData extends NumericDocFieldData { + + public DoubleDocFieldData(DoubleFieldData fieldData) { + super(fieldData); + } + + public double getValue() { + return fieldData.value(docId); + } + + public double[] getValues() { + return fieldData.values(docId); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/doubles/DoubleFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/doubles/DoubleFieldData.java index c267f5d2fe7..c933891b2e4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/doubles/DoubleFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/doubles/DoubleFieldData.java @@ -31,7 +31,7 @@ import java.io.IOException; /** * @author kimchy (shay.banon) */ -public abstract class DoubleFieldData extends NumericFieldData { +public abstract class DoubleFieldData extends NumericFieldData { public static final double[] EMPTY_DOUBLE_ARRAY = new double[0]; @@ -48,6 +48,14 @@ public abstract class DoubleFieldData extends NumericFieldData { abstract public double[] values(int docId); + @Override public DoubleDocFieldData docFieldData(int docId) { + return super.docFieldData(docId); + } + + @Override protected DoubleDocFieldData createFieldData() { + return new DoubleDocFieldData(this); + } + @Override public String stringValue(int docId) { return Double.toString(value(docId)); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/floats/FloatDocFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/floats/FloatDocFieldData.java new file mode 100644 index 00000000000..c5663a08f3e --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/floats/FloatDocFieldData.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.field.floats; + +import org.elasticsearch.index.field.NumericDocFieldData; + +/** + * @author kimchy (shay.banon) + */ +public class FloatDocFieldData extends NumericDocFieldData { + + public FloatDocFieldData(FloatFieldData fieldData) { + super(fieldData); + } + + public float getValue() { + return fieldData.value(docId); + } + + public float[] getValues() { + return fieldData.values(docId); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/floats/FloatFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/floats/FloatFieldData.java index 08b68984dbc..49ba88d35f1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/floats/FloatFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/floats/FloatFieldData.java @@ -31,7 +31,7 @@ import java.io.IOException; /** * @author kimchy (Shay Banon) */ -public abstract class FloatFieldData extends NumericFieldData { +public abstract class FloatFieldData extends NumericFieldData { static final float[] EMPTY_FLOAT_ARRAY = new float[0]; @@ -48,6 +48,14 @@ public abstract class FloatFieldData extends NumericFieldData { abstract public float[] values(int docId); + @Override public FloatDocFieldData docFieldData(int docId) { + return super.docFieldData(docId); + } + + @Override protected FloatDocFieldData createFieldData() { + return new FloatDocFieldData(this); + } + @Override public String stringValue(int docId) { return Float.toString(value(docId)); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/ints/IntDocFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/ints/IntDocFieldData.java new file mode 100644 index 00000000000..88c3491d952 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/ints/IntDocFieldData.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.field.ints; + +import org.elasticsearch.index.field.NumericDocFieldData; + +/** + * @author kimchy (shay.banon) + */ +public class IntDocFieldData extends NumericDocFieldData { + + public IntDocFieldData(IntFieldData fieldData) { + super(fieldData); + } + + public int getValue() { + return fieldData.value(docId); + } + + public int[] getValues() { + return fieldData.values(docId); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/ints/IntFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/ints/IntFieldData.java index 2a614deb690..0ae2760875e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/ints/IntFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/ints/IntFieldData.java @@ -29,9 +29,9 @@ import org.elasticsearch.util.gnu.trove.TIntArrayList; import java.io.IOException; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ -public abstract class IntFieldData extends NumericFieldData { +public abstract class IntFieldData extends NumericFieldData { static final int[] EMPTY_INT_ARRAY = new int[0]; @@ -48,6 +48,14 @@ public abstract class IntFieldData extends NumericFieldData { abstract public int[] values(int docId); + @Override public IntDocFieldData docFieldData(int docId) { + return super.docFieldData(docId); + } + + @Override protected IntDocFieldData createFieldData() { + return new IntDocFieldData(this); + } + @Override public String stringValue(int docId) { return Integer.toString(value(docId)); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/longs/LongDocFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/longs/LongDocFieldData.java new file mode 100644 index 00000000000..d4e43fbcb58 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/longs/LongDocFieldData.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.field.longs; + +import org.elasticsearch.index.field.NumericDocFieldData; + +/** + * @author kimchy (shay.banon) + */ +public class LongDocFieldData extends NumericDocFieldData { + + public LongDocFieldData(LongFieldData fieldData) { + super(fieldData); + } + + public long getValue() { + return fieldData.value(docId); + } + + public long[] getValues() { + return fieldData.values(docId); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/longs/LongFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/longs/LongFieldData.java index 69a87517f1c..f3b0c82cc71 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/longs/LongFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/longs/LongFieldData.java @@ -29,9 +29,9 @@ import org.elasticsearch.util.gnu.trove.TLongArrayList; import java.io.IOException; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ -public abstract class LongFieldData extends NumericFieldData { +public abstract class LongFieldData extends NumericFieldData { static final long[] EMPTY_LONG_ARRAY = new long[0]; @@ -49,6 +49,14 @@ public abstract class LongFieldData extends NumericFieldData { abstract public long[] values(int docId); + @Override public LongDocFieldData docFieldData(int docId) { + return super.docFieldData(docId); + } + + @Override protected LongDocFieldData createFieldData() { + return new LongDocFieldData(this); + } + @Override public void forEachValue(StringValueProc proc) { if (freqs == null) { for (int i = 1; i < values.length; i++) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/shorts/ShortDocFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/shorts/ShortDocFieldData.java new file mode 100644 index 00000000000..fd4d67bc445 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/shorts/ShortDocFieldData.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.field.shorts; + +import org.elasticsearch.index.field.NumericDocFieldData; + +/** + * @author kimchy (shay.banon) + */ +public class ShortDocFieldData extends NumericDocFieldData { + + public ShortDocFieldData(ShortFieldData fieldData) { + super(fieldData); + } + + public short getValue() { + return fieldData.value(docId); + } + + public short[] getValues() { + return fieldData.values(docId); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/shorts/ShortFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/shorts/ShortFieldData.java index 39bca87aac4..f7d4211a753 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/shorts/ShortFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/shorts/ShortFieldData.java @@ -31,7 +31,7 @@ import java.io.IOException; /** * @author kimchy (Shay Banon) */ -public abstract class ShortFieldData extends NumericFieldData { +public abstract class ShortFieldData extends NumericFieldData { static final short[] EMPTY_SHORT_ARRAY = new short[0]; @@ -48,6 +48,14 @@ public abstract class ShortFieldData extends NumericFieldData { abstract public short[] values(int docId); + @Override public ShortDocFieldData docFieldData(int docId) { + return super.docFieldData(docId); + } + + @Override protected ShortDocFieldData createFieldData() { + return new ShortDocFieldData(this); + } + @Override public void forEachValue(StringValueProc proc) { if (freqs == null) { for (int i = 1; i < values.length; i++) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/strings/StringDocFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/strings/StringDocFieldData.java new file mode 100644 index 00000000000..df3b14a0306 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/strings/StringDocFieldData.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.field.strings; + +import org.elasticsearch.index.field.DocFieldData; + +/** + * @author kimchy (shay.banon) + */ +public class StringDocFieldData extends DocFieldData { + + public StringDocFieldData(StringFieldData fieldData) { + super(fieldData); + } + + public String getValue() { + return fieldData.value(docId); + } + + public String[] getValues() { + return fieldData.values(docId); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/strings/StringFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/strings/StringFieldData.java index a8063dd2dcb..12c2cd71601 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/strings/StringFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/strings/StringFieldData.java @@ -30,7 +30,7 @@ import java.util.ArrayList; /** * @author kimchy (Shay Banon) */ -public abstract class StringFieldData extends FieldData { +public abstract class StringFieldData extends FieldData { protected final String[] values; protected final int[] freqs; @@ -45,10 +45,18 @@ public abstract class StringFieldData extends FieldData { abstract public String[] values(int docId); + @Override public StringDocFieldData docFieldData(int docId) { + return super.docFieldData(docId); + } + @Override public String stringValue(int docId) { return value(docId); } + @Override protected StringDocFieldData createFieldData() { + return new StringDocFieldData(this); + } + @Override public Type type() { return Type.STRING; } diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/doubles/DoubleFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/doubles/DoubleFieldDataTests.java index 37bc3b6cdc5..7e2ff4a7227 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/doubles/DoubleFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/doubles/DoubleFieldDataTests.java @@ -88,20 +88,27 @@ public class DoubleFieldDataTests { // svalue assertThat(sFieldData.hasValue(0), equalTo(true)); assertThat(sFieldData.value(0), equalTo(4d)); + assertThat(sFieldData.docFieldData(0).getValue(), equalTo(4d)); assertThat(sFieldData.values(0).length, equalTo(1)); assertThat(sFieldData.values(0)[0], equalTo(4d)); + assertThat(sFieldData.docFieldData(0).getValues()[0], equalTo(4d)); assertThat(sFieldData.hasValue(1), equalTo(true)); assertThat(sFieldData.value(1), equalTo(3d)); + assertThat(sFieldData.docFieldData(1).getValue(), equalTo(3d)); assertThat(sFieldData.values(1).length, equalTo(1)); assertThat(sFieldData.values(1)[0], equalTo(3d)); + assertThat(sFieldData.docFieldData(1).getValues()[0], equalTo(3d)); assertThat(sFieldData.hasValue(2), equalTo(true)); assertThat(sFieldData.value(2), equalTo(7d)); + assertThat(sFieldData.docFieldData(2).getValue(), equalTo(7d)); assertThat(sFieldData.values(2).length, equalTo(1)); assertThat(sFieldData.values(2)[0], equalTo(7d)); + assertThat(sFieldData.docFieldData(2).getValues()[0], equalTo(7d)); assertThat(sFieldData.hasValue(3), equalTo(false)); + assertThat(sFieldData.docFieldData(3).isEmpty(), equalTo(true)); assertThat(sFieldData.hasValue(4), equalTo(true)); assertThat(sFieldData.value(4), equalTo(4d)); @@ -129,9 +136,12 @@ public class DoubleFieldDataTests { // mvalue assertThat(mFieldData.hasValue(0), equalTo(true)); + assertThat(mFieldData.docFieldData(0).isEmpty(), equalTo(false)); assertThat(mFieldData.value(0), equalTo(104d)); + assertThat(mFieldData.docFieldData(0).getValue(), equalTo(104d)); assertThat(mFieldData.values(0).length, equalTo(1)); assertThat(mFieldData.values(0)[0], equalTo(104d)); + assertThat(mFieldData.docFieldData(0).getValues()[0], equalTo(104d)); assertThat(mFieldData.hasValue(1), equalTo(true)); assertThat(mFieldData.value(1), equalTo(104d)); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/floats/FloatFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/floats/FloatFieldDataTests.java index 2d3b6c37954..d6ff8a8fc3d 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/floats/FloatFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/floats/FloatFieldDataTests.java @@ -87,9 +87,12 @@ public class FloatFieldDataTests { // svalue assertThat(sFieldData.hasValue(0), equalTo(true)); + assertThat(sFieldData.docFieldData(0).isEmpty(), equalTo(false)); assertThat(sFieldData.value(0), equalTo(4f)); + assertThat(sFieldData.docFieldData(0).getValue(), equalTo(4f)); assertThat(sFieldData.values(0).length, equalTo(1)); - assertThat(sFieldData.values(0)[0], equalTo(4f)); + assertThat(sFieldData.docFieldData(0).getValues().length, equalTo(1)); + assertThat(sFieldData.docFieldData(0).getValues()[0], equalTo(4f)); assertThat(sFieldData.hasValue(1), equalTo(true)); assertThat(sFieldData.value(1), equalTo(3f)); @@ -129,15 +132,21 @@ public class FloatFieldDataTests { // mvalue assertThat(mFieldData.hasValue(0), equalTo(true)); + assertThat(mFieldData.docFieldData(0).isEmpty(), equalTo(false)); assertThat(mFieldData.value(0), equalTo(104f)); + assertThat(mFieldData.docFieldData(0).getValue(), equalTo(104f)); assertThat(mFieldData.values(0).length, equalTo(1)); + assertThat(mFieldData.docFieldData(0).getValues().length, equalTo(1)); assertThat(mFieldData.values(0)[0], equalTo(104f)); + assertThat(mFieldData.docFieldData(0).getValues()[0], equalTo(104f)); assertThat(mFieldData.hasValue(1), equalTo(true)); assertThat(mFieldData.value(1), equalTo(104f)); assertThat(mFieldData.values(1).length, equalTo(2)); + assertThat(mFieldData.docFieldData(1).getValues().length, equalTo(2)); assertThat(mFieldData.values(1)[0], equalTo(104f)); - assertThat(mFieldData.values(1)[1], equalTo(105f)); + assertThat(mFieldData.docFieldData(1).getValues()[0], equalTo(104f)); + assertThat(mFieldData.docFieldData(1).getValues()[1], equalTo(105f)); assertThat(mFieldData.hasValue(2), equalTo(false)); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/ints/IntFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/ints/IntFieldDataTests.java index 06697291c67..071de6b41af 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/ints/IntFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/ints/IntFieldDataTests.java @@ -87,9 +87,12 @@ public class IntFieldDataTests { // svalue assertThat(sFieldData.hasValue(0), equalTo(true)); + assertThat(sFieldData.docFieldData(0).isEmpty(), equalTo(false)); assertThat(sFieldData.value(0), equalTo(4)); + assertThat(sFieldData.docFieldData(0).getValue(), equalTo(4)); assertThat(sFieldData.values(0).length, equalTo(1)); - assertThat(sFieldData.values(0)[0], equalTo(4)); + assertThat(sFieldData.docFieldData(0).getValues().length, equalTo(1)); + assertThat(sFieldData.docFieldData(0).getValues()[0], equalTo(4)); assertThat(sFieldData.hasValue(1), equalTo(true)); assertThat(sFieldData.value(1), equalTo(3)); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/longs/LongFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/longs/LongFieldDataTests.java index 385f42fb3b0..ea51ba1748b 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/longs/LongFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/longs/LongFieldDataTests.java @@ -89,9 +89,13 @@ public class LongFieldDataTests { // svalue assertThat(sFieldData.hasValue(0), equalTo(true)); + assertThat(sFieldData.docFieldData(0).isEmpty(), equalTo(false)); assertThat(sFieldData.value(0), equalTo(4l)); + assertThat(sFieldData.docFieldData(0).getValue(), equalTo(4l)); assertThat(sFieldData.values(0).length, equalTo(1)); + assertThat(sFieldData.docFieldData(0).getValues().length, equalTo(1)); assertThat(sFieldData.values(0)[0], equalTo(4l)); + assertThat(sFieldData.docFieldData(0).getValues()[0], equalTo(4l)); assertThat(sFieldData.hasValue(1), equalTo(true)); assertThat(sFieldData.value(1), equalTo(3l)); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/shorts/ShortFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/shorts/ShortFieldDataTests.java index 59fe4e7e975..4e012f85092 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/shorts/ShortFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/shorts/ShortFieldDataTests.java @@ -87,9 +87,13 @@ public class ShortFieldDataTests { // svalue assertThat(sFieldData.hasValue(0), equalTo(true)); + assertThat(sFieldData.docFieldData(0).isEmpty(), equalTo(false)); assertThat(sFieldData.value(0), equalTo((short) 4)); + assertThat(sFieldData.docFieldData(0).getValue(), equalTo((short) 4)); assertThat(sFieldData.values(0).length, equalTo(1)); + assertThat(sFieldData.docFieldData(0).getValues().length, equalTo(1)); assertThat(sFieldData.values(0)[0], equalTo((short) 4)); + assertThat(sFieldData.docFieldData(0).getValues()[0], equalTo((short) 4)); assertThat(sFieldData.hasValue(1), equalTo(true)); assertThat(sFieldData.value(1), equalTo((short) 3)); @@ -135,9 +139,12 @@ public class ShortFieldDataTests { assertThat(mFieldData.hasValue(1), equalTo(true)); assertThat(mFieldData.value(1), equalTo((short) 104)); + assertThat(mFieldData.docFieldData(1).getValue(), equalTo((short) 104)); assertThat(mFieldData.values(1).length, equalTo(2)); + assertThat(mFieldData.docFieldData(1).getValues().length, equalTo(2)); assertThat(mFieldData.values(1)[0], equalTo((short) 104)); - assertThat(mFieldData.values(1)[1], equalTo((short) 105)); + assertThat(mFieldData.docFieldData(1).getValues()[0], equalTo((short) 104)); + assertThat(mFieldData.docFieldData(1).getValues()[1], equalTo((short) 105)); assertThat(mFieldData.hasValue(2), equalTo(false)); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/strings/StringFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/strings/StringFieldDataTests.java index 60d110ae0f5..efecc2a5f98 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/strings/StringFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/strings/StringFieldDataTests.java @@ -81,8 +81,11 @@ public class StringFieldDataTests { // svalue assertThat(sFieldData.hasValue(0), equalTo(true)); assertThat(sFieldData.value(0), equalTo("zzz")); + assertThat(sFieldData.docFieldData(0).getValue(), equalTo("zzz")); assertThat(sFieldData.values(0).length, equalTo(1)); + assertThat(sFieldData.docFieldData(0).getValues().length, equalTo(1)); assertThat(sFieldData.values(0)[0], equalTo("zzz")); + assertThat(sFieldData.docFieldData(0).getValues()[0], equalTo("zzz")); assertThat(sFieldData.hasValue(1), equalTo(true)); assertThat(sFieldData.value(1), equalTo("xxx"));