allow to disable the optimization of removal of ords on single value numerics/geo field data

field data settings in the mappings can have ordinals=always option
This commit is contained in:
Shay Banon 2013-04-05 00:44:07 +02:00
parent 54f685674b
commit 5af6343697
8 changed files with 28 additions and 16 deletions

View File

@ -35,6 +35,18 @@ import org.elasticsearch.index.settings.IndexSettings;
*/
public interface IndexFieldData<FD extends AtomicFieldData> extends IndexComponent {
public static class CommonSettings {
/**
* Should single value cross documents case be optimized to remove ords. Note, this optimization
* might not be supported by all Field Data implementations, but the ones that do, should consult
* this method to check if it should be done or not.
*/
public static boolean removeOrdsOnSingleValue(FieldDataType fieldDataType) {
return !"always".equals(fieldDataType.getSettings().get("ordinals"));
}
}
/**
* The field name.
*/

View File

@ -100,7 +100,7 @@ public class ByteArrayIndexFieldData extends AbstractIndexFieldData<ByteArrayAto
}
try {
Ordinals build = builder.build(fieldDataType.getSettings());
return build(reader, builder, build, new BuilderBytes() {
return build(reader, fieldDataType, builder, build, new BuilderBytes() {
@Override
public byte get(int index) {
return values.get(index);
@ -122,8 +122,8 @@ public class ByteArrayIndexFieldData extends AbstractIndexFieldData<ByteArrayAto
byte[] toArray();
}
static ByteArrayAtomicFieldData build(AtomicReader reader, OrdinalsBuilder builder, Ordinals build, BuilderBytes values) {
if (!build.isMultiValued()) {
static ByteArrayAtomicFieldData build(AtomicReader reader, FieldDataType fieldDataType, OrdinalsBuilder builder, Ordinals build, BuilderBytes values) {
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
Docs ordinals = build.ordinals();
byte[] sValues = new byte[reader.maxDoc()];
int maxDoc = reader.maxDoc();

View File

@ -101,7 +101,7 @@ public class DoubleArrayIndexFieldData extends AbstractIndexFieldData<DoubleArra
values.add(NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(term)));
}
Ordinals build = builder.build(fieldDataType.getSettings());
if (!build.isMultiValued()) {
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
Docs ordinals = build.ordinals();
double[] sValues = new double[reader.maxDoc()];
int maxDoc = reader.maxDoc();

View File

@ -101,7 +101,7 @@ public class FloatArrayIndexFieldData extends AbstractIndexFieldData<FloatArrayA
values.add(NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(term)));
}
Ordinals build = builder.build(fieldDataType.getSettings());
if (!build.isMultiValued()) {
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
Docs ordinals = build.ordinals();
float[] sValues = new float[reader.maxDoc()];
int maxDoc = reader.maxDoc();

View File

@ -106,7 +106,7 @@ public class GeoPointDoubleArrayIndexFieldData extends AbstractIndexFieldData<Ge
}
Ordinals build = builder.build(fieldDataType.getSettings());
if (!build.isMultiValued()) {
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
Docs ordinals = build.ordinals();
double[] sLat = new double[reader.maxDoc()];
double[] sLon = new double[reader.maxDoc()];

View File

@ -100,7 +100,7 @@ public class IntArrayIndexFieldData extends AbstractIndexFieldData<IntArrayAtomi
values.add(NumericUtils.prefixCodedToInt(term));
}
Ordinals build = builder.build(fieldDataType.getSettings());
return build(reader, builder, build, new BuilderIntegers() {
return build(reader, fieldDataType, builder, build, new BuilderIntegers() {
@Override
public int get(int index) {
return values.get(index);
@ -122,8 +122,8 @@ public class IntArrayIndexFieldData extends AbstractIndexFieldData<IntArrayAtomi
int[] toArray();
}
static IntArrayAtomicFieldData build(AtomicReader reader, OrdinalsBuilder builder, Ordinals build, BuilderIntegers values) {
if (!build.isMultiValued()) {
static IntArrayAtomicFieldData build(AtomicReader reader, FieldDataType fieldDataType, OrdinalsBuilder builder, Ordinals build, BuilderIntegers values) {
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
Docs ordinals = build.ordinals();
int[] sValues = new int[reader.maxDoc()];
int maxDoc = reader.maxDoc();

View File

@ -114,7 +114,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<AtomicNumeri
if (fieldDataType.getSettings().getAsBoolean("optimize_type", true)) {
// since the default mapping for numeric is long, its worth optimizing the actual type used to represent the data
if (min >= Byte.MIN_VALUE && max <= Byte.MAX_VALUE) {
return ByteArrayIndexFieldData.build(reader, builder, build, new ByteArrayIndexFieldData.BuilderBytes() {
return ByteArrayIndexFieldData.build(reader, fieldDataType, builder, build, new ByteArrayIndexFieldData.BuilderBytes() {
@Override
public byte get(int index) {
return (byte) values.get(index);
@ -131,7 +131,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<AtomicNumeri
}
});
} else if (min >= Short.MIN_VALUE && max <= Short.MAX_VALUE) {
return ShortArrayIndexFieldData.build(reader, builder, build, new ShortArrayIndexFieldData.BuilderShorts() {
return ShortArrayIndexFieldData.build(reader, fieldDataType, builder, build, new ShortArrayIndexFieldData.BuilderShorts() {
@Override
public short get(int index) {
return (short) values.get(index);
@ -148,7 +148,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<AtomicNumeri
}
});
} else if (min >= Integer.MIN_VALUE && max <= Integer.MAX_VALUE) {
return IntArrayIndexFieldData.build(reader, builder, build, new IntArrayIndexFieldData.BuilderIntegers() {
return IntArrayIndexFieldData.build(reader, fieldDataType, builder, build, new IntArrayIndexFieldData.BuilderIntegers() {
@Override
public int get(int index) {
return (int) values.get(index);
@ -167,7 +167,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<AtomicNumeri
}
}
if (!build.isMultiValued()) {
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
Docs ordinals = build.ordinals();
long[] sValues = new long[reader.maxDoc()];
int maxDoc = reader.maxDoc();

View File

@ -101,7 +101,7 @@ public class ShortArrayIndexFieldData extends AbstractIndexFieldData<ShortArrayA
}
Ordinals build = builder.build(fieldDataType.getSettings());
return build(reader, builder, build, new BuilderShorts() {
return build(reader, fieldDataType, builder, build, new BuilderShorts() {
@Override
public short get(int index) {
return values.get(index);
@ -123,8 +123,8 @@ public class ShortArrayIndexFieldData extends AbstractIndexFieldData<ShortArrayA
short[] toArray();
}
static ShortArrayAtomicFieldData build(AtomicReader reader, OrdinalsBuilder builder, Ordinals build, BuilderShorts values) {
if (!build.isMultiValued()) {
static ShortArrayAtomicFieldData build(AtomicReader reader, FieldDataType fieldDataType, OrdinalsBuilder builder, Ordinals build, BuilderShorts values) {
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
Docs ordinals = build.ordinals();
short[] sValues = new short[reader.maxDoc()];
int maxDoc = reader.maxDoc();