Cleanup NumericFieldData. FieldData interfaces are reduced to long and double while internal

represenations still operate on the actual datatypes.
This commit is contained in:
Simon Willnauer 2013-02-08 11:28:57 +01:00
parent 1189a2c2c2
commit f5331c9535
40 changed files with 503 additions and 4916 deletions

View File

@ -23,16 +23,8 @@ package org.elasticsearch.index.fielddata;
*/ */
public interface AtomicNumericFieldData<Script extends ScriptDocValues> extends AtomicFieldData<Script> { public interface AtomicNumericFieldData<Script extends ScriptDocValues> extends AtomicFieldData<Script> {
ByteValues getByteValues();
ShortValues getShortValues();
IntValues getIntValues();
LongValues getLongValues(); LongValues getLongValues();
FloatValues getFloatValues();
DoubleValues getDoubleValues(); DoubleValues getDoubleValues();
} }

View File

@ -1,335 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch 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.fielddata;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.fielddata.util.ByteArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef;
/**
*/
public interface ByteValues {
static ByteValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
boolean isMultiValued();
/**
* Is there a value for this doc?
*/
boolean hasValue(int docId);
byte getValue(int docId);
byte getValueMissing(int docId, byte missingValue);
ByteArrayRef getValues(int docId);
Iter getIter(int docId);
void forEachValueInDoc(int docId, ValueInDocProc proc);
static interface ValueInDocProc {
void onValue(int docId, byte value);
void onMissing(int docId);
}
static interface Iter {
boolean hasNext();
byte next();
static class Empty implements Iter {
public static final Empty INSTANCE = new Empty();
@Override
public boolean hasNext() {
return false;
}
@Override
public byte next() {
throw new ElasticSearchIllegalStateException();
}
}
static class Single implements Iter {
public byte value;
public boolean done;
public Single reset(byte value) {
this.value = value;
this.done = false;
return this;
}
@Override
public boolean hasNext() {
return !done;
}
@Override
public byte next() {
assert !done;
done = true;
return value;
}
}
}
static class Empty implements ByteValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public byte getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty ByteValues");
}
@Override
public byte getValueMissing(int docId, byte missingValue) {
return missingValue;
}
@Override
public ByteArrayRef getValues(int docId) {
return ByteArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class IntBased implements ByteValues {
private final IntValues values;
private final ByteArrayRef arrayScratch = new ByteArrayRef(new byte[1], 1);
private final ValueIter iter = new ValueIter();
private final Proc proc = new Proc();
public IntBased(IntValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public byte getValue(int docId) {
return (byte) values.getValue(docId);
}
@Override
public byte getValueMissing(int docId, byte missingValue) {
return (byte) values.getValueMissing(docId, missingValue);
}
@Override
public ByteArrayRef getValues(int docId) {
IntArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size();
if (size == 0) {
return ByteArrayRef.EMPTY;
}
arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = (byte) arrayRef.values[i];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
values.forEachValueInDoc(docId, this.proc.reset(proc));
}
static class ValueIter implements Iter {
private IntValues.Iter iter;
public ValueIter reset(IntValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public byte next() {
return (byte) iter.next();
}
}
static class Proc implements IntValues.ValueInDocProc {
private ValueInDocProc proc;
public Proc reset(ValueInDocProc proc) {
this.proc = proc;
return this;
}
@Override
public void onValue(int docId, int value) {
proc.onValue(docId, (byte) value);
}
@Override
public void onMissing(int docId) {
proc.onMissing(docId);
}
}
}
public static class LongBased implements ByteValues {
private final LongValues values;
private final ByteArrayRef arrayScratch = new ByteArrayRef(new byte[1], 1);
private final ValueIter iter = new ValueIter();
private final Proc proc = new Proc();
public LongBased(LongValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public byte getValue(int docId) {
return (byte) values.getValue(docId);
}
@Override
public byte getValueMissing(int docId, byte missingValue) {
return (byte) values.getValueMissing(docId, missingValue);
}
@Override
public ByteArrayRef getValues(int docId) {
LongArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size();
if (size == 0) {
return ByteArrayRef.EMPTY;
}
arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = (byte) arrayRef.values[i];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
values.forEachValueInDoc(docId, this.proc.reset(proc));
}
static class ValueIter implements Iter {
private LongValues.Iter iter;
public ValueIter reset(LongValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public byte next() {
return (byte) iter.next();
}
}
static class Proc implements LongValues.ValueInDocProc {
private ValueInDocProc proc;
public Proc reset(ValueInDocProc proc) {
this.proc = proc;
return this;
}
@Override
public void onValue(int docId, long value) {
proc.onValue(docId, (byte) value);
}
@Override
public void onMissing(int docId) {
proc.onMissing(docId);
}
}
}
}

View File

@ -238,4 +238,41 @@ public interface DoubleValues {
} }
} }
public static class FilteredDoubleValues implements DoubleValues {
protected final DoubleValues delegate;
public FilteredDoubleValues(DoubleValues delegate) {
this.delegate = delegate;
}
public boolean isMultiValued() {
return delegate.isMultiValued();
}
public boolean hasValue(int docId) {
return delegate.hasValue(docId);
}
public double getValue(int docId) {
return delegate.getValue(docId);
}
public double getValueMissing(int docId, double missingValue) {
return delegate.getValueMissing(docId, missingValue);
}
public DoubleArrayRef getValues(int docId) {
return delegate.getValues(docId);
}
public Iter getIter(int docId) {
return delegate.getIter(docId);
}
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
delegate.forEachValueInDoc(docId, proc);
}
}
} }

View File

@ -1,237 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch 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.fielddata;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.FloatArrayRef;
/**
*/
public interface FloatValues {
static final FloatValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
boolean isMultiValued();
/**
* Is there a value for this doc?
*/
boolean hasValue(int docId);
float getValue(int docId);
float getValueMissing(int docId, float missingValue);
FloatArrayRef getValues(int docId);
Iter getIter(int docId);
void forEachValueInDoc(int docId, ValueInDocProc proc);
static interface ValueInDocProc {
void onValue(int docId, float value);
void onMissing(int docId);
}
static interface Iter {
boolean hasNext();
float next();
static class Empty implements Iter {
public static final Empty INSTANCE = new Empty();
@Override
public boolean hasNext() {
return false;
}
@Override
public float next() {
throw new ElasticSearchIllegalStateException();
}
}
static class Single implements Iter {
public float value;
public boolean done;
public Single reset(float value) {
this.value = value;
this.done = false;
return this;
}
@Override
public boolean hasNext() {
return !done;
}
@Override
public float next() {
assert !done;
done = true;
return value;
}
}
}
static class Empty implements FloatValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public float getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty FloatValues");
}
@Override
public float getValueMissing(int docId, float missingValue) {
return missingValue;
}
@Override
public FloatArrayRef getValues(int docId) {
return FloatArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class DoubleBased implements FloatValues {
private final DoubleValues values;
private final FloatArrayRef arrayScratch = new FloatArrayRef(new float[1], 1);
private final ValueIter iter = new ValueIter();
private final Proc proc = new Proc();
public DoubleBased(DoubleValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public float getValue(int docId) {
return (float) values.getValue(docId);
}
@Override
public float getValueMissing(int docId, float missingValue) {
return (float) values.getValueMissing(docId, missingValue);
}
@Override
public FloatArrayRef getValues(int docId) {
DoubleArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size();
if (size == 0) {
return FloatArrayRef.EMPTY;
}
arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = (float) arrayRef.values[i];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
values.forEachValueInDoc(docId, this.proc.reset(proc));
}
static class ValueIter implements Iter {
private DoubleValues.Iter iter;
public ValueIter reset(DoubleValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public float next() {
return (float) iter.next();
}
}
static class Proc implements DoubleValues.ValueInDocProc {
private ValueInDocProc proc;
public Proc reset(ValueInDocProc proc) {
this.proc = proc;
return this;
}
@Override
public void onValue(int docId, double value) {
proc.onValue(docId, (float) value);
}
@Override
public void onMissing(int docId) {
proc.onMissing(docId);
}
}
}
}

View File

@ -31,39 +31,69 @@ public interface IndexNumericFieldData<FD extends AtomicNumericFieldData> extend
public boolean isFloatingPoint() { public boolean isFloatingPoint() {
return false; return false;
} }
@Override
public int requiredBits() {
return 8;
}
}, },
SHORT { SHORT {
@Override @Override
public boolean isFloatingPoint() { public boolean isFloatingPoint() {
return false; return false;
} }
@Override
public int requiredBits() {
return 16;
}
}, },
INT { INT {
@Override @Override
public boolean isFloatingPoint() { public boolean isFloatingPoint() {
return false; return false;
} }
@Override
public int requiredBits() {
return 32;
}
}, },
LONG { LONG {
@Override @Override
public boolean isFloatingPoint() { public boolean isFloatingPoint() {
return false; return false;
} }
@Override
public int requiredBits() {
return 64;
}
}, },
FLOAT { FLOAT {
@Override @Override
public boolean isFloatingPoint() { public boolean isFloatingPoint() {
return true; return true;
} }
@Override
public int requiredBits() {
return 32;
}
}, },
DOUBLE { DOUBLE {
@Override @Override
public boolean isFloatingPoint() { public boolean isFloatingPoint() {
return true; return true;
} }
@Override
public int requiredBits() {
return 64;
}
}; };
public abstract boolean isFloatingPoint(); public abstract boolean isFloatingPoint();
public abstract int requiredBits();
} }
NumericType getNumericType(); NumericType getNumericType();

View File

@ -1,237 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch 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.fielddata;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef;
/**
*/
public interface IntValues {
static final IntValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
boolean isMultiValued();
/**
* Is there a value for this doc?
*/
boolean hasValue(int docId);
int getValue(int docId);
int getValueMissing(int docId, int missingValue);
IntArrayRef getValues(int docId);
Iter getIter(int docId);
void forEachValueInDoc(int docId, ValueInDocProc proc);
static interface ValueInDocProc {
void onValue(int docId, int value);
void onMissing(int docId);
}
static interface Iter {
boolean hasNext();
int next();
static class Empty implements Iter {
public static final Empty INSTANCE = new Empty();
@Override
public boolean hasNext() {
return false;
}
@Override
public int next() {
throw new ElasticSearchIllegalStateException();
}
}
static class Single implements Iter {
public int value;
public boolean done;
public Single reset(int value) {
this.value = value;
this.done = false;
return this;
}
@Override
public boolean hasNext() {
return !done;
}
@Override
public int next() {
assert !done;
done = true;
return value;
}
}
}
static class Empty implements IntValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public int getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty IntValues");
}
@Override
public int getValueMissing(int docId, int missingValue) {
return missingValue;
}
@Override
public IntArrayRef getValues(int docId) {
return IntArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class LongBased implements IntValues {
private final LongValues values;
private final IntArrayRef arrayScratch = new IntArrayRef(new int[1], 1);
private final ValueIter iter = new ValueIter();
private final Proc proc = new Proc();
public LongBased(LongValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public int getValue(int docId) {
return (int) values.getValue(docId);
}
@Override
public int getValueMissing(int docId, int missingValue) {
return (int) values.getValueMissing(docId, missingValue);
}
@Override
public IntArrayRef getValues(int docId) {
LongArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size();
if (size == 0) {
return IntArrayRef.EMPTY;
}
arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = (int) arrayRef.values[i];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
values.forEachValueInDoc(docId, this.proc.reset(proc));
}
static class ValueIter implements Iter {
private LongValues.Iter iter;
public ValueIter reset(LongValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public int next() {
return (int) iter.next();
}
}
static class Proc implements LongValues.ValueInDocProc {
private ValueInDocProc proc;
public Proc reset(ValueInDocProc proc) {
this.proc = proc;
return this;
}
@Override
public void onValue(int docId, long value) {
proc.onValue(docId, (int) value);
}
@Override
public void onMissing(int docId) {
proc.onMissing(docId);
}
}
}
}

View File

@ -139,4 +139,41 @@ public interface LongValues {
} }
} }
public static class FilteredLongValues implements LongValues {
protected final LongValues delegate;
public FilteredLongValues(LongValues delegate) {
this.delegate = delegate;
}
public boolean isMultiValued() {
return delegate.isMultiValued();
}
public boolean hasValue(int docId) {
return delegate.hasValue(docId);
}
public long getValue(int docId) {
return delegate.getValue(docId);
}
public long getValueMissing(int docId, long missingValue) {
return delegate.getValueMissing(docId, missingValue);
}
public LongArrayRef getValues(int docId) {
return delegate.getValues(docId);
}
public Iter getIter(int docId) {
return delegate.getIter(docId);
}
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
delegate.forEachValueInDoc(docId, proc);
}
}
} }

View File

@ -78,117 +78,7 @@ public interface ScriptDocValues {
} }
} }
static class Bytes implements ScriptDocValues {
private final BytesValues values;
private int docId;
public Bytes(BytesValues values) {
this.values = values;
}
@Override
public void setNextDocId(int docId) {
this.docId = docId;
}
@Override
public boolean isEmpty() {
return !values.hasValue(docId);
}
public BytesRef getValue() {
return values.getValue(docId);
}
public BytesRefArrayRef getValues() {
return values.getValues(docId);
}
}
static class NumericByte implements ScriptDocValues {
private final ByteValues values;
private int docId;
public NumericByte(ByteValues values) {
this.values = values;
}
@Override
public void setNextDocId(int docId) {
this.docId = docId;
}
@Override
public boolean isEmpty() {
return !values.hasValue(docId);
}
public byte getValue() {
return values.getValue(docId);
}
public ByteArrayRef getValues() {
return values.getValues(docId);
}
}
static class NumericShort implements ScriptDocValues {
private final ShortValues values;
private int docId;
public NumericShort(ShortValues values) {
this.values = values;
}
@Override
public void setNextDocId(int docId) {
this.docId = docId;
}
@Override
public boolean isEmpty() {
return !values.hasValue(docId);
}
public short getValue() {
return values.getValue(docId);
}
public ShortArrayRef getValues() {
return values.getValues(docId);
}
}
static class NumericInteger implements ScriptDocValues {
private final IntValues values;
private int docId;
public NumericInteger(IntValues values) {
this.values = values;
}
@Override
public void setNextDocId(int docId) {
this.docId = docId;
}
@Override
public boolean isEmpty() {
return !values.hasValue(docId);
}
public int getValue() {
return values.getValue(docId);
}
public IntArrayRef getValues() {
return values.getValues(docId);
}
}
static class NumericLong implements ScriptDocValues { static class NumericLong implements ScriptDocValues {
@ -224,34 +114,6 @@ public interface ScriptDocValues {
} }
} }
static class NumericFloat implements ScriptDocValues {
private final FloatValues values;
private int docId;
public NumericFloat(FloatValues values) {
this.values = values;
}
@Override
public void setNextDocId(int docId) {
this.docId = docId;
}
@Override
public boolean isEmpty() {
return !values.hasValue(docId);
}
public float getValue() {
return values.getValue(docId);
}
public FloatArrayRef getValues() {
return values.getValues(docId);
}
}
static class NumericDouble implements ScriptDocValues { static class NumericDouble implements ScriptDocValues {
private final DoubleValues values; private final DoubleValues values;

View File

@ -1,335 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch 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.fielddata;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef;
import org.elasticsearch.index.fielddata.util.ShortArrayRef;
/**
*/
public interface ShortValues {
static final ShortValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
boolean isMultiValued();
/**
* Is there a value for this doc?
*/
boolean hasValue(int docId);
short getValue(int docId);
short getValueMissing(int docId, short missingValue);
ShortArrayRef getValues(int docId);
Iter getIter(int docId);
void forEachValueInDoc(int docId, ValueInDocProc proc);
static interface ValueInDocProc {
void onValue(int docId, short value);
void onMissing(int docId);
}
static interface Iter {
boolean hasNext();
short next();
static class Empty implements Iter {
public static final Empty INSTANCE = new Empty();
@Override
public boolean hasNext() {
return false;
}
@Override
public short next() {
throw new ElasticSearchIllegalStateException();
}
}
static class Single implements Iter {
public short value;
public boolean done;
public Single reset(short value) {
this.value = value;
this.done = false;
return this;
}
@Override
public boolean hasNext() {
return !done;
}
@Override
public short next() {
assert !done;
done = true;
return value;
}
}
}
static class Empty implements ShortValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public short getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty ShortValues");
}
@Override
public short getValueMissing(int docId, short missingValue) {
return missingValue;
}
@Override
public ShortArrayRef getValues(int docId) {
return ShortArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class IntBased implements ShortValues {
private final IntValues values;
private final ShortArrayRef arrayScratch = new ShortArrayRef(new short[1], 1);
private final ValueIter iter = new ValueIter();
private final Proc proc = new Proc();
public IntBased(IntValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public short getValue(int docId) {
return (short) values.getValue(docId);
}
@Override
public short getValueMissing(int docId, short missingValue) {
return (short) values.getValueMissing(docId, missingValue);
}
@Override
public ShortArrayRef getValues(int docId) {
IntArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size();
if (size == 0) {
return ShortArrayRef.EMPTY;
}
arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = (short) arrayRef.values[i];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
values.forEachValueInDoc(docId, this.proc.reset(proc));
}
static class ValueIter implements Iter {
private IntValues.Iter iter;
public ValueIter reset(IntValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public short next() {
return (short) iter.next();
}
}
static class Proc implements IntValues.ValueInDocProc {
private ValueInDocProc proc;
public Proc reset(ValueInDocProc proc) {
this.proc = proc;
return this;
}
@Override
public void onValue(int docId, int value) {
proc.onValue(docId, (short) value);
}
@Override
public void onMissing(int docId) {
proc.onMissing(docId);
}
}
}
public static class LongBased implements ShortValues {
private final LongValues values;
private final ShortArrayRef arrayScratch = new ShortArrayRef(new short[1], 1);
private final ValueIter iter = new ValueIter();
private final Proc proc = new Proc();
public LongBased(LongValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public short getValue(int docId) {
return (short) values.getValue(docId);
}
@Override
public short getValueMissing(int docId, short missingValue) {
return (short) values.getValueMissing(docId, missingValue);
}
@Override
public ShortArrayRef getValues(int docId) {
LongArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size();
if (size == 0) {
return ShortArrayRef.EMPTY;
}
arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = (short) arrayRef.values[i];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
values.forEachValueInDoc(docId, this.proc.reset(proc));
}
static class ValueIter implements Iter {
private LongValues.Iter iter;
public ValueIter reset(LongValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public short next() {
return (short) iter.next();
}
}
static class Proc implements LongValues.ValueInDocProc {
private ValueInDocProc proc;
public Proc reset(ValueInDocProc proc) {
this.proc = proc;
return this;
}
@Override
public void onValue(int docId, long value) {
proc.onValue(docId, (short) value);
}
@Override
public void onMissing(int docId) {
proc.onMissing(docId);
}
}
}
}

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.fielddata; package org.elasticsearch.index.fielddata;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals; import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals; import org.elasticsearch.index.fielddata.ordinals.Ordinals;
@ -136,15 +137,15 @@ public interface StringValues {
} }
} }
public static class ByteBased implements StringValues {
private final ByteValues values; static class DoubleBased implements StringValues {
private final DoubleValues values;
private final StringArrayRef arrayScratch = new StringArrayRef(new String[1], 1); private final StringArrayRef arrayScratch = new StringArrayRef(new String[1], 1);
private final ValuesIter valuesIter = new ValuesIter(); private final ValuesIter valuesIter = new ValuesIter();
private final Proc proc = new Proc(); private final Proc proc = new Proc();
public ByteBased(ByteValues values) { public DoubleBased(DoubleValues values) {
this.values = values; this.values = values;
} }
@ -163,18 +164,18 @@ public interface StringValues {
if (!values.hasValue(docId)) { if (!values.hasValue(docId)) {
return null; return null;
} }
return Byte.toString(values.getValue(docId)); return Double.toString(values.getValue(docId));
} }
@Override @Override
public StringArrayRef getValues(int docId) { public StringArrayRef getValues(int docId) {
ByteArrayRef arrayRef = values.getValues(docId); DoubleArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size(); int size = arrayRef.size();
if (size == 0) return StringArrayRef.EMPTY; if (size == 0) return StringArrayRef.EMPTY;
arrayScratch.reset(size); arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) { for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = Byte.toString(arrayRef.values[i]); arrayScratch.values[arrayScratch.end++] = Double.toString(arrayRef.values[i]);
} }
return arrayScratch; return arrayScratch;
} }
@ -191,9 +192,9 @@ public interface StringValues {
static class ValuesIter implements Iter { static class ValuesIter implements Iter {
private ByteValues.Iter iter; private DoubleValues.Iter iter;
private ValuesIter reset(ByteValues.Iter iter) { private ValuesIter reset(DoubleValues.Iter iter) {
this.iter = iter; this.iter = iter;
return this; return this;
} }
@ -205,11 +206,11 @@ public interface StringValues {
@Override @Override
public String next() { public String next() {
return Byte.toString(iter.next()); return Double.toString(iter.next());
} }
} }
static class Proc implements ByteValues.ValueInDocProc { static class Proc implements DoubleValues.ValueInDocProc {
private ValueInDocProc proc; private ValueInDocProc proc;
@ -219,196 +220,8 @@ public interface StringValues {
} }
@Override @Override
public void onValue(int docId, byte value) { public void onValue(int docId, double value) {
proc.onValue(docId, Byte.toString(value)); proc.onValue(docId, Double.toString(value));
}
@Override
public void onMissing(int docId) {
proc.onMissing(docId);
}
}
}
public static class ShortBased implements StringValues {
private final ShortValues values;
private final StringArrayRef arrayScratch = new StringArrayRef(new String[1], 1);
private final ValuesIter valuesIter = new ValuesIter();
private final Proc proc = new Proc();
public ShortBased(ShortValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public String getValue(int docId) {
if (!values.hasValue(docId)) {
return null;
}
return Short.toString(values.getValue(docId));
}
@Override
public StringArrayRef getValues(int docId) {
ShortArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size();
if (size == 0) return StringArrayRef.EMPTY;
arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = Short.toString(arrayRef.values[i]);
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return valuesIter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
values.forEachValueInDoc(docId, this.proc.reset(proc));
}
static class ValuesIter implements Iter {
private ShortValues.Iter iter;
private ValuesIter reset(ShortValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public String next() {
return Short.toString(iter.next());
}
}
static class Proc implements ShortValues.ValueInDocProc {
private ValueInDocProc proc;
private Proc reset(ValueInDocProc proc) {
this.proc = proc;
return this;
}
@Override
public void onValue(int docId, short value) {
proc.onValue(docId, Short.toString(value));
}
@Override
public void onMissing(int docId) {
proc.onMissing(docId);
}
}
}
public static class IntBased implements StringValues {
private final IntValues values;
private final StringArrayRef arrayScratch = new StringArrayRef(new String[1], 1);
private final ValuesIter valuesIter = new ValuesIter();
private final Proc proc = new Proc();
public IntBased(IntValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public String getValue(int docId) {
if (!values.hasValue(docId)) {
return null;
}
return Integer.toString(values.getValue(docId));
}
@Override
public StringArrayRef getValues(int docId) {
IntArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size();
if (size == 0) return StringArrayRef.EMPTY;
arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = Integer.toString(arrayRef.values[i]);
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return valuesIter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
values.forEachValueInDoc(docId, this.proc.reset(proc));
}
static class ValuesIter implements Iter {
private IntValues.Iter iter;
private ValuesIter reset(IntValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public String next() {
return Integer.toString(iter.next());
}
}
static class Proc implements IntValues.ValueInDocProc {
private ValueInDocProc proc;
private Proc reset(ValueInDocProc proc) {
this.proc = proc;
return this;
}
@Override
public void onValue(int docId, int value) {
proc.onValue(docId, Integer.toString(value));
} }
@Override @Override
@ -512,100 +325,6 @@ public interface StringValues {
} }
} }
public static class FloatBased implements StringValues {
private final FloatValues values;
private final StringArrayRef arrayScratch = new StringArrayRef(new String[1], 1);
private final ValuesIter valuesIter = new ValuesIter();
private final Proc proc = new Proc();
public FloatBased(FloatValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public String getValue(int docId) {
if (!values.hasValue(docId)) {
return null;
}
return Float.toString(values.getValue(docId));
}
@Override
public StringArrayRef getValues(int docId) {
FloatArrayRef arrayRef = values.getValues(docId);
int size = arrayRef.size();
if (size == 0) return StringArrayRef.EMPTY;
arrayScratch.reset(size);
for (int i = arrayRef.start; i < arrayRef.end; i++) {
arrayScratch.values[arrayScratch.end++] = Float.toString(arrayRef.values[i]);
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return valuesIter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
values.forEachValueInDoc(docId, this.proc.reset(proc));
}
static class ValuesIter implements Iter {
private FloatValues.Iter iter;
private ValuesIter reset(FloatValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public String next() {
return Float.toString(iter.next());
}
}
static class Proc implements FloatValues.ValueInDocProc {
private ValueInDocProc proc;
private Proc reset(ValueInDocProc proc) {
this.proc = proc;
return this;
}
@Override
public void onValue(int docId, float value) {
proc.onValue(docId, Float.toString(value));
}
@Override
public void onMissing(int docId) {
proc.onMissing(docId);
}
}
}
public interface WithOrdinals extends StringValues { public interface WithOrdinals extends StringValues {
Ordinals.Docs ordinals(); Ordinals.Docs ordinals();

View File

@ -19,44 +19,27 @@
package org.elasticsearch.index.fielddata.fieldcomparator; package org.elasticsearch.index.fielddata.fieldcomparator;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.elasticsearch.index.fielddata.ByteValues;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.util.ByteArrayRef;
import java.io.IOException; import java.io.IOException;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
/** /**
*/ */
public class ByteValuesComparator extends FieldComparator<Byte> { public final class ByteValuesComparator extends LongValuesComparatorBase<Byte> {
private final IndexNumericFieldData indexFieldData;
private final byte missingValue;
private final boolean reversed;
private final byte[] values; private final byte[] values;
private byte bottom;
private ByteValues readerValues;
public ByteValuesComparator(IndexNumericFieldData indexFieldData, byte missingValue, int numHits, boolean reversed) { public ByteValuesComparator(IndexNumericFieldData<?> indexFieldData, byte missingValue, int numHits, boolean reversed) {
this.indexFieldData = indexFieldData; super(indexFieldData, missingValue, reversed);
this.missingValue = missingValue;
this.reversed = reversed;
this.values = new byte[numHits]; this.values = new byte[numHits];
assert indexFieldData.getNumericType().requiredBits() <= 8;
} }
@Override @Override
public int compare(int slot1, int slot2) { public int compare(int slot1, int slot2) {
final byte v1 = values[slot1]; final int v1 = values[slot1];
final byte v2 = values[slot2]; final int v2 = values[slot2];
if (v1 > v2) { return v1 - v2; // we cast to int so it can't overflow
return 1;
} else if (v1 < v2) {
return -1;
} else {
return 0;
}
} }
@Override @Override
@ -64,124 +47,13 @@ public class ByteValuesComparator extends FieldComparator<Byte> {
this.bottom = values[slot]; this.bottom = values[slot];
} }
@Override
public int compareBottom(int doc) throws IOException {
byte v2 = readerValues.getValueMissing(doc, missingValue);
if (bottom > v2) {
return 1;
} else if (bottom < v2) {
return -1;
} else {
return 0;
}
}
@Override @Override
public void copy(int slot, int doc) throws IOException { public void copy(int slot, int doc) throws IOException {
values[slot] = readerValues.getValueMissing(doc, missingValue); values[slot] = (byte) readerValues.getValueMissing(doc, missingValue);
}
@Override
public FieldComparator<Byte> setNextReader(AtomicReaderContext context) throws IOException {
readerValues = indexFieldData.load(context).getByteValues();
if (readerValues.isMultiValued()) {
readerValues = new MultiValuedBytesWrapper(readerValues, reversed);
}
return this;
} }
@Override @Override
public Byte value(int slot) { public Byte value(int slot) {
return Byte.valueOf(values[slot]); return Byte.valueOf(values[slot]);
} }
@Override
public int compareDocToValue(int doc, Byte valueObj) throws IOException {
final byte value = valueObj.byteValue();
byte docValue = readerValues.getValueMissing(doc, missingValue);
if (docValue < value) {
return -1;
} else if (docValue > value) {
return 1;
} else {
return 0;
}
}
public static class FilteredByteValues implements ByteValues {
protected final ByteValues delegate;
public FilteredByteValues(ByteValues delegate) {
this.delegate = delegate;
}
public boolean isMultiValued() {
return delegate.isMultiValued();
}
public boolean hasValue(int docId) {
return delegate.hasValue(docId);
}
public byte getValue(int docId) {
return delegate.getValue(docId);
}
public byte getValueMissing(int docId, byte missingValue) {
return delegate.getValueMissing(docId, missingValue);
}
public ByteArrayRef getValues(int docId) {
return delegate.getValues(docId);
}
public Iter getIter(int docId) {
return delegate.getIter(docId);
}
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
delegate.forEachValueInDoc(docId, proc);
}
}
private static final class MultiValuedBytesWrapper extends FilteredByteValues {
private final boolean reversed;
public MultiValuedBytesWrapper(ByteValues delegate, boolean reversed) {
super(delegate);
this.reversed = reversed;
}
@Override
public byte getValueMissing(int docId, byte missing) {
ByteValues.Iter iter = delegate.getIter(docId);
if (!iter.hasNext()) {
return missing;
}
byte currentVal = iter.next();
byte relevantVal = currentVal;
while (true) {
if (reversed) {
if (currentVal > relevantVal) {
relevantVal = currentVal;
}
} else {
if (currentVal < relevantVal) {
relevantVal = currentVal;
}
}
if (!iter.hasNext()) {
break;
}
currentVal = iter.next();
}
return relevantVal;
}
}
} }

View File

@ -31,10 +31,10 @@ import java.io.IOException;
*/ */
public class ByteValuesComparatorSource extends IndexFieldData.XFieldComparatorSource { public class ByteValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
private final IndexNumericFieldData indexFieldData; private final IndexNumericFieldData<?> indexFieldData;
private final Object missingValue; private final Object missingValue;
public ByteValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) { public ByteValuesComparatorSource(IndexNumericFieldData<?> indexFieldData, @Nullable Object missingValue) {
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
this.missingValue = missingValue; this.missingValue = missingValue;
} }

View File

@ -29,9 +29,9 @@ import java.io.IOException;
*/ */
public class BytesRefFieldComparatorSource extends IndexFieldData.XFieldComparatorSource { public class BytesRefFieldComparatorSource extends IndexFieldData.XFieldComparatorSource {
private final IndexFieldData indexFieldData; private final IndexFieldData<?> indexFieldData;
public BytesRefFieldComparatorSource(IndexFieldData indexFieldData) { public BytesRefFieldComparatorSource(IndexFieldData<?> indexFieldData) {
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
} }
@ -44,7 +44,7 @@ public class BytesRefFieldComparatorSource extends IndexFieldData.XFieldComparat
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
assert fieldname.equals(indexFieldData.getFieldNames().indexName()); assert fieldname.equals(indexFieldData.getFieldNames().indexName());
if (indexFieldData.valuesOrdered() && indexFieldData instanceof IndexFieldData.WithOrdinals) { if (indexFieldData.valuesOrdered() && indexFieldData instanceof IndexFieldData.WithOrdinals) {
return new BytesRefOrdValComparator((IndexFieldData.WithOrdinals) indexFieldData, numHits, reversed); return new BytesRefOrdValComparator((IndexFieldData.WithOrdinals<?>) indexFieldData, numHits, reversed);
} }
return new BytesRefValComparator(indexFieldData, numHits, reversed); return new BytesRefValComparator(indexFieldData, numHits, reversed);
} }

View File

@ -41,7 +41,7 @@ import java.io.IOException;
*/ */
public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> { public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
final IndexFieldData.WithOrdinals indexFieldData; final IndexFieldData.WithOrdinals<?> indexFieldData;
/* Ords for each slot. /* Ords for each slot.
@lucene.internal */ @lucene.internal */
@ -89,7 +89,7 @@ public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
final BytesRef tempBR = new BytesRef(); final BytesRef tempBR = new BytesRef();
public BytesRefOrdValComparator(IndexFieldData.WithOrdinals indexFieldData, int numHits, boolean reversed) { public BytesRefOrdValComparator(IndexFieldData.WithOrdinals<?> indexFieldData, int numHits, boolean reversed) {
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
this.reversed = reversed; this.reversed = reversed;
ords = new int[numHits]; ords = new int[numHits];

View File

@ -36,14 +36,14 @@ import java.io.IOException;
*/ */
public final class BytesRefValComparator extends FieldComparator<BytesRef> { public final class BytesRefValComparator extends FieldComparator<BytesRef> {
private final IndexFieldData indexFieldData; private final IndexFieldData<?> indexFieldData;
private final boolean reversed; private final boolean reversed;
private final BytesRef[] values; private final BytesRef[] values;
private BytesRef bottom; private BytesRef bottom;
private BytesValues docTerms; private BytesValues docTerms;
BytesRefValComparator(IndexFieldData indexFieldData, int numHits, boolean reversed) { BytesRefValComparator(IndexFieldData<?> indexFieldData, int numHits, boolean reversed) {
this.reversed = reversed; this.reversed = reversed;
values = new BytesRef[numHits]; values = new BytesRef[numHits];
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
@ -53,30 +53,13 @@ public final class BytesRefValComparator extends FieldComparator<BytesRef> {
public int compare(int slot1, int slot2) { public int compare(int slot1, int slot2) {
final BytesRef val1 = values[slot1]; final BytesRef val1 = values[slot1];
final BytesRef val2 = values[slot2]; final BytesRef val2 = values[slot2];
if (val1 == null) { return compareValues(val1, val2);
if (val2 == null) {
return 0;
}
return -1;
} else if (val2 == null) {
return 1;
}
return val1.compareTo(val2);
} }
@Override @Override
public int compareBottom(int doc) throws IOException { public int compareBottom(int doc) throws IOException {
BytesRef val2 = docTerms.getValue(doc); final BytesRef val2 = docTerms.getValue(doc);
if (bottom == null) { return compareValues(bottom, val2);
if (val2 == null) {
return 0;
}
return -1;
} else if (val2 == null) {
return 1;
}
return bottom.compareTo(val2);
} }
@Override @Override

View File

@ -47,7 +47,7 @@ public class DoubleScriptDataComparator extends FieldComparator<Double> {
} }
@Override @Override
public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { public FieldComparator<? extends Number> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
return new DoubleScriptDataComparator(numHits, script); return new DoubleScriptDataComparator(numHits, script);
} }

View File

@ -19,30 +19,19 @@
package org.elasticsearch.index.fielddata.fieldcomparator; package org.elasticsearch.index.fielddata.fieldcomparator;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import java.io.IOException; import java.io.IOException;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
/** /**
*/ */
public class DoubleValuesComparator extends FieldComparator<Double> { public final class DoubleValuesComparator extends DoubleValuesComparatorBase<Double> {
private final IndexNumericFieldData indexFieldData;
private final double missingValue;
private final boolean reversed;
private final double[] values; private final double[] values;
private double bottom;
private DoubleValues readerValues;
public DoubleValuesComparator(IndexNumericFieldData indexFieldData, double missingValue, int numHits, boolean reversed) { public DoubleValuesComparator(IndexNumericFieldData<?> indexFieldData, double missingValue, int numHits, boolean reversed) {
this.indexFieldData = indexFieldData; super(indexFieldData, missingValue, reversed);
this.missingValue = missingValue; assert indexFieldData.getNumericType().requiredBits() <= 64;
this.reversed = reversed;
this.values = new double[numHits]; this.values = new double[numHits];
} }
@ -50,13 +39,7 @@ public class DoubleValuesComparator extends FieldComparator<Double> {
public int compare(int slot1, int slot2) { public int compare(int slot1, int slot2) {
final double v1 = values[slot1]; final double v1 = values[slot1];
final double v2 = values[slot2]; final double v2 = values[slot2];
if (v1 > v2) { return compare(v1, v2);
return 1;
} else if (v1 < v2) {
return -1;
} else {
return 0;
}
} }
@Override @Override
@ -64,125 +47,13 @@ public class DoubleValuesComparator extends FieldComparator<Double> {
this.bottom = values[slot]; this.bottom = values[slot];
} }
@Override
public int compareBottom(int doc) throws IOException {
double v2 = readerValues.getValueMissing(doc, missingValue);
if (bottom > v2) {
return 1;
} else if (bottom < v2) {
return -1;
} else {
return 0;
}
}
@Override @Override
public void copy(int slot, int doc) throws IOException { public void copy(int slot, int doc) throws IOException {
values[slot] = readerValues.getValueMissing(doc, missingValue); values[slot] = readerValues.getValueMissing(doc, missingValue);
} }
@Override
public FieldComparator<Double> setNextReader(AtomicReaderContext context) throws IOException {
readerValues = indexFieldData.load(context).getDoubleValues();
if (readerValues.isMultiValued()) {
readerValues = new MultiValuedBytesWrapper(readerValues, reversed);
}
return this;
}
@Override @Override
public Double value(int slot) { public Double value(int slot) {
return Double.valueOf(values[slot]); return Double.valueOf(values[slot]);
} }
@Override
public int compareDocToValue(int doc, Double valueObj) throws IOException {
final double value = valueObj.doubleValue();
double docValue = readerValues.getValueMissing(doc, missingValue);
if (docValue < value) {
return -1;
} else if (docValue > value) {
return 1;
} else {
return 0;
}
}
public static class FilteredByteValues implements DoubleValues {
protected final DoubleValues delegate;
public FilteredByteValues(DoubleValues delegate) {
this.delegate = delegate;
}
public boolean isMultiValued() {
return delegate.isMultiValued();
}
public boolean hasValue(int docId) {
return delegate.hasValue(docId);
}
public double getValue(int docId) {
return delegate.getValue(docId);
}
public double getValueMissing(int docId, double missingValue) {
return delegate.getValueMissing(docId, missingValue);
}
public DoubleArrayRef getValues(int docId) {
return delegate.getValues(docId);
}
public Iter getIter(int docId) {
return delegate.getIter(docId);
}
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
delegate.forEachValueInDoc(docId, proc);
}
}
private static final class MultiValuedBytesWrapper extends FilteredByteValues {
private final boolean reversed;
public MultiValuedBytesWrapper(DoubleValues delegate, boolean reversed) {
super(delegate);
this.reversed = reversed;
}
@Override
public double getValueMissing(int docId, double missing) {
DoubleValues.Iter iter = delegate.getIter(docId);
if (!iter.hasNext()) {
return missing;
}
double currentVal = iter.next();
double relevantVal = currentVal;
while (true) {
int cmp = Double.compare(currentVal, relevantVal);
if (reversed) {
if (cmp > 0) {
relevantVal = currentVal;
}
} else {
if (cmp < 0) {
relevantVal = currentVal;
}
}
if (!iter.hasNext()) {
break;
}
currentVal = iter.next();
}
return relevantVal;
}
}
} }

View File

@ -0,0 +1,113 @@
package org.elasticsearch.index.fielddata.fieldcomparator;
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch 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.
*/
import java.io.IOException;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
abstract class DoubleValuesComparatorBase<T extends Number> extends FieldComparator<T> {
protected final IndexNumericFieldData<?>indexFieldData;
protected final double missingValue;
protected double bottom;
protected DoubleValues readerValues;
private final boolean reversed;
public DoubleValuesComparatorBase(IndexNumericFieldData<?> indexFieldData, double missingValue, boolean reversed) {
this.indexFieldData = indexFieldData;
this.missingValue = missingValue;
this.reversed = reversed;
}
@Override
public final int compareBottom(int doc) throws IOException {
final double v2 = readerValues.getValueMissing(doc, missingValue);
return compare(bottom, v2);
}
@Override
public final int compareDocToValue(int doc, T valueObj) throws IOException {
final double value = valueObj.doubleValue();
final double docValue = readerValues.getValueMissing(doc, missingValue);
return compare(docValue, value);
}
@Override
public final FieldComparator<T> setNextReader(AtomicReaderContext context) throws IOException {
readerValues = indexFieldData.load(context).getDoubleValues();
if (readerValues.isMultiValued()) {
readerValues = new MultiValuedBytesWrapper(readerValues, reversed);
}
return this;
}
static final int compare(double left, double right) {
if (left > right) {
return 1;
} else if (left < right) {
return -1;
} else {
return 0;
}
}
static final class MultiValuedBytesWrapper extends DoubleValues.FilteredDoubleValues {
private final boolean reversed;
public MultiValuedBytesWrapper(DoubleValues delegate, boolean reversed) {
super(delegate);
this.reversed = reversed;
}
@Override
public double getValueMissing(int docId, double missing) {
DoubleValues.Iter iter = delegate.getIter(docId);
if (!iter.hasNext()) {
return missing;
}
double currentVal = iter.next();
double relevantVal = currentVal;
while (true) {
int cmp = Double.compare(currentVal, relevantVal);
if (reversed) {
if (cmp > 0) {
relevantVal = currentVal;
}
} else {
if (cmp < 0) {
relevantVal = currentVal;
}
}
if (!iter.hasNext()) {
break;
}
currentVal = iter.next();
}
return relevantVal;
}
}
}

View File

@ -31,10 +31,10 @@ import java.io.IOException;
*/ */
public class DoubleValuesComparatorSource extends IndexFieldData.XFieldComparatorSource { public class DoubleValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
private final IndexNumericFieldData indexFieldData; private final IndexNumericFieldData<?> indexFieldData;
private final Object missingValue; private final Object missingValue;
public DoubleValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) { public DoubleValuesComparatorSource(IndexNumericFieldData<?> indexFieldData, @Nullable Object missingValue) {
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
this.missingValue = missingValue; this.missingValue = missingValue;
} }

View File

@ -19,30 +19,19 @@
package org.elasticsearch.index.fielddata.fieldcomparator; package org.elasticsearch.index.fielddata.fieldcomparator;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.elasticsearch.index.fielddata.FloatValues;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.util.FloatArrayRef;
import java.io.IOException; import java.io.IOException;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
/** /**
*/ */
public class FloatValuesComparator extends FieldComparator<Float> { public final class FloatValuesComparator extends DoubleValuesComparatorBase<Float> {
private final IndexNumericFieldData indexFieldData;
private final float missingValue;
private final boolean reversed;
private final float[] values; private final float[] values;
private float bottom;
private FloatValues readerValues;
public FloatValuesComparator(IndexNumericFieldData indexFieldData, float missingValue, int numHits, boolean reversed) { public FloatValuesComparator(IndexNumericFieldData<?> indexFieldData, float missingValue, int numHits, boolean reversed) {
this.indexFieldData = indexFieldData; super(indexFieldData, missingValue, reversed);
this.missingValue = missingValue; assert indexFieldData.getNumericType().requiredBits() <= 32;
this.reversed = reversed;
this.values = new float[numHits]; this.values = new float[numHits];
} }
@ -64,31 +53,9 @@ public class FloatValuesComparator extends FieldComparator<Float> {
this.bottom = values[slot]; this.bottom = values[slot];
} }
@Override
public int compareBottom(int doc) throws IOException {
float v2 = readerValues.getValueMissing(doc, missingValue);
if (bottom > v2) {
return 1;
} else if (bottom < v2) {
return -1;
} else {
return 0;
}
}
@Override @Override
public void copy(int slot, int doc) throws IOException { public void copy(int slot, int doc) throws IOException {
values[slot] = readerValues.getValueMissing(doc, missingValue); values[slot] = (float) readerValues.getValueMissing(doc, missingValue);
}
@Override
public FieldComparator<Float> setNextReader(AtomicReaderContext context) throws IOException {
readerValues = indexFieldData.load(context).getFloatValues();
if (readerValues.isMultiValued()) {
readerValues = new MultiValuedBytesWrapper(readerValues, reversed);
}
return this;
} }
@Override @Override
@ -96,93 +63,4 @@ public class FloatValuesComparator extends FieldComparator<Float> {
return Float.valueOf(values[slot]); return Float.valueOf(values[slot]);
} }
@Override
public int compareDocToValue(int doc, Float valueObj) throws IOException {
final float value = valueObj.floatValue();
float docValue = readerValues.getValueMissing(doc, missingValue);
if (docValue < value) {
return -1;
} else if (docValue > value) {
return 1;
} else {
return 0;
}
}
public static class FilteredByteValues implements FloatValues {
protected final FloatValues delegate;
public FilteredByteValues(FloatValues delegate) {
this.delegate = delegate;
}
public boolean isMultiValued() {
return delegate.isMultiValued();
}
public boolean hasValue(int docId) {
return delegate.hasValue(docId);
}
public float getValue(int docId) {
return delegate.getValue(docId);
}
public float getValueMissing(int docId, float missingValue) {
return delegate.getValueMissing(docId, missingValue);
}
public FloatArrayRef getValues(int docId) {
return delegate.getValues(docId);
}
public Iter getIter(int docId) {
return delegate.getIter(docId);
}
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
delegate.forEachValueInDoc(docId, proc);
}
}
private static final class MultiValuedBytesWrapper extends FilteredByteValues {
private final boolean reversed;
public MultiValuedBytesWrapper(FloatValues delegate, boolean reversed) {
super(delegate);
this.reversed = reversed;
}
@Override
public float getValueMissing(int docId, float missing) {
FloatValues.Iter iter = delegate.getIter(docId);
if (!iter.hasNext()) {
return missing;
}
float currentVal = iter.next();
float relevantVal = currentVal;
while (true) {
int cmp = Float.compare(currentVal, relevantVal);
if (reversed) {
if (cmp > 0) {
relevantVal = currentVal;
}
} else {
if (cmp < 0) {
relevantVal = currentVal;
}
}
if (!iter.hasNext()) {
break;
}
currentVal = iter.next();
}
return relevantVal;
}
}
} }

View File

@ -31,10 +31,10 @@ import java.io.IOException;
*/ */
public class FloatValuesComparatorSource extends IndexFieldData.XFieldComparatorSource { public class FloatValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
private final IndexNumericFieldData indexFieldData; private final IndexNumericFieldData<?> indexFieldData;
private final Object missingValue; private final Object missingValue;
public FloatValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) { public FloatValuesComparatorSource(IndexNumericFieldData<?> indexFieldData, @Nullable Object missingValue) {
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
this.missingValue = missingValue; this.missingValue = missingValue;
} }

View File

@ -33,7 +33,7 @@ import java.io.IOException;
*/ */
public class GeoDistanceComparator extends FieldComparator<Double> { public class GeoDistanceComparator extends FieldComparator<Double> {
protected final IndexGeoPointFieldData indexFieldData; protected final IndexGeoPointFieldData<?> indexFieldData;
protected final double lat; protected final double lat;
protected final double lon; protected final double lon;
@ -46,7 +46,7 @@ public class GeoDistanceComparator extends FieldComparator<Double> {
private GeoPointValues readerValues; private GeoPointValues readerValues;
public GeoDistanceComparator(int numHits, IndexGeoPointFieldData indexFieldData, double lat, double lon, DistanceUnit unit, GeoDistance geoDistance) { public GeoDistanceComparator(int numHits, IndexGeoPointFieldData<?> indexFieldData, double lat, double lon, DistanceUnit unit, GeoDistance geoDistance) {
this.values = new double[numHits]; this.values = new double[numHits];
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
this.lat = lat; this.lat = lat;

View File

@ -32,13 +32,13 @@ import java.io.IOException;
*/ */
public class GeoDistanceComparatorSource extends IndexFieldData.XFieldComparatorSource { public class GeoDistanceComparatorSource extends IndexFieldData.XFieldComparatorSource {
private final IndexGeoPointFieldData indexFieldData; private final IndexGeoPointFieldData<?> indexFieldData;
private final double lat; private final double lat;
private final double lon; private final double lon;
private final DistanceUnit unit; private final DistanceUnit unit;
private final GeoDistance geoDistance; private final GeoDistance geoDistance;
public GeoDistanceComparatorSource(IndexGeoPointFieldData indexFieldData, double lat, double lon, DistanceUnit unit, GeoDistance geoDistance) { public GeoDistanceComparatorSource(IndexGeoPointFieldData<?> indexFieldData, double lat, double lon, DistanceUnit unit, GeoDistance geoDistance) {
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
this.lat = lat; this.lat = lat;
this.lon = lon; this.lon = lon;

View File

@ -19,30 +19,19 @@
package org.elasticsearch.index.fielddata.fieldcomparator; package org.elasticsearch.index.fielddata.fieldcomparator;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.IntValues;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
import java.io.IOException; import java.io.IOException;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
/** /**
*/ */
public class IntValuesComparator extends FieldComparator<Integer> { public final class IntValuesComparator extends LongValuesComparatorBase<Integer> {
private final IndexNumericFieldData indexFieldData;
private final int missingValue;
private final boolean reversed;
private final int[] values; private final int[] values;
private int bottom;
private IntValues readerValues;
public IntValuesComparator(IndexNumericFieldData indexFieldData, int missingValue, int numHits, boolean reversed) { public IntValuesComparator(IndexNumericFieldData<?> indexFieldData, int missingValue, int numHits, boolean reversed) {
this.indexFieldData = indexFieldData; super(indexFieldData, missingValue, reversed);
this.missingValue = missingValue; assert indexFieldData.getNumericType().requiredBits() <= 32;
this.reversed = reversed;
this.values = new int[numHits]; this.values = new int[numHits];
} }
@ -64,124 +53,13 @@ public class IntValuesComparator extends FieldComparator<Integer> {
this.bottom = values[slot]; this.bottom = values[slot];
} }
@Override
public int compareBottom(int doc) throws IOException {
int v2 = readerValues.getValueMissing(doc, missingValue);
if (bottom > v2) {
return 1;
} else if (bottom < v2) {
return -1;
} else {
return 0;
}
}
@Override @Override
public void copy(int slot, int doc) throws IOException { public void copy(int slot, int doc) throws IOException {
values[slot] = readerValues.getValueMissing(doc, missingValue); values[slot] = (int) readerValues.getValueMissing(doc, missingValue);
}
@Override
public FieldComparator<Integer> setNextReader(AtomicReaderContext context) throws IOException {
readerValues = indexFieldData.load(context).getIntValues();
if (readerValues.isMultiValued()) {
readerValues = new MultiValuedBytesWrapper(readerValues, reversed);
}
return this;
} }
@Override @Override
public Integer value(int slot) { public Integer value(int slot) {
return Integer.valueOf(values[slot]); return Integer.valueOf(values[slot]);
} }
@Override
public int compareDocToValue(int doc, Integer valueObj) throws IOException {
final int value = valueObj.intValue();
int docValue = readerValues.getValueMissing(doc, missingValue);
if (docValue < value) {
return -1;
} else if (docValue > value) {
return 1;
} else {
return 0;
}
}
public static class FilteredByteValues implements IntValues {
protected final IntValues delegate;
public FilteredByteValues(IntValues delegate) {
this.delegate = delegate;
}
public boolean isMultiValued() {
return delegate.isMultiValued();
}
public boolean hasValue(int docId) {
return delegate.hasValue(docId);
}
public int getValue(int docId) {
return delegate.getValue(docId);
}
public int getValueMissing(int docId, int missingValue) {
return delegate.getValueMissing(docId, missingValue);
}
public IntArrayRef getValues(int docId) {
return delegate.getValues(docId);
}
public Iter getIter(int docId) {
return delegate.getIter(docId);
}
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
delegate.forEachValueInDoc(docId, proc);
}
}
private static final class MultiValuedBytesWrapper extends FilteredByteValues {
private final boolean reversed;
public MultiValuedBytesWrapper(IntValues delegate, boolean reversed) {
super(delegate);
this.reversed = reversed;
}
@Override
public int getValueMissing(int docId, int missing) {
IntValues.Iter iter = delegate.getIter(docId);
if (!iter.hasNext()) {
return missing;
}
int currentVal = iter.next();
int relevantVal = currentVal;
while (true) {
if (reversed) {
if (currentVal > relevantVal) {
relevantVal = currentVal;
}
} else {
if (currentVal < relevantVal) {
relevantVal = currentVal;
}
}
if (!iter.hasNext()) {
break;
}
currentVal = iter.next();
}
return relevantVal;
}
}
} }

View File

@ -31,10 +31,10 @@ import java.io.IOException;
*/ */
public class IntValuesComparatorSource extends IndexFieldData.XFieldComparatorSource { public class IntValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
private final IndexNumericFieldData indexFieldData; private final IndexNumericFieldData<?> indexFieldData;
private final Object missingValue; private final Object missingValue;
public IntValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) { public IntValuesComparatorSource(IndexNumericFieldData<?> indexFieldData, @Nullable Object missingValue) {
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
this.missingValue = missingValue; this.missingValue = missingValue;
} }

View File

@ -19,44 +19,27 @@
package org.elasticsearch.index.fielddata.fieldcomparator; package org.elasticsearch.index.fielddata.fieldcomparator;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.util.LongArrayRef;
import java.io.IOException; import java.io.IOException;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
/** /**
*/ */
public class LongValuesComparator extends FieldComparator<Long> { public final class LongValuesComparator extends LongValuesComparatorBase<Long> {
private final IndexNumericFieldData indexFieldData;
private final long missingValue;
private final boolean reversed;
private final long[] values; private final long[] values;
private LongValues readerValues;
private long bottom;
public LongValuesComparator(IndexNumericFieldData indexFieldData, long missingValue, int numHits, boolean reversed) { public LongValuesComparator(IndexNumericFieldData<?> indexFieldData, long missingValue, int numHits, boolean reversed) {
this.indexFieldData = indexFieldData; super(indexFieldData, missingValue, reversed);
this.missingValue = missingValue;
this.values = new long[numHits]; this.values = new long[numHits];
this.reversed = reversed; assert indexFieldData.getNumericType().requiredBits() <= 64;
} }
@Override @Override
public int compare(int slot1, int slot2) { public int compare(int slot1, int slot2) {
final long v1 = values[slot1]; final long v1 = values[slot1];
final long v2 = values[slot2]; final long v2 = values[slot2];
if (v1 > v2) { return compare(v1, v2);
return 1;
} else if (v1 < v2) {
return -1;
} else {
return 0;
}
} }
@Override @Override
@ -64,139 +47,12 @@ public class LongValuesComparator extends FieldComparator<Long> {
this.bottom = values[slot]; this.bottom = values[slot];
} }
@Override
public int compareBottom(int doc) throws IOException {
long v2 = readerValues.getValueMissing(doc, missingValue);
if (bottom > v2) {
return 1;
} else if (bottom < v2) {
return -1;
} else {
return 0;
}
}
@Override
public void copy(int slot, int doc) throws IOException { public void copy(int slot, int doc) throws IOException {
values[slot] = readerValues.getValueMissing(doc, missingValue); values[slot] = readerValues.getValueMissing(doc, missingValue);
} }
@Override
public FieldComparator<Long> setNextReader(AtomicReaderContext context) throws IOException {
readerValues = indexFieldData.load(context).getLongValues();
if (readerValues.isMultiValued()) {
readerValues = new MultiValuedBytesWrapper(readerValues, reversed);
}
return this;
}
@Override @Override
public Long value(int slot) { public Long value(int slot) {
return Long.valueOf(values[slot]); return Long.valueOf(values[slot]);
} }
@Override
public int compareDocToValue(int doc, Long valueObj) throws IOException {
final long value = valueObj.longValue();
long docValue = readerValues.getValueMissing(doc, missingValue);
if (docValue < value) {
return -1;
} else if (docValue > value) {
return 1;
} else {
return 0;
}
}
// THIS SHOULD GO INTO the fielddata package
public static class FilteredByteValues implements LongValues {
protected final LongValues delegate;
public FilteredByteValues(LongValues delegate) {
this.delegate = delegate;
}
public boolean isMultiValued() {
return delegate.isMultiValued();
}
public boolean hasValue(int docId) {
return delegate.hasValue(docId);
}
public long getValue(int docId) {
return delegate.getValue(docId);
}
public long getValueMissing(int docId, long missingValue) {
return delegate.getValueMissing(docId, missingValue);
}
public LongArrayRef getValues(int docId) {
return delegate.getValues(docId);
}
public Iter getIter(int docId) {
return delegate.getIter(docId);
}
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
delegate.forEachValueInDoc(docId, proc);
}
}
private static final class MultiValuedBytesWrapper extends FilteredByteValues {
private final boolean reversed;
public MultiValuedBytesWrapper(LongValues delegate, boolean reversed) {
super(delegate);
this.reversed = reversed;
}
@Override
public long getValueMissing(int docId, long missing) {
LongValues.Iter iter = delegate.getIter(docId);
if (!iter.hasNext()) {
return missing;
}
long currentVal = iter.next();
long relevantVal = currentVal;
while (true) {
if (reversed) {
if (currentVal > relevantVal) {
relevantVal = currentVal;
}
} else {
if (currentVal < relevantVal) {
relevantVal = currentVal;
}
}
if (!iter.hasNext()) {
break;
}
currentVal = iter.next();
}
return relevantVal;
// If we have a method on readerValues that tells if the values emitted by Iter or ArrayRef are sorted per
// document that we can do this or something similar:
// (This is already possible, if values are loaded from index, but we just need a method that tells us this
// For example a impl that read values from the _source field might not read values in order)
/*if (reversed) {
// Would be nice if there is a way to get highest value from LongValues. The values are sorted anyway.
LongArrayRef ref = readerValues.getValues(doc);
if (ref.isEmpty()) {
return missing;
} else {
return ref.values[ref.end - 1]; // last element is the highest value.
}
} else {
return readerValues.getValueMissing(doc, missing); // returns lowest
}*/
}
}
} }

View File

@ -0,0 +1,127 @@
package org.elasticsearch.index.fielddata.fieldcomparator;
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch 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.
*/
import java.io.IOException;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.LongValues;
abstract class LongValuesComparatorBase<T extends Number> extends FieldComparator<T> {
protected final IndexNumericFieldData<?> indexFieldData;
private final boolean reversed;
protected final long missingValue;
protected long bottom;
protected LongValues readerValues;
public LongValuesComparatorBase(IndexNumericFieldData<?> indexFieldData, long missingValue, boolean reversed) {
this.indexFieldData = indexFieldData;
this.missingValue = missingValue;
this.reversed = reversed;
}
@Override
public final int compareBottom(int doc) throws IOException {
long v2 = readerValues.getValueMissing(doc, missingValue);
return compare(bottom, v2);
}
@Override
public final int compareDocToValue(int doc, T valueObj) throws IOException {
final long value = valueObj.longValue();
long docValue = readerValues.getValueMissing(doc, missingValue);
return compare(docValue, value);
}
static final int compare(long left, long right) {
if (left > right) {
return 1;
} else if (left < right) {
return -1;
} else {
return 0;
}
}
@Override
public final FieldComparator<T> setNextReader(AtomicReaderContext context) throws IOException {
readerValues = indexFieldData.load(context).getLongValues();
if (readerValues.isMultiValued()) {
readerValues = new MultiValuedBytesWrapper(readerValues, reversed);
}
return this;
}
private static final class MultiValuedBytesWrapper extends LongValues.FilteredLongValues {
private final boolean reversed;
public MultiValuedBytesWrapper(LongValues delegate, boolean reversed) {
super(delegate);
this.reversed = reversed;
}
@Override
public long getValueMissing(int docId, long missing) {
LongValues.Iter iter = delegate.getIter(docId);
if (!iter.hasNext()) {
return missing;
}
long currentVal = iter.next();
long relevantVal = currentVal;
while (true) {
if (reversed) {
if (currentVal > relevantVal) {
relevantVal = currentVal;
}
} else {
if (currentVal < relevantVal) {
relevantVal = currentVal;
}
}
if (!iter.hasNext()) {
break;
}
currentVal = iter.next();
}
return relevantVal;
// If we have a method on readerValues that tells if the values emitted by Iter or ArrayRef are sorted per
// document that we can do this or something similar:
// (This is already possible, if values are loaded from index, but we just need a method that tells us this
// For example a impl that read values from the _source field might not read values in order)
/*if (reversed) {
// Would be nice if there is a way to get highest value from LongValues. The values are sorted anyway.
LongArrayRef ref = readerValues.getValues(doc);
if (ref.isEmpty()) {
return missing;
} else {
return ref.values[ref.end - 1]; // last element is the highest value.
}
} else {
return readerValues.getValueMissing(doc, missing); // returns lowest
}*/
}
}
}

View File

@ -31,10 +31,10 @@ import java.io.IOException;
*/ */
public class LongValuesComparatorSource extends IndexFieldData.XFieldComparatorSource { public class LongValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
private final IndexNumericFieldData indexFieldData; private final IndexNumericFieldData<?> indexFieldData;
private final Object missingValue; private final Object missingValue;
public LongValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) { public LongValuesComparatorSource(IndexNumericFieldData<?> indexFieldData, @Nullable Object missingValue) {
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
this.missingValue = missingValue; this.missingValue = missingValue;
} }

View File

@ -19,44 +19,27 @@
package org.elasticsearch.index.fielddata.fieldcomparator; package org.elasticsearch.index.fielddata.fieldcomparator;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.ShortValues;
import org.elasticsearch.index.fielddata.util.ShortArrayRef;
import java.io.IOException; import java.io.IOException;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
/** /**
*/ */
public class ShortValuesComparator extends FieldComparator<Short> { public final class ShortValuesComparator extends LongValuesComparatorBase<Short> {
private final IndexNumericFieldData indexFieldData;
private final short missingValue;
private final boolean reversed;
private final short[] values; private final short[] values;
private short bottom;
private ShortValues readerValues;
public ShortValuesComparator(IndexNumericFieldData indexFieldData, short missingValue, int numHits, boolean reversed) { public ShortValuesComparator(IndexNumericFieldData<?> indexFieldData, short missingValue, int numHits, boolean reversed) {
this.indexFieldData = indexFieldData; super(indexFieldData, missingValue, reversed);
this.missingValue = missingValue; assert indexFieldData.getNumericType().requiredBits() <= 16;
this.reversed = reversed;
this.values = new short[numHits]; this.values = new short[numHits];
} }
@Override @Override
public int compare(int slot1, int slot2) { public int compare(int slot1, int slot2) {
final short v1 = values[slot1]; final int v1 = values[slot1];
final short v2 = values[slot2]; final int v2 = values[slot2];
if (v1 > v2) { return v1-v2; // we cast to int so it can't overflow
return 1;
} else if (v1 < v2) {
return -1;
} else {
return 0;
}
} }
@Override @Override
@ -64,31 +47,9 @@ public class ShortValuesComparator extends FieldComparator<Short> {
this.bottom = values[slot]; this.bottom = values[slot];
} }
@Override
public int compareBottom(int doc) throws IOException {
short v2 = readerValues.getValueMissing(doc, missingValue);
if (bottom > v2) {
return 1;
} else if (bottom < v2) {
return -1;
} else {
return 0;
}
}
@Override @Override
public void copy(int slot, int doc) throws IOException { public void copy(int slot, int doc) throws IOException {
values[slot] = readerValues.getValueMissing(doc, missingValue); values[slot] = (short) readerValues.getValueMissing(doc, missingValue);
}
@Override
public FieldComparator<Short> setNextReader(AtomicReaderContext context) throws IOException {
readerValues = indexFieldData.load(context).getShortValues();
if (readerValues.isMultiValued()) {
readerValues = new MultiValuedBytesWrapper(readerValues, reversed);
}
return this;
} }
@Override @Override
@ -96,92 +57,4 @@ public class ShortValuesComparator extends FieldComparator<Short> {
return Short.valueOf(values[slot]); return Short.valueOf(values[slot]);
} }
@Override
public int compareDocToValue(int doc, Short valueObj) throws IOException {
final short value = valueObj.shortValue();
short docValue = readerValues.getValueMissing(doc, missingValue);
if (docValue < value) {
return -1;
} else if (docValue > value) {
return 1;
} else {
return 0;
}
}
public static class FilteredByteValues implements ShortValues {
protected final ShortValues delegate;
public FilteredByteValues(ShortValues delegate) {
this.delegate = delegate;
}
public boolean isMultiValued() {
return delegate.isMultiValued();
}
public boolean hasValue(int docId) {
return delegate.hasValue(docId);
}
public short getValue(int docId) {
return delegate.getValue(docId);
}
public short getValueMissing(int docId, short missingValue) {
return delegate.getValueMissing(docId, missingValue);
}
public ShortArrayRef getValues(int docId) {
return delegate.getValues(docId);
}
public Iter getIter(int docId) {
return delegate.getIter(docId);
}
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
delegate.forEachValueInDoc(docId, proc);
}
}
private static final class MultiValuedBytesWrapper extends FilteredByteValues {
private final boolean reversed;
public MultiValuedBytesWrapper(ShortValues delegate, boolean reversed) {
super(delegate);
this.reversed = reversed;
}
@Override
public short getValueMissing(int docId, short missing) {
ShortValues.Iter iter = delegate.getIter(docId);
if (!iter.hasNext()) {
return missing;
}
short currentVal = iter.next();
short relevantVal = currentVal;
while (true) {
if (reversed) {
if (currentVal > relevantVal) {
relevantVal = currentVal;
}
} else {
if (currentVal < relevantVal) {
relevantVal = currentVal;
}
}
if (!iter.hasNext()) {
break;
}
currentVal = iter.next();
}
return relevantVal;
}
}
} }

View File

@ -31,10 +31,10 @@ import java.io.IOException;
*/ */
public class ShortValuesComparatorSource extends IndexFieldData.XFieldComparatorSource { public class ShortValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
private final IndexNumericFieldData indexFieldData; private final IndexNumericFieldData<?> indexFieldData;
private final Object missingValue; private final Object missingValue;
public ShortValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) { public ShortValuesComparatorSource(IndexNumericFieldData<?> indexFieldData, @Nullable Object missingValue) {
this.indexFieldData = indexFieldData; this.indexFieldData = indexFieldData;
this.missingValue = missingValue; this.missingValue = missingValue;
} }

View File

@ -46,7 +46,7 @@ public class StringScriptDataComparator extends FieldComparator<String> {
} }
@Override @Override
public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
return new StringScriptDataComparator(numHits, script); return new StringScriptDataComparator(numHits, script);
} }

View File

@ -21,9 +21,14 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage; import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.HashedBytesValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals; import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.ByteArrayRef;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef; import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef; import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef; import org.elasticsearch.index.fielddata.util.LongArrayRef;
@ -55,31 +60,11 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
super(null, 0); super(null, 0);
} }
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return LongValues.EMPTY; return LongValues.EMPTY;
} }
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY; return DoubleValues.EMPTY;
@ -160,27 +145,12 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.ByteBased(getByteValues()); return new StringValues.LongBased(getLongValues());
} }
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericByte(getByteValues()); return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues(values, ordinals.ordinals());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
@ -188,116 +158,11 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
return new LongValues(values, ordinals.ordinals()); return new LongValues(values, ordinals.ordinals());
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, ordinals.ordinals()); return new DoubleValues(values, ordinals.ordinals());
} }
static class ByteValues implements org.elasticsearch.index.fielddata.ByteValues {
private final byte[] values;
private final Ordinals.Docs ordinals;
private final ByteArrayRef arrayScratch = new ByteArrayRef(new byte[1], 1);
private final ValuesIter iter;
ByteValues(byte[] values, Ordinals.Docs ordinals) {
this.values = values;
this.ordinals = ordinals;
this.iter = new ValuesIter(values);
}
@Override
public boolean isMultiValued() {
return ordinals.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return ordinals.getOrd(docId) != 0;
}
@Override
public byte getValue(int docId) {
return values[ordinals.getOrd(docId)];
}
@Override
public byte getValueMissing(int docId, byte missingValue) {
int ord = ordinals.getOrd(docId);
if (ord == 0) {
return missingValue;
} else {
return values[ord];
}
}
@Override
public ByteArrayRef getValues(int docId) {
IntArrayRef ords = ordinals.getOrds(docId);
int size = ords.size();
if (size == 0) return ByteArrayRef.EMPTY;
arrayScratch.reset(size);
for (int i = ords.start; i < ords.end; i++) {
arrayScratch.values[arrayScratch.end++] = values[ords.values[i]];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(ordinals.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
Ordinals.Docs.Iter iter = ordinals.getIter(docId);
int ord = iter.next();
if (ord == 0) {
proc.onMissing(docId);
return;
}
do {
proc.onValue(docId, values[ord]);
} while ((ord = iter.next()) != 0);
}
static class ValuesIter implements Iter {
private final byte[] values;
private Ordinals.Docs.Iter ordsIter;
private int ord;
ValuesIter(byte[] values) {
this.values = values;
}
public ValuesIter reset(Ordinals.Docs.Iter ordsIter) {
this.ordsIter = ordsIter;
this.ord = ordsIter.next();
return this;
}
@Override
public boolean hasNext() {
return ord != 0;
}
@Override
public byte next() {
byte value = values[ord];
ord = ordsIter.next();
return value;
}
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final byte[] values; private final byte[] values;
@ -532,7 +397,7 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericByte(getByteValues()); return new ScriptDocValues.NumericLong(getLongValues());
} }
@Override @Override
@ -547,22 +412,7 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.ByteBased(getByteValues()); return new StringValues.LongBased(getLongValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues(values, set);
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
@ -570,80 +420,12 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
return new LongValues(values, set); return new LongValues(values, set);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, set); return new DoubleValues(values, set);
} }
static class ByteValues implements org.elasticsearch.index.fielddata.ByteValues {
private final byte[] values;
private final FixedBitSet set;
private final ByteArrayRef arrayScratch = new ByteArrayRef(new byte[1], 1);
private final Iter.Single iter = new Iter.Single();
ByteValues(byte[] values, FixedBitSet set) {
this.values = values;
this.set = set;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return set.get(docId);
}
@Override
public byte getValue(int docId) {
return values[docId];
}
@Override
public byte getValueMissing(int docId, byte missingValue) {
if (set.get(docId)) {
return values[docId];
} else {
return missingValue;
}
}
@Override
public ByteArrayRef getValues(int docId) {
if (set.get(docId)) {
arrayScratch.values[0] = values[docId];
return arrayScratch;
} else {
return ByteArrayRef.EMPTY;
}
}
@Override
public Iter getIter(int docId) {
if (set.get(docId)) {
return iter.reset(values[docId]);
} else {
return Iter.Empty.INSTANCE;
}
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
if (set.get(docId)) {
proc.onValue(docId, values[docId]);
}
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final byte[] values; private final byte[] values;
@ -807,7 +589,7 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericByte(getByteValues()); return new ScriptDocValues.NumericLong(getLongValues());
} }
@Override @Override
@ -822,22 +604,7 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.ByteBased(getByteValues()); return new StringValues.LongBased(getLongValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues(values);
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
@ -845,63 +612,11 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
return new LongValues(values); return new LongValues(values);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values); return new DoubleValues(values);
} }
static class ByteValues implements org.elasticsearch.index.fielddata.ByteValues {
private final byte[] values;
private final ByteArrayRef arrayScratch = new ByteArrayRef(new byte[1], 1);
private final Iter.Single iter = new Iter.Single();
ByteValues(byte[] values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return true;
}
@Override
public byte getValue(int docId) {
return values[docId];
}
@Override
public byte getValueMissing(int docId, byte missingValue) {
return values[docId];
}
@Override
public ByteArrayRef getValues(int docId) {
arrayScratch.values[0] = values[docId];
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values[docId]);
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onValue(docId, values[docId]);
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {

View File

@ -55,31 +55,11 @@ public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldDa
super(null, 0); super(null, 0);
} }
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return LongValues.EMPTY; return LongValues.EMPTY;
} }
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY; return DoubleValues.EMPTY;
@ -168,31 +148,11 @@ public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldDa
return new ScriptDocValues.NumericDouble(getDoubleValues()); return new ScriptDocValues.NumericDouble(getDoubleValues());
} }
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return new LongValues(values, ordinals.ordinals()); return new LongValues(values, ordinals.ordinals());
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, ordinals.ordinals()); return new DoubleValues(values, ordinals.ordinals());
@ -541,100 +501,18 @@ public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldDa
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues(values, set); return new StringValues.DoubleBased(getDoubleValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return new LongValues(values, set); return new LongValues(values, set);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, set); return new DoubleValues(values, set);
} }
static class StringValues implements org.elasticsearch.index.fielddata.StringValues {
private final double[] values;
private final FixedBitSet set;
private final StringArrayRef arrayScratch = new StringArrayRef(new String[1], 1);
private final Iter.Single iter = new Iter.Single();
StringValues(double[] values, FixedBitSet set) {
this.values = values;
this.set = set;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return set.get(docId);
}
@Override
public String getValue(int docId) {
if (set.get(docId)) {
return Double.toString(values[docId]);
} else {
return null;
}
}
@Override
public StringArrayRef getValues(int docId) {
if (set.get(docId)) {
arrayScratch.values[0] = Double.toString(values[docId]);
return arrayScratch;
} else {
return StringArrayRef.EMPTY;
}
}
@Override
public Iter getIter(int docId) {
if (set.get(docId)) {
return iter.reset(Double.toString(values[docId]));
} else {
return Iter.Empty.INSTANCE;
}
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
if (set.get(docId)) {
proc.onValue(docId, Double.toString(values[docId]));
} else {
proc.onMissing(docId);
}
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final double[] values; private final double[] values;
@ -815,31 +693,11 @@ public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldDa
return new StringValues(values); return new StringValues(values);
} }
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return new LongValues(values); return new LongValues(values);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values); return new DoubleValues(values);

View File

@ -21,10 +21,15 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage; import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.HashedBytesValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals; import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef; import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.FloatArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef; import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef; import org.elasticsearch.index.fielddata.util.LongArrayRef;
@ -55,31 +60,11 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
super(null, 0); super(null, 0);
} }
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return LongValues.EMPTY; return LongValues.EMPTY;
} }
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY; return DoubleValues.EMPTY;
@ -160,27 +145,12 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.FloatBased(getFloatValues()); return new StringValues.DoubleBased(getDoubleValues());
} }
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericFloat(getFloatValues()); return new ScriptDocValues.NumericDouble(getDoubleValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
@ -188,116 +158,11 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
return new LongValues(values, ordinals.ordinals()); return new LongValues(values, ordinals.ordinals());
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues(values, ordinals.ordinals());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, ordinals.ordinals()); return new DoubleValues(values, ordinals.ordinals());
} }
static class FloatValues implements org.elasticsearch.index.fielddata.FloatValues {
private final float[] values;
private final Ordinals.Docs ordinals;
private final FloatArrayRef arrayScratch = new FloatArrayRef(new float[1], 1);
private final ValuesIter iter;
FloatValues(float[] values, Ordinals.Docs ordinals) {
this.values = values;
this.ordinals = ordinals;
this.iter = new ValuesIter(values);
}
@Override
public boolean isMultiValued() {
return ordinals.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return ordinals.getOrd(docId) != 0;
}
@Override
public float getValue(int docId) {
return values[ordinals.getOrd(docId)];
}
@Override
public float getValueMissing(int docId, float missingValue) {
int ord = ordinals.getOrd(docId);
if (ord == 0) {
return missingValue;
} else {
return values[ord];
}
}
@Override
public FloatArrayRef getValues(int docId) {
IntArrayRef ords = ordinals.getOrds(docId);
int size = ords.size();
if (size == 0) return FloatArrayRef.EMPTY;
arrayScratch.reset(size);
for (int i = ords.start; i < ords.end; i++) {
arrayScratch.values[arrayScratch.end++] = values[ords.values[i]];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(ordinals.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
Ordinals.Docs.Iter iter = ordinals.getIter(docId);
int ord = iter.next();
if (ord == 0) {
proc.onMissing(docId);
return;
}
do {
proc.onValue(docId, values[ord]);
} while ((ord = iter.next()) != 0);
}
static class ValuesIter implements Iter {
private final float[] values;
private Ordinals.Docs.Iter ordsIter;
private int ord;
ValuesIter(float[] values) {
this.values = values;
}
public ValuesIter reset(Ordinals.Docs.Iter ordsIter) {
this.ordsIter = ordsIter;
this.ord = ordsIter.next();
return this;
}
@Override
public boolean hasNext() {
return ord != 0;
}
@Override
public float next() {
float value = values[ord];
ord = ordsIter.next();
return value;
}
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final float[] values; private final float[] values;
@ -532,7 +397,7 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericFloat(getFloatValues()); return new ScriptDocValues.NumericDouble(getDoubleValues());
} }
@Override @Override
@ -547,22 +412,7 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.FloatBased(getFloatValues()); return new StringValues.DoubleBased(getDoubleValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
@ -570,79 +420,11 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
return new LongValues(values, set); return new LongValues(values, set);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues(values, set);
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, set); return new DoubleValues(values, set);
} }
static class FloatValues implements org.elasticsearch.index.fielddata.FloatValues {
private final float[] values;
private final FixedBitSet set;
private final FloatArrayRef arrayScratch = new FloatArrayRef(new float[1], 1);
private final Iter.Single iter = new Iter.Single();
FloatValues(float[] values, FixedBitSet set) {
this.values = values;
this.set = set;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return set.get(docId);
}
@Override
public float getValue(int docId) {
return values[docId];
}
@Override
public float getValueMissing(int docId, float missingValue) {
if (set.get(docId)) {
return values[docId];
} else {
return missingValue;
}
}
@Override
public FloatArrayRef getValues(int docId) {
if (set.get(docId)) {
arrayScratch.values[0] = values[docId];
return arrayScratch;
} else {
return FloatArrayRef.EMPTY;
}
}
@Override
public Iter getIter(int docId) {
if (set.get(docId)) {
return iter.reset(values[docId]);
} else {
return Iter.Empty.INSTANCE;
}
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
if (set.get(docId)) {
proc.onValue(docId, values[docId]);
}
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
@ -807,7 +589,7 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericFloat(getFloatValues()); return new ScriptDocValues.NumericDouble(getDoubleValues());
} }
@Override @Override
@ -822,22 +604,7 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.FloatBased(getFloatValues()); return new StringValues.DoubleBased(getDoubleValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
@ -845,63 +612,11 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
return new LongValues(values); return new LongValues(values);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues(values);
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values); return new DoubleValues(values);
} }
static class FloatValues implements org.elasticsearch.index.fielddata.FloatValues {
private final float[] values;
private final FloatArrayRef arrayScratch = new FloatArrayRef(new float[1], 1);
private final Iter.Single iter = new Iter.Single();
FloatValues(float[] values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return true;
}
@Override
public float getValue(int docId) {
return values[docId];
}
@Override
public float getValueMissing(int docId, float missingValue) {
return values[docId];
}
@Override
public FloatArrayRef getValues(int docId) {
arrayScratch.values[0] = values[docId];
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values[docId]);
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onValue(docId, values[docId]);
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {

View File

@ -54,31 +54,11 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
super(null, 0); super(null, 0);
} }
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return LongValues.EMPTY; return LongValues.EMPTY;
} }
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY; return DoubleValues.EMPTY;
@ -159,27 +139,12 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.IntBased(getIntValues()); return new StringValues.LongBased(getLongValues());
} }
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericInteger(getIntValues()); return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues(values, ordinals.ordinals());
} }
@Override @Override
@ -187,116 +152,11 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
return new LongValues(values, ordinals.ordinals()); return new LongValues(values, ordinals.ordinals());
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, ordinals.ordinals()); return new DoubleValues(values, ordinals.ordinals());
} }
static class IntValues implements org.elasticsearch.index.fielddata.IntValues {
private final int[] values;
private final Ordinals.Docs ordinals;
private final IntArrayRef arrayScratch = new IntArrayRef(new int[1], 1);
private final ValuesIter iter;
IntValues(int[] values, Ordinals.Docs ordinals) {
this.values = values;
this.ordinals = ordinals;
this.iter = new ValuesIter(values);
}
@Override
public boolean isMultiValued() {
return ordinals.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return ordinals.getOrd(docId) != 0;
}
@Override
public int getValue(int docId) {
return values[ordinals.getOrd(docId)];
}
@Override
public int getValueMissing(int docId, int missingValue) {
int ord = ordinals.getOrd(docId);
if (ord == 0) {
return missingValue;
} else {
return values[ord];
}
}
@Override
public IntArrayRef getValues(int docId) {
IntArrayRef ords = ordinals.getOrds(docId);
int size = ords.size();
if (size == 0) return IntArrayRef.EMPTY;
arrayScratch.reset(size);
for (int i = ords.start; i < ords.end; i++) {
arrayScratch.values[arrayScratch.end++] = values[ords.values[i]];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(ordinals.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
Ordinals.Docs.Iter iter = ordinals.getIter(docId);
int ord = iter.next();
if (ord == 0) {
proc.onMissing(docId);
return;
}
do {
proc.onValue(docId, values[ord]);
} while ((ord = iter.next()) != 0);
}
static class ValuesIter implements Iter {
private final int[] values;
private Ordinals.Docs.Iter ordsIter;
private int ord;
ValuesIter(int[] values) {
this.values = values;
}
public ValuesIter reset(Ordinals.Docs.Iter ordsIter) {
this.ordsIter = ordsIter;
this.ord = ordsIter.next();
return this;
}
@Override
public boolean hasNext() {
return ord != 0;
}
@Override
public int next() {
int value = values[ord];
ord = ordsIter.next();
return value;
}
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final int[] values; private final int[] values;
@ -531,7 +391,7 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericInteger(getIntValues()); return new ScriptDocValues.NumericLong(getLongValues());
} }
@Override @Override
@ -549,100 +409,16 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
return new StringValues.LongBased(getLongValues()); return new StringValues.LongBased(getLongValues());
} }
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues(values, set);
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return new LongValues(values, set); return new LongValues(values, set);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, set); return new DoubleValues(values, set);
} }
static class IntValues implements org.elasticsearch.index.fielddata.IntValues {
private final int[] values;
private final FixedBitSet set;
private final IntArrayRef arrayScratch = new IntArrayRef(new int[1], 1);
private final Iter.Single iter = new Iter.Single();
IntValues(int[] values, FixedBitSet set) {
this.values = values;
this.set = set;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return set.get(docId);
}
@Override
public int getValue(int docId) {
return values[docId];
}
@Override
public int getValueMissing(int docId, int missingValue) {
if (set.get(docId)) {
return values[docId];
} else {
return missingValue;
}
}
@Override
public IntArrayRef getValues(int docId) {
if (set.get(docId)) {
arrayScratch.values[0] = values[docId];
return arrayScratch;
} else {
return IntArrayRef.EMPTY;
}
}
@Override
public Iter getIter(int docId) {
if (set.get(docId)) {
return iter.reset(values[docId]);
} else {
return Iter.Empty.INSTANCE;
}
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
if (set.get(docId)) {
proc.onValue(docId, values[docId]);
}
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final int[] values; private final int[] values;
@ -805,7 +581,7 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericInteger(getIntValues()); return new ScriptDocValues.NumericLong(getLongValues());
} }
@Override @Override
@ -823,84 +599,16 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
return new StringValues.LongBased(getLongValues()); return new StringValues.LongBased(getLongValues());
} }
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues(values);
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return new LongValues(values); return new LongValues(values);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values); return new DoubleValues(values);
} }
static class IntValues implements org.elasticsearch.index.fielddata.IntValues {
private final int[] values;
private final IntArrayRef arrayScratch = new IntArrayRef(new int[1], 1);
private final Iter.Single iter = new Iter.Single();
IntValues(int[] values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return true;
}
@Override
public int getValue(int docId) {
return values[docId];
}
@Override
public int getValueMissing(int docId, int missingValue) {
return values[docId];
}
@Override
public IntArrayRef getValues(int docId) {
arrayScratch.values[0] = values[docId];
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values[docId]);
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onValue(docId, values[docId]);
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final int[] values; private final int[] values;

View File

@ -21,7 +21,13 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage; import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.HashedBytesValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals; import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef; import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef; import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -55,31 +61,11 @@ public abstract class LongArrayAtomicFieldData implements AtomicNumericFieldData
super(null, 0); super(null, 0);
} }
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return LongValues.EMPTY; return LongValues.EMPTY;
} }
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY; return DoubleValues.EMPTY;
@ -168,31 +154,10 @@ public abstract class LongArrayAtomicFieldData implements AtomicNumericFieldData
return new ScriptDocValues.NumericLong(getLongValues()); return new ScriptDocValues.NumericLong(getLongValues());
} }
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return new LongValues(values, ordinals.ordinals()); return new LongValues(values, ordinals.ordinals());
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, ordinals.ordinals()); return new DoubleValues(values, ordinals.ordinals());
@ -544,31 +509,11 @@ public abstract class LongArrayAtomicFieldData implements AtomicNumericFieldData
return new StringValues(values, set); return new StringValues(values, set);
} }
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return new LongValues(values, set); return new LongValues(values, set);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, set); return new DoubleValues(values, set);
@ -815,31 +760,11 @@ public abstract class LongArrayAtomicFieldData implements AtomicNumericFieldData
return new StringValues(values); return new StringValues(values);
} }
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues.LongBased(getLongValues());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return new LongValues(values); return new LongValues(values);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values); return new DoubleValues(values);

View File

@ -21,12 +21,17 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage; import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.*; import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.HashedBytesValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals; import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef; import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef; import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef; import org.elasticsearch.index.fielddata.util.LongArrayRef;
import org.elasticsearch.index.fielddata.util.ShortArrayRef;
/** /**
*/ */
@ -55,31 +60,11 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
super(null, 0); super(null, 0);
} }
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override @Override
public LongValues getLongValues() { public LongValues getLongValues() {
return LongValues.EMPTY; return LongValues.EMPTY;
} }
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY; return DoubleValues.EMPTY;
@ -160,27 +145,12 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.ShortBased(getShortValues()); return new StringValues.LongBased(getLongValues());
} }
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericShort(getShortValues()); return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues(values, ordinals.ordinals());
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
@ -188,116 +158,11 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
return new LongValues(values, ordinals.ordinals()); return new LongValues(values, ordinals.ordinals());
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, ordinals.ordinals()); return new DoubleValues(values, ordinals.ordinals());
} }
static class ShortValues implements org.elasticsearch.index.fielddata.ShortValues {
private final short[] values;
private final Ordinals.Docs ordinals;
private final ShortArrayRef arrayScratch = new ShortArrayRef(new short[1], 1);
private final ValuesIter iter;
ShortValues(short[] values, Ordinals.Docs ordinals) {
this.values = values;
this.ordinals = ordinals;
this.iter = new ValuesIter(values);
}
@Override
public boolean isMultiValued() {
return ordinals.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return ordinals.getOrd(docId) != 0;
}
@Override
public short getValue(int docId) {
return values[ordinals.getOrd(docId)];
}
@Override
public short getValueMissing(int docId, short missingValue) {
int ord = ordinals.getOrd(docId);
if (ord == 0) {
return missingValue;
} else {
return values[ord];
}
}
@Override
public ShortArrayRef getValues(int docId) {
IntArrayRef ords = ordinals.getOrds(docId);
int size = ords.size();
if (size == 0) return ShortArrayRef.EMPTY;
arrayScratch.reset(size);
for (int i = ords.start; i < ords.end; i++) {
arrayScratch.values[arrayScratch.end++] = values[ords.values[i]];
}
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(ordinals.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
Ordinals.Docs.Iter iter = ordinals.getIter(docId);
int ord = iter.next();
if (ord == 0) {
proc.onMissing(docId);
return;
}
do {
proc.onValue(docId, values[ord]);
} while ((ord = iter.next()) != 0);
}
static class ValuesIter implements Iter {
private final short[] values;
private Ordinals.Docs.Iter ordsIter;
private int ord;
ValuesIter(short[] values) {
this.values = values;
}
public ValuesIter reset(Ordinals.Docs.Iter ordsIter) {
this.ordsIter = ordsIter;
this.ord = ordsIter.next();
return this;
}
@Override
public boolean hasNext() {
return ord != 0;
}
@Override
public short next() {
short value = values[ord];
ord = ordsIter.next();
return value;
}
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final short[] values; private final short[] values;
@ -532,7 +397,7 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericShort(getShortValues()); return new ScriptDocValues.NumericLong(getLongValues());
} }
@Override @Override
@ -547,22 +412,7 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.ShortBased(getShortValues()); return new StringValues.LongBased(getLongValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues(values, set);
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
@ -570,80 +420,11 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
return new LongValues(values, set); return new LongValues(values, set);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values, set); return new DoubleValues(values, set);
} }
static class ShortValues implements org.elasticsearch.index.fielddata.ShortValues {
private final short[] values;
private final FixedBitSet set;
private final ShortArrayRef arrayScratch = new ShortArrayRef(new short[1], 1);
private final Iter.Single iter = new Iter.Single();
ShortValues(short[] values, FixedBitSet set) {
this.values = values;
this.set = set;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return set.get(docId);
}
@Override
public short getValue(int docId) {
return values[docId];
}
@Override
public short getValueMissing(int docId, short missingValue) {
if (set.get(docId)) {
return values[docId];
} else {
return missingValue;
}
}
@Override
public ShortArrayRef getValues(int docId) {
if (set.get(docId)) {
arrayScratch.values[0] = values[docId];
return arrayScratch;
} else {
return ShortArrayRef.EMPTY;
}
}
@Override
public Iter getIter(int docId) {
if (set.get(docId)) {
return iter.reset(values[docId]);
} else {
return Iter.Empty.INSTANCE;
}
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
if (set.get(docId)) {
proc.onValue(docId, values[docId]);
}
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final short[] values; private final short[] values;
@ -807,7 +588,7 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public ScriptDocValues getScriptValues() { public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericShort(getShortValues()); return new ScriptDocValues.NumericLong(getLongValues());
} }
@Override @Override
@ -822,22 +603,7 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
@Override @Override
public StringValues getStringValues() { public StringValues getStringValues() {
return new StringValues.ShortBased(getShortValues()); return new StringValues.LongBased(getLongValues());
}
@Override
public ByteValues getByteValues() {
return new ByteValues.LongBased(getLongValues());
}
@Override
public ShortValues getShortValues() {
return new ShortValues(values);
}
@Override
public IntValues getIntValues() {
return new IntValues.LongBased(getLongValues());
} }
@Override @Override
@ -845,64 +611,12 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
return new LongValues(values); return new LongValues(values);
} }
@Override
public FloatValues getFloatValues() {
return new FloatValues.DoubleBased(getDoubleValues());
}
@Override @Override
public DoubleValues getDoubleValues() { public DoubleValues getDoubleValues() {
return new DoubleValues(values); return new DoubleValues(values);
} }
static class ShortValues implements org.elasticsearch.index.fielddata.ShortValues {
private final short[] values;
private final ShortArrayRef arrayScratch = new ShortArrayRef(new short[1], 1);
private final Iter.Single iter = new Iter.Single();
ShortValues(short[] values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return true;
}
@Override
public short getValue(int docId) {
return values[docId];
}
@Override
public short getValueMissing(int docId, short missingValue) {
return values[docId];
}
@Override
public ShortArrayRef getValues(int docId) {
arrayScratch.values[0] = values[docId];
return arrayScratch;
}
@Override
public Iter getIter(int docId) {
return iter.reset(values[docId]);
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onValue(docId, values[docId]);
}
}
static class LongValues implements org.elasticsearch.index.fielddata.LongValues { static class LongValues implements org.elasticsearch.index.fielddata.LongValues {
private final short[] values; private final short[] values;

View File

@ -131,7 +131,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
if (inclusiveLowerPoint > inclusiveUpperPoint) if (inclusiveLowerPoint > inclusiveUpperPoint)
return null; return null;
final ByteValues values = indexFieldData.load(ctx).getByteValues(); final LongValues values = indexFieldData.load(ctx).getLongValues();
return new MatchDocIdSet(ctx.reader().maxDoc(), acceptedDocs) { return new MatchDocIdSet(ctx.reader().maxDoc(), acceptedDocs) {
@Override @Override
@ -141,9 +141,9 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
@Override @Override
protected boolean matchDoc(int doc) { protected boolean matchDoc(int doc) {
ByteValues.Iter iter = values.getIter(doc); LongValues.Iter iter = values.getIter(doc);
while (iter.hasNext()) { while (iter.hasNext()) {
byte value = iter.next(); long value = iter.next();
if (value >= inclusiveLowerPoint && value <= inclusiveUpperPoint) { if (value >= inclusiveLowerPoint && value <= inclusiveUpperPoint) {
return true; return true;
} }
@ -181,7 +181,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
if (inclusiveLowerPoint > inclusiveUpperPoint) if (inclusiveLowerPoint > inclusiveUpperPoint)
return null; return null;
final ShortValues values = indexFieldData.load(ctx).getShortValues(); final LongValues values = indexFieldData.load(ctx).getLongValues();
return new MatchDocIdSet(ctx.reader().maxDoc(), acceptedDocs) { return new MatchDocIdSet(ctx.reader().maxDoc(), acceptedDocs) {
@Override @Override
@ -191,9 +191,9 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
@Override @Override
protected boolean matchDoc(int doc) { protected boolean matchDoc(int doc) {
ShortValues.Iter iter = values.getIter(doc); LongValues.Iter iter = values.getIter(doc);
while (iter.hasNext()) { while (iter.hasNext()) {
short value = iter.next(); long value = iter.next();
if (value >= inclusiveLowerPoint && value <= inclusiveUpperPoint) { if (value >= inclusiveLowerPoint && value <= inclusiveUpperPoint) {
return true; return true;
} }
@ -230,7 +230,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
if (inclusiveLowerPoint > inclusiveUpperPoint) if (inclusiveLowerPoint > inclusiveUpperPoint)
return null; return null;
final IntValues values = indexFieldData.load(ctx).getIntValues(); final LongValues values = indexFieldData.load(ctx).getLongValues();
return new MatchDocIdSet(ctx.reader().maxDoc(), acceptedDocs) { return new MatchDocIdSet(ctx.reader().maxDoc(), acceptedDocs) {
@Override @Override
@ -240,9 +240,9 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
@Override @Override
protected boolean matchDoc(int doc) { protected boolean matchDoc(int doc) {
IntValues.Iter iter = values.getIter(doc); LongValues.Iter iter = values.getIter(doc);
while (iter.hasNext()) { while (iter.hasNext()) {
int value = iter.next(); long value = iter.next();
if (value >= inclusiveLowerPoint && value <= inclusiveUpperPoint) { if (value >= inclusiveLowerPoint && value <= inclusiveUpperPoint) {
return true; return true;
} }
@ -332,7 +332,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
if (inclusiveLowerPoint > inclusiveUpperPoint) if (inclusiveLowerPoint > inclusiveUpperPoint)
return null; return null;
final FloatValues values = indexFieldData.load(ctx).getFloatValues(); final DoubleValues values = indexFieldData.load(ctx).getDoubleValues();
return new MatchDocIdSet(ctx.reader().maxDoc(), acceptedDocs) { return new MatchDocIdSet(ctx.reader().maxDoc(), acceptedDocs) {
@Override @Override
@ -342,9 +342,9 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
@Override @Override
protected boolean matchDoc(int doc) { protected boolean matchDoc(int doc) {
FloatValues.Iter iter = values.getIter(doc); DoubleValues.Iter iter = values.getIter(doc);
while (iter.hasNext()) { while (iter.hasNext()) {
float value = iter.next(); double value = iter.next();
if (value >= inclusiveLowerPoint && value <= inclusiveUpperPoint) { if (value >= inclusiveLowerPoint && value <= inclusiveUpperPoint) {
return true; return true;
} }

View File

@ -267,148 +267,4 @@ public abstract class AbstractFieldDataTests {
assertThat(MISSING, sameInstance(expected.get(idx++))); assertThat(MISSING, sameInstance(expected.get(idx++)));
} }
} }
public static class ByteValuesVerifierProc implements ByteValues.ValueInDocProc {
private static final Byte MISSING = new Byte((byte) 0);
private final int docId;
private final List<Byte> expected = new ArrayList<Byte>();
private int idx;
ByteValuesVerifierProc(int docId) {
this.docId = docId;
}
public ByteValuesVerifierProc addExpected(byte value) {
expected.add(value);
return this;
}
public ByteValuesVerifierProc addMissing() {
expected.add(MISSING);
return this;
}
@Override
public void onValue(int docId, byte value) {
assertThat(docId, equalTo(this.docId));
assertThat(value, equalTo(expected.get(idx++)));
}
@Override
public void onMissing(int docId) {
assertThat(docId, equalTo(this.docId));
assertThat(MISSING, sameInstance(expected.get(idx++)));
}
}
public static class ShortValuesVerifierProc implements ShortValues.ValueInDocProc {
private static final Short MISSING = new Short((byte) 0);
private final int docId;
private final List<Short> expected = new ArrayList<Short>();
private int idx;
ShortValuesVerifierProc(int docId) {
this.docId = docId;
}
public ShortValuesVerifierProc addExpected(short value) {
expected.add(value);
return this;
}
public ShortValuesVerifierProc addMissing() {
expected.add(MISSING);
return this;
}
@Override
public void onValue(int docId, short value) {
assertThat(docId, equalTo(this.docId));
assertThat(value, equalTo(expected.get(idx++)));
}
@Override
public void onMissing(int docId) {
assertThat(docId, equalTo(this.docId));
assertThat(MISSING, sameInstance(expected.get(idx++)));
}
}
public static class IntValuesVerifierProc implements IntValues.ValueInDocProc {
private static final Integer MISSING = new Integer(0);
private final int docId;
private final List<Integer> expected = new ArrayList<Integer>();
private int idx;
IntValuesVerifierProc(int docId) {
this.docId = docId;
}
public IntValuesVerifierProc addExpected(int value) {
expected.add(value);
return this;
}
public IntValuesVerifierProc addMissing() {
expected.add(MISSING);
return this;
}
@Override
public void onValue(int docId, int value) {
assertThat(docId, equalTo(this.docId));
assertThat(value, equalTo(expected.get(idx++)));
}
@Override
public void onMissing(int docId) {
assertThat(docId, equalTo(this.docId));
assertThat(MISSING, sameInstance(expected.get(idx++)));
}
}
public static class FloatValuesVerifierProc implements FloatValues.ValueInDocProc {
private static final Float MISSING = new Float(0);
private final int docId;
private final List<Float> expected = new ArrayList<Float>();
private int idx;
FloatValuesVerifierProc(int docId) {
this.docId = docId;
}
public FloatValuesVerifierProc addExpected(float value) {
expected.add(value);
return this;
}
public FloatValuesVerifierProc addMissing() {
expected.add(MISSING);
return this;
}
@Override
public void onValue(int docId, float value) {
assertThat(docId, equalTo(this.docId));
assertThat(value, equalTo(expected.get(idx++)));
}
@Override
public void onMissing(int docId) {
assertThat(docId, equalTo(this.docId));
assertThat(MISSING, sameInstance(expected.get(idx++)));
}
}
} }

View File

@ -140,194 +140,6 @@ public abstract class NumericFieldDataTests extends StringFieldDataTests {
doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addExpected(1d)); doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addExpected(1d));
doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addExpected(3d)); doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addExpected(3d));
ByteValues byteValues = fieldData.getByteValues();
assertThat(byteValues.isMultiValued(), equalTo(false));
assertThat(byteValues.hasValue(0), equalTo(true));
assertThat(byteValues.hasValue(1), equalTo(true));
assertThat(byteValues.hasValue(2), equalTo(true));
assertThat(byteValues.getValue(0), equalTo((byte) 2));
assertThat(byteValues.getValue(1), equalTo((byte) 1));
assertThat(byteValues.getValue(2), equalTo((byte) 3));
assertThat(byteValues.getValueMissing(0, (byte) -1), equalTo((byte) 2));
assertThat(byteValues.getValueMissing(1, (byte) -1), equalTo((byte) 1));
assertThat(byteValues.getValueMissing(2, (byte) -1), equalTo((byte) 3));
ByteArrayRef byteArrayRef = byteValues.getValues(0);
assertThat(byteArrayRef.size(), equalTo(1));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 2));
byteArrayRef = byteValues.getValues(1);
assertThat(byteArrayRef.size(), equalTo(1));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 1));
byteArrayRef = byteValues.getValues(2);
assertThat(byteArrayRef.size(), equalTo(1));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 3));
ByteValues.Iter byteValuesIter = byteValues.getIter(0);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 2));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(1);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 1));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(2);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 3));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValues.forEachValueInDoc(0, new ByteValuesVerifierProc(0).addExpected((byte) 2));
byteValues.forEachValueInDoc(1, new ByteValuesVerifierProc(1).addExpected((byte) 1));
byteValues.forEachValueInDoc(2, new ByteValuesVerifierProc(2).addExpected((byte) 3));
ShortValues shortValues = fieldData.getShortValues();
assertThat(shortValues.isMultiValued(), equalTo(false));
assertThat(shortValues.hasValue(0), equalTo(true));
assertThat(shortValues.hasValue(1), equalTo(true));
assertThat(shortValues.hasValue(2), equalTo(true));
assertThat(shortValues.getValue(0), equalTo((short) 2));
assertThat(shortValues.getValue(1), equalTo((short) 1));
assertThat(shortValues.getValue(2), equalTo((short) 3));
assertThat(shortValues.getValueMissing(0, (short) -1), equalTo((short) 2));
assertThat(shortValues.getValueMissing(1, (short) -1), equalTo((short) 1));
assertThat(shortValues.getValueMissing(2, (short) -1), equalTo((short) 3));
ShortArrayRef shortArrayRef = shortValues.getValues(0);
assertThat(shortArrayRef.size(), equalTo(1));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 2));
shortArrayRef = shortValues.getValues(1);
assertThat(shortArrayRef.size(), equalTo(1));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 1));
shortArrayRef = shortValues.getValues(2);
assertThat(shortArrayRef.size(), equalTo(1));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 3));
ShortValues.Iter shortValuesIter = shortValues.getIter(0);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 2));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(1);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 1));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(2);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 3));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValues.forEachValueInDoc(0, new ShortValuesVerifierProc(0).addExpected((short) 2));
shortValues.forEachValueInDoc(1, new ShortValuesVerifierProc(1).addExpected((short) 1));
shortValues.forEachValueInDoc(2, new ShortValuesVerifierProc(2).addExpected((short) 3));
IntValues intValues = fieldData.getIntValues();
assertThat(intValues.isMultiValued(), equalTo(false));
assertThat(intValues.hasValue(0), equalTo(true));
assertThat(intValues.hasValue(1), equalTo(true));
assertThat(intValues.hasValue(2), equalTo(true));
assertThat(intValues.getValue(0), equalTo(2));
assertThat(intValues.getValue(1), equalTo(1));
assertThat(intValues.getValue(2), equalTo(3));
assertThat(intValues.getValueMissing(0, -1), equalTo(2));
assertThat(intValues.getValueMissing(1, -1), equalTo(1));
assertThat(intValues.getValueMissing(2, -1), equalTo(3));
IntArrayRef intArrayRef = intValues.getValues(0);
assertThat(intArrayRef.size(), equalTo(1));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(2));
intArrayRef = intValues.getValues(1);
assertThat(intArrayRef.size(), equalTo(1));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(1));
intArrayRef = intValues.getValues(2);
assertThat(intArrayRef.size(), equalTo(1));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(3));
IntValues.Iter intValuesIter = intValues.getIter(0);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(2));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(1);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(1));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(2);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(3));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValues.forEachValueInDoc(0, new IntValuesVerifierProc(0).addExpected(2));
intValues.forEachValueInDoc(1, new IntValuesVerifierProc(1).addExpected(1));
intValues.forEachValueInDoc(2, new IntValuesVerifierProc(2).addExpected(3));
FloatValues floatValues = fieldData.getFloatValues();
assertThat(floatValues.isMultiValued(), equalTo(false));
assertThat(floatValues.hasValue(0), equalTo(true));
assertThat(floatValues.hasValue(1), equalTo(true));
assertThat(floatValues.hasValue(2), equalTo(true));
assertThat(floatValues.getValue(0), equalTo(2f));
assertThat(floatValues.getValue(1), equalTo(1f));
assertThat(floatValues.getValue(2), equalTo(3f));
assertThat(floatValues.getValueMissing(0, -1), equalTo(2f));
assertThat(floatValues.getValueMissing(1, -1), equalTo(1f));
assertThat(floatValues.getValueMissing(2, -1), equalTo(3f));
FloatArrayRef floatArrayRef = floatValues.getValues(0);
assertThat(floatArrayRef.size(), equalTo(1));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(2f));
floatArrayRef = floatValues.getValues(1);
assertThat(floatArrayRef.size(), equalTo(1));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(1f));
floatArrayRef = floatValues.getValues(2);
assertThat(floatArrayRef.size(), equalTo(1));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(3f));
FloatValues.Iter floatValuesIter = floatValues.getIter(0);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(2f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(1);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(1f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(2);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(3f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValues.forEachValueInDoc(0, new FloatValuesVerifierProc(0).addExpected(2f));
floatValues.forEachValueInDoc(1, new FloatValuesVerifierProc(1).addExpected(1f));
floatValues.forEachValueInDoc(2, new FloatValuesVerifierProc(2).addExpected(3f));
IndexSearcher searcher = new IndexSearcher(readerContext.reader()); IndexSearcher searcher = new IndexSearcher(readerContext.reader());
TopFieldDocs topDocs; TopFieldDocs topDocs;
@ -440,178 +252,6 @@ public abstract class NumericFieldDataTests extends StringFieldDataTests {
doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addMissing()); doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addMissing());
doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addExpected(3d)); doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addExpected(3d));
ByteValues byteValues = fieldData.getByteValues();
assertThat(byteValues.isMultiValued(), equalTo(false));
assertThat(byteValues.hasValue(0), equalTo(true));
assertThat(byteValues.hasValue(1), equalTo(false));
assertThat(byteValues.hasValue(2), equalTo(true));
assertThat(byteValues.getValue(0), equalTo((byte) 2));
assertThat(byteValues.getValue(2), equalTo((byte) 3));
assertThat(byteValues.getValueMissing(0, (byte) -1), equalTo((byte) 2));
assertThat(byteValues.getValueMissing(1, (byte) -1), equalTo((byte) -1));
assertThat(byteValues.getValueMissing(2, (byte) -1), equalTo((byte) 3));
ByteArrayRef byteArrayRef = byteValues.getValues(0);
assertThat(byteArrayRef.size(), equalTo(1));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 2));
byteArrayRef = byteValues.getValues(1);
assertThat(byteArrayRef.size(), equalTo(0));
byteArrayRef = byteValues.getValues(2);
assertThat(byteArrayRef.size(), equalTo(1));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 3));
ByteValues.Iter byteValuesIter = byteValues.getIter(0);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 2));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(1);
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(2);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 3));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValues.forEachValueInDoc(0, new ByteValuesVerifierProc(0).addExpected((byte) 2));
byteValues.forEachValueInDoc(1, new ByteValuesVerifierProc(1).addMissing());
byteValues.forEachValueInDoc(2, new ByteValuesVerifierProc(2).addExpected((byte) 3));
ShortValues shortValues = fieldData.getShortValues();
assertThat(shortValues.isMultiValued(), equalTo(false));
assertThat(shortValues.hasValue(0), equalTo(true));
assertThat(shortValues.hasValue(1), equalTo(false));
assertThat(shortValues.hasValue(2), equalTo(true));
assertThat(shortValues.getValue(0), equalTo((short) 2));
assertThat(shortValues.getValue(2), equalTo((short) 3));
assertThat(shortValues.getValueMissing(0, (short) -1), equalTo((short) 2));
assertThat(shortValues.getValueMissing(1, (short) -1), equalTo((short) -1));
assertThat(shortValues.getValueMissing(2, (short) -1), equalTo((short) 3));
ShortArrayRef shortArrayRef = shortValues.getValues(0);
assertThat(shortArrayRef.size(), equalTo(1));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 2));
shortArrayRef = shortValues.getValues(1);
assertThat(shortArrayRef.size(), equalTo(0));
shortArrayRef = shortValues.getValues(2);
assertThat(shortArrayRef.size(), equalTo(1));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 3));
ShortValues.Iter shortValuesIter = shortValues.getIter(0);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 2));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(1);
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(2);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 3));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValues.forEachValueInDoc(0, new ShortValuesVerifierProc(0).addExpected((short) 2));
shortValues.forEachValueInDoc(1, new ShortValuesVerifierProc(1).addMissing());
shortValues.forEachValueInDoc(2, new ShortValuesVerifierProc(2).addExpected((short) 3));
IntValues intValues = fieldData.getIntValues();
assertThat(intValues.isMultiValued(), equalTo(false));
assertThat(intValues.hasValue(0), equalTo(true));
assertThat(intValues.hasValue(1), equalTo(false));
assertThat(intValues.hasValue(2), equalTo(true));
assertThat(intValues.getValue(0), equalTo(2));
assertThat(intValues.getValue(2), equalTo(3));
assertThat(intValues.getValueMissing(0, -1), equalTo(2));
assertThat(intValues.getValueMissing(1, -1), equalTo(-1));
assertThat(intValues.getValueMissing(2, -1), equalTo(3));
IntArrayRef intArrayRef = intValues.getValues(0);
assertThat(intArrayRef.size(), equalTo(1));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(2));
intArrayRef = intValues.getValues(1);
assertThat(intArrayRef.size(), equalTo(0));
intArrayRef = intValues.getValues(2);
assertThat(intArrayRef.size(), equalTo(1));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(3));
IntValues.Iter intValuesIter = intValues.getIter(0);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(2));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(1);
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(2);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(3));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValues.forEachValueInDoc(0, new IntValuesVerifierProc(0).addExpected(2));
intValues.forEachValueInDoc(1, new IntValuesVerifierProc(1).addMissing());
intValues.forEachValueInDoc(2, new IntValuesVerifierProc(2).addExpected(3));
FloatValues floatValues = fieldData.getFloatValues();
assertThat(floatValues.isMultiValued(), equalTo(false));
assertThat(floatValues.hasValue(0), equalTo(true));
assertThat(floatValues.hasValue(1), equalTo(false));
assertThat(floatValues.hasValue(2), equalTo(true));
assertThat(floatValues.getValue(0), equalTo(2f));
assertThat(floatValues.getValue(2), equalTo(3f));
assertThat(floatValues.getValueMissing(0, -1), equalTo(2f));
assertThat(floatValues.getValueMissing(1, -1), equalTo(-1f));
assertThat(floatValues.getValueMissing(2, -1), equalTo(3f));
FloatArrayRef floatArrayRef = floatValues.getValues(0);
assertThat(floatArrayRef.size(), equalTo(1));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(2f));
floatArrayRef = floatValues.getValues(1);
assertThat(floatArrayRef.size(), equalTo(0));
floatArrayRef = floatValues.getValues(2);
assertThat(floatArrayRef.size(), equalTo(1));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(3f));
FloatValues.Iter floatValuesIter = floatValues.getIter(0);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(2f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(1);
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(2);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(3f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValues.forEachValueInDoc(0, new FloatValuesVerifierProc(0).addExpected(2f));
floatValues.forEachValueInDoc(1, new FloatValuesVerifierProc(1).addMissing());
floatValues.forEachValueInDoc(2, new FloatValuesVerifierProc(2).addExpected(3f));
IndexSearcher searcher = new IndexSearcher(readerContext.reader()); IndexSearcher searcher = new IndexSearcher(readerContext.reader());
TopFieldDocs topDocs; TopFieldDocs topDocs;
@ -765,206 +405,6 @@ public abstract class NumericFieldDataTests extends StringFieldDataTests {
doubleValues.forEachValueInDoc(0, new DoubleValuesVerifierProc(0).addExpected(2d).addExpected(4d)); doubleValues.forEachValueInDoc(0, new DoubleValuesVerifierProc(0).addExpected(2d).addExpected(4d));
doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addExpected(1d)); doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addExpected(1d));
doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addExpected(3d)); doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addExpected(3d));
ByteValues byteValues = fieldData.getByteValues();
assertThat(byteValues.isMultiValued(), equalTo(true));
assertThat(byteValues.hasValue(0), equalTo(true));
assertThat(byteValues.hasValue(1), equalTo(true));
assertThat(byteValues.hasValue(2), equalTo(true));
assertThat(byteValues.getValue(0), equalTo((byte) 2));
assertThat(byteValues.getValue(1), equalTo((byte) 1));
assertThat(byteValues.getValue(2), equalTo((byte) 3));
assertThat(byteValues.getValueMissing(0, (byte) -1), equalTo((byte) 2));
assertThat(byteValues.getValueMissing(1, (byte) -1), equalTo((byte) 1));
assertThat(byteValues.getValueMissing(2, (byte) -1), equalTo((byte) 3));
ByteArrayRef byteArrayRef = byteValues.getValues(0);
assertThat(byteArrayRef.size(), equalTo(2));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 2));
assertThat(byteArrayRef.values[byteArrayRef.start + 1], equalTo((byte) 4));
byteArrayRef = byteValues.getValues(1);
assertThat(byteArrayRef.size(), equalTo(1));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 1));
byteArrayRef = byteValues.getValues(2);
assertThat(byteArrayRef.size(), equalTo(1));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 3));
ByteValues.Iter byteValuesIter = byteValues.getIter(0);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 2));
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 4));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(1);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 1));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(2);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 3));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValues.forEachValueInDoc(0, new ByteValuesVerifierProc(0).addExpected((byte) 2).addExpected((byte) 4));
byteValues.forEachValueInDoc(1, new ByteValuesVerifierProc(1).addExpected((byte) 1));
byteValues.forEachValueInDoc(2, new ByteValuesVerifierProc(2).addExpected((byte) 3));
ShortValues shortValues = fieldData.getShortValues();
assertThat(shortValues.isMultiValued(), equalTo(true));
assertThat(shortValues.hasValue(0), equalTo(true));
assertThat(shortValues.hasValue(1), equalTo(true));
assertThat(shortValues.hasValue(2), equalTo(true));
assertThat(shortValues.getValue(0), equalTo((short) 2));
assertThat(shortValues.getValue(1), equalTo((short) 1));
assertThat(shortValues.getValue(2), equalTo((short) 3));
assertThat(shortValues.getValueMissing(0, (short) -1), equalTo((short) 2));
assertThat(shortValues.getValueMissing(1, (short) -1), equalTo((short) 1));
assertThat(shortValues.getValueMissing(2, (short) -1), equalTo((short) 3));
ShortArrayRef shortArrayRef = shortValues.getValues(0);
assertThat(shortArrayRef.size(), equalTo(2));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 2));
assertThat(shortArrayRef.values[shortArrayRef.start + 1], equalTo((short) 4));
shortArrayRef = shortValues.getValues(1);
assertThat(shortArrayRef.size(), equalTo(1));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 1));
shortArrayRef = shortValues.getValues(2);
assertThat(shortArrayRef.size(), equalTo(1));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 3));
ShortValues.Iter shortValuesIter = shortValues.getIter(0);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 2));
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 4));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(1);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 1));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(2);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 3));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValues.forEachValueInDoc(0, new ShortValuesVerifierProc(0).addExpected((short) 2).addExpected((short) 4));
shortValues.forEachValueInDoc(1, new ShortValuesVerifierProc(1).addExpected((short) 1));
shortValues.forEachValueInDoc(2, new ShortValuesVerifierProc(2).addExpected((short) 3));
IntValues intValues = fieldData.getIntValues();
assertThat(intValues.isMultiValued(), equalTo(true));
assertThat(intValues.hasValue(0), equalTo(true));
assertThat(intValues.hasValue(1), equalTo(true));
assertThat(intValues.hasValue(2), equalTo(true));
assertThat(intValues.getValue(0), equalTo(2));
assertThat(intValues.getValue(1), equalTo(1));
assertThat(intValues.getValue(2), equalTo(3));
assertThat(intValues.getValueMissing(0, -1), equalTo(2));
assertThat(intValues.getValueMissing(1, -1), equalTo(1));
assertThat(intValues.getValueMissing(2, -1), equalTo(3));
IntArrayRef intArrayRef = intValues.getValues(0);
assertThat(intArrayRef.size(), equalTo(2));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(2));
assertThat(intArrayRef.values[intArrayRef.start + 1], equalTo(4));
intArrayRef = intValues.getValues(1);
assertThat(intArrayRef.size(), equalTo(1));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(1));
intArrayRef = intValues.getValues(2);
assertThat(intArrayRef.size(), equalTo(1));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(3));
IntValues.Iter intValuesIter = intValues.getIter(0);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(2));
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(4));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(1);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(1));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(2);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(3));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValues.forEachValueInDoc(0, new IntValuesVerifierProc(0).addExpected(2).addExpected(4));
intValues.forEachValueInDoc(1, new IntValuesVerifierProc(1).addExpected(1));
intValues.forEachValueInDoc(2, new IntValuesVerifierProc(2).addExpected(3));
FloatValues floatValues = fieldData.getFloatValues();
assertThat(floatValues.isMultiValued(), equalTo(true));
assertThat(floatValues.hasValue(0), equalTo(true));
assertThat(floatValues.hasValue(1), equalTo(true));
assertThat(floatValues.hasValue(2), equalTo(true));
assertThat(floatValues.getValue(0), equalTo(2f));
assertThat(floatValues.getValue(1), equalTo(1f));
assertThat(floatValues.getValue(2), equalTo(3f));
assertThat(floatValues.getValueMissing(0, -1), equalTo(2f));
assertThat(floatValues.getValueMissing(1, -1), equalTo(1f));
assertThat(floatValues.getValueMissing(2, -1), equalTo(3f));
FloatArrayRef floatArrayRef = floatValues.getValues(0);
assertThat(floatArrayRef.size(), equalTo(2));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(2f));
assertThat(floatArrayRef.values[floatArrayRef.start + 1], equalTo(4f));
floatArrayRef = floatValues.getValues(1);
assertThat(floatArrayRef.size(), equalTo(1));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(1f));
floatArrayRef = floatValues.getValues(2);
assertThat(floatArrayRef.size(), equalTo(1));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(3f));
FloatValues.Iter floatValuesIter = floatValues.getIter(0);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(2f));
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(4f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(1);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(1f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(2);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(3f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValues.forEachValueInDoc(0, new FloatValuesVerifierProc(0).addExpected(2f).addExpected(4f));
floatValues.forEachValueInDoc(1, new FloatValuesVerifierProc(1).addExpected(1f));
floatValues.forEachValueInDoc(2, new FloatValuesVerifierProc(2).addExpected(3f));
} }
@Test @Test
@ -1066,190 +506,6 @@ public abstract class NumericFieldDataTests extends StringFieldDataTests {
doubleValues.forEachValueInDoc(0, new DoubleValuesVerifierProc(0).addExpected(2d).addExpected(4d)); doubleValues.forEachValueInDoc(0, new DoubleValuesVerifierProc(0).addExpected(2d).addExpected(4d));
doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addMissing()); doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addMissing());
doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addExpected(3d)); doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addExpected(3d));
ByteValues byteValues = fieldData.getByteValues();
assertThat(byteValues.isMultiValued(), equalTo(true));
assertThat(byteValues.hasValue(0), equalTo(true));
assertThat(byteValues.hasValue(1), equalTo(false));
assertThat(byteValues.hasValue(2), equalTo(true));
assertThat(byteValues.getValue(0), equalTo((byte) 2));
assertThat(byteValues.getValue(2), equalTo((byte) 3));
assertThat(byteValues.getValueMissing(0, (byte) -1), equalTo((byte) 2));
assertThat(byteValues.getValueMissing(1, (byte) -1), equalTo((byte) -1));
assertThat(byteValues.getValueMissing(2, (byte) -1), equalTo((byte) 3));
ByteArrayRef byteArrayRef = byteValues.getValues(0);
assertThat(byteArrayRef.size(), equalTo(2));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 2));
assertThat(byteArrayRef.values[byteArrayRef.start + 1], equalTo((byte) 4));
byteArrayRef = byteValues.getValues(1);
assertThat(byteArrayRef.size(), equalTo(0));
byteArrayRef = byteValues.getValues(2);
assertThat(byteArrayRef.size(), equalTo(1));
assertThat(byteArrayRef.values[byteArrayRef.start], equalTo((byte) 3));
ByteValues.Iter byteValuesIter = byteValues.getIter(0);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 2));
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 4));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(1);
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(2);
assertThat(byteValuesIter.hasNext(), equalTo(true));
assertThat(byteValuesIter.next(), equalTo((byte) 3));
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValues.forEachValueInDoc(0, new ByteValuesVerifierProc(0).addExpected((byte) 2).addExpected((byte) 4));
byteValues.forEachValueInDoc(1, new ByteValuesVerifierProc(1).addMissing());
byteValues.forEachValueInDoc(2, new ByteValuesVerifierProc(2).addExpected((byte) 3));
ShortValues shortValues = fieldData.getShortValues();
assertThat(shortValues.isMultiValued(), equalTo(true));
assertThat(shortValues.hasValue(0), equalTo(true));
assertThat(shortValues.hasValue(1), equalTo(false));
assertThat(shortValues.hasValue(2), equalTo(true));
assertThat(shortValues.getValue(0), equalTo((short) 2));
assertThat(shortValues.getValue(2), equalTo((short) 3));
assertThat(shortValues.getValueMissing(0, (short) -1), equalTo((short) 2));
assertThat(shortValues.getValueMissing(1, (short) -1), equalTo((short) -1));
assertThat(shortValues.getValueMissing(2, (short) -1), equalTo((short) 3));
ShortArrayRef shortArrayRef = shortValues.getValues(0);
assertThat(shortArrayRef.size(), equalTo(2));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 2));
assertThat(shortArrayRef.values[shortArrayRef.start + 1], equalTo((short) 4));
shortArrayRef = shortValues.getValues(1);
assertThat(shortArrayRef.size(), equalTo(0));
shortArrayRef = shortValues.getValues(2);
assertThat(shortArrayRef.size(), equalTo(1));
assertThat(shortArrayRef.values[shortArrayRef.start], equalTo((short) 3));
ShortValues.Iter shortValuesIter = shortValues.getIter(0);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 2));
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 4));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(1);
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(2);
assertThat(shortValuesIter.hasNext(), equalTo(true));
assertThat(shortValuesIter.next(), equalTo((short) 3));
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValues.forEachValueInDoc(0, new ShortValuesVerifierProc(0).addExpected((short) 2).addExpected((short) 4));
shortValues.forEachValueInDoc(1, new ShortValuesVerifierProc(1).addMissing());
shortValues.forEachValueInDoc(2, new ShortValuesVerifierProc(2).addExpected((short) 3));
IntValues intValues = fieldData.getIntValues();
assertThat(intValues.isMultiValued(), equalTo(true));
assertThat(intValues.hasValue(0), equalTo(true));
assertThat(intValues.hasValue(1), equalTo(false));
assertThat(intValues.hasValue(2), equalTo(true));
assertThat(intValues.getValue(0), equalTo(2));
assertThat(intValues.getValue(2), equalTo(3));
assertThat(intValues.getValueMissing(0, -1), equalTo(2));
assertThat(intValues.getValueMissing(1, -1), equalTo(-1));
assertThat(intValues.getValueMissing(2, -1), equalTo(3));
IntArrayRef intArrayRef = intValues.getValues(0);
assertThat(intArrayRef.size(), equalTo(2));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(2));
assertThat(intArrayRef.values[intArrayRef.start + 1], equalTo(4));
intArrayRef = intValues.getValues(1);
assertThat(intArrayRef.size(), equalTo(0));
intArrayRef = intValues.getValues(2);
assertThat(intArrayRef.size(), equalTo(1));
assertThat(intArrayRef.values[intArrayRef.start], equalTo(3));
IntValues.Iter intValuesIter = intValues.getIter(0);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(2));
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(4));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(1);
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(2);
assertThat(intValuesIter.hasNext(), equalTo(true));
assertThat(intValuesIter.next(), equalTo(3));
assertThat(intValuesIter.hasNext(), equalTo(false));
intValues.forEachValueInDoc(0, new IntValuesVerifierProc(0).addExpected(2).addExpected(4));
intValues.forEachValueInDoc(1, new IntValuesVerifierProc(1).addMissing());
intValues.forEachValueInDoc(2, new IntValuesVerifierProc(2).addExpected(3));
FloatValues floatValues = fieldData.getFloatValues();
assertThat(floatValues.isMultiValued(), equalTo(true));
assertThat(floatValues.hasValue(0), equalTo(true));
assertThat(floatValues.hasValue(1), equalTo(false));
assertThat(floatValues.hasValue(2), equalTo(true));
assertThat(floatValues.getValue(0), equalTo(2f));
assertThat(floatValues.getValue(2), equalTo(3f));
assertThat(floatValues.getValueMissing(0, -1), equalTo(2f));
assertThat(floatValues.getValueMissing(1, -1), equalTo(-1f));
assertThat(floatValues.getValueMissing(2, -1), equalTo(3f));
FloatArrayRef floatArrayRef = floatValues.getValues(0);
assertThat(floatArrayRef.size(), equalTo(2));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(2f));
assertThat(floatArrayRef.values[floatArrayRef.start + 1], equalTo(4f));
floatArrayRef = floatValues.getValues(1);
assertThat(floatArrayRef.size(), equalTo(0));
floatArrayRef = floatValues.getValues(2);
assertThat(floatArrayRef.size(), equalTo(1));
assertThat(floatArrayRef.values[floatArrayRef.start], equalTo(3f));
FloatValues.Iter floatValuesIter = floatValues.getIter(0);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(2f));
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(4f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(1);
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(2);
assertThat(floatValuesIter.hasNext(), equalTo(true));
assertThat(floatValuesIter.next(), equalTo(3f));
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValues.forEachValueInDoc(0, new FloatValuesVerifierProc(0).addExpected(2f).addExpected(4f));
floatValues.forEachValueInDoc(1, new FloatValuesVerifierProc(1).addMissing());
floatValues.forEachValueInDoc(2, new FloatValuesVerifierProc(2).addExpected(3f));
} }
@Test @Test
@ -1331,150 +587,6 @@ public abstract class NumericFieldDataTests extends StringFieldDataTests {
doubleValues.forEachValueInDoc(0, new DoubleValuesVerifierProc(0).addMissing()); doubleValues.forEachValueInDoc(0, new DoubleValuesVerifierProc(0).addMissing());
doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addMissing()); doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addMissing());
doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addMissing()); doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addMissing());
// byte values
ByteValues byteValues = fieldData.getByteValues();
assertThat(byteValues.isMultiValued(), equalTo(false));
assertThat(byteValues.hasValue(0), equalTo(false));
assertThat(byteValues.hasValue(1), equalTo(false));
assertThat(byteValues.hasValue(2), equalTo(false));
assertThat(byteValues.getValueMissing(0, (byte) -1), equalTo((byte) -1));
assertThat(byteValues.getValueMissing(1, (byte) -1), equalTo((byte) -1));
assertThat(byteValues.getValueMissing(2, (byte) -1), equalTo((byte) -1));
ByteArrayRef byteArrayRef = byteValues.getValues(0);
assertThat(byteArrayRef.size(), equalTo(0));
byteArrayRef = byteValues.getValues(1);
assertThat(byteArrayRef.size(), equalTo(0));
byteArrayRef = byteValues.getValues(2);
assertThat(byteArrayRef.size(), equalTo(0));
ByteValues.Iter byteValuesIter = byteValues.getIter(0);
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(1);
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(2);
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValues.forEachValueInDoc(0, new ByteValuesVerifierProc(0).addMissing());
byteValues.forEachValueInDoc(1, new ByteValuesVerifierProc(1).addMissing());
byteValues.forEachValueInDoc(2, new ByteValuesVerifierProc(2).addMissing());
// short values
ShortValues shortValues = fieldData.getShortValues();
assertThat(shortValues.isMultiValued(), equalTo(false));
assertThat(shortValues.hasValue(0), equalTo(false));
assertThat(shortValues.hasValue(1), equalTo(false));
assertThat(shortValues.hasValue(2), equalTo(false));
assertThat(shortValues.getValueMissing(0, (short) -1), equalTo((short) -1));
assertThat(shortValues.getValueMissing(1, (short) -1), equalTo((short) -1));
assertThat(shortValues.getValueMissing(2, (short) -1), equalTo((short) -1));
ShortArrayRef shortArrayRef = shortValues.getValues(0);
assertThat(shortArrayRef.size(), equalTo(0));
shortArrayRef = shortValues.getValues(1);
assertThat(shortArrayRef.size(), equalTo(0));
shortArrayRef = shortValues.getValues(2);
assertThat(shortArrayRef.size(), equalTo(0));
ShortValues.Iter shortValuesIter = shortValues.getIter(0);
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(1);
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(2);
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValues.forEachValueInDoc(0, new ShortValuesVerifierProc(0).addMissing());
shortValues.forEachValueInDoc(1, new ShortValuesVerifierProc(1).addMissing());
shortValues.forEachValueInDoc(2, new ShortValuesVerifierProc(2).addMissing());
// int values
IntValues intValues = fieldData.getIntValues();
assertThat(intValues.isMultiValued(), equalTo(false));
assertThat(intValues.hasValue(0), equalTo(false));
assertThat(intValues.hasValue(1), equalTo(false));
assertThat(intValues.hasValue(2), equalTo(false));
assertThat(intValues.getValueMissing(0, -1), equalTo(-1));
assertThat(intValues.getValueMissing(1, -1), equalTo(-1));
assertThat(intValues.getValueMissing(2, -1), equalTo(-1));
IntArrayRef intArrayRef = intValues.getValues(0);
assertThat(intArrayRef.size(), equalTo(0));
intArrayRef = intValues.getValues(1);
assertThat(intArrayRef.size(), equalTo(0));
intArrayRef = intValues.getValues(2);
assertThat(intArrayRef.size(), equalTo(0));
IntValues.Iter intValuesIter = intValues.getIter(0);
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(1);
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(2);
assertThat(intValuesIter.hasNext(), equalTo(false));
intValues.forEachValueInDoc(0, new IntValuesVerifierProc(0).addMissing());
intValues.forEachValueInDoc(1, new IntValuesVerifierProc(1).addMissing());
intValues.forEachValueInDoc(2, new IntValuesVerifierProc(2).addMissing());
// float
FloatValues floatValues = fieldData.getFloatValues();
assertThat(floatValues.isMultiValued(), equalTo(false));
assertThat(floatValues.hasValue(0), equalTo(false));
assertThat(floatValues.hasValue(1), equalTo(false));
assertThat(floatValues.hasValue(2), equalTo(false));
assertThat(floatValues.getValueMissing(0, -1), equalTo(-1f));
assertThat(floatValues.getValueMissing(1, -1), equalTo(-1f));
assertThat(floatValues.getValueMissing(2, -1), equalTo(-1f));
FloatArrayRef floatArrayRef = floatValues.getValues(0);
assertThat(floatArrayRef.size(), equalTo(0));
floatArrayRef = floatValues.getValues(1);
assertThat(floatArrayRef.size(), equalTo(0));
floatArrayRef = floatValues.getValues(2);
assertThat(floatArrayRef.size(), equalTo(0));
FloatValues.Iter floatValuesIter = floatValues.getIter(0);
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(1);
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(2);
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValues.forEachValueInDoc(0, new FloatValuesVerifierProc(0).addMissing());
floatValues.forEachValueInDoc(1, new FloatValuesVerifierProc(1).addMissing());
floatValues.forEachValueInDoc(2, new FloatValuesVerifierProc(2).addMissing());
} }
protected void fillAllMissing() throws Exception { protected void fillAllMissing() throws Exception {