add more scanning options on the field data cache

This commit is contained in:
kimchy 2010-12-30 17:08:32 +02:00
parent 6c8b06c967
commit 019359a896
12 changed files with 147 additions and 1 deletions

View File

@ -107,6 +107,11 @@ public abstract class FloatFieldData extends NumericFieldData<FloatDocFieldData>
void onValue(float value);
}
public abstract void forEachValueInDoc(int docId, ValueInDocProc proc);
public static interface ValueInDocProc {
void onValue(int docId, float value);
}
public static FloatFieldData load(IndexReader reader, String field) throws IOException {
return FieldDataLoader.load(reader, field, new FloatTypeLoader());

View File

@ -95,6 +95,16 @@ public class MultiValueFloatFieldData extends FloatFieldData {
}
}
@Override public void forEachValueInDoc(int docId, ValueInDocProc proc) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {
return;
}
for (int docOrder : docOrders) {
proc.onValue(docId, values[docOrder]);
}
}
@Override public double[] doubleValues(int docId) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {

View File

@ -77,6 +77,14 @@ public class SingleValueFloatFieldData extends FloatFieldData {
proc.onValue(docId, values[loc]);
}
@Override public void forEachValueInDoc(int docId, ValueInDocProc proc) {
int loc = ordinals[docId];
if (loc == 0) {
return;
}
proc.onValue(docId, values[loc]);
}
@Override public double[] doubleValues(int docId) {
int loc = ordinals[docId];
if (loc == 0) {

View File

@ -107,6 +107,11 @@ public abstract class IntFieldData extends NumericFieldData<IntDocFieldData> {
void onValue(int value);
}
public abstract void forEachValueInDoc(int docId, ValueInDocProc proc);
public static interface ValueInDocProc {
void onValue(int docId, int value);
}
public static IntFieldData load(IndexReader reader, String field) throws IOException {
return FieldDataLoader.load(reader, field, new IntTypeLoader());

View File

@ -95,6 +95,16 @@ public class MultiValueIntFieldData extends IntFieldData {
}
}
@Override public void forEachValueInDoc(int docId, ValueInDocProc proc) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {
return;
}
for (int docOrder : docOrders) {
proc.onValue(docId, values[docOrder]);
}
}
@Override public double[] doubleValues(int docId) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {

View File

@ -77,6 +77,14 @@ public class SingleValueIntFieldData extends IntFieldData {
proc.onValue(docId, values[loc]);
}
@Override public void forEachValueInDoc(int docId, ValueInDocProc proc) {
int loc = ordinals[docId];
if (loc == 0) {
return;
}
proc.onValue(docId, values[loc]);
}
@Override public double[] doubleValues(int docId) {
int loc = ordinals[docId];
if (loc == 0) {

View File

@ -40,7 +40,7 @@ public abstract class LongFieldData extends NumericFieldData<LongDocFieldData> {
static final long[] EMPTY_LONG_ARRAY = new long[0];
static final MutableDateTime[] EMPTY_DATETIME_ARRAY = new MutableDateTime[0];
private ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime>> dateTimeCache = new ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime>>() {
ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime>> dateTimeCache = new ThreadLocal<ThreadLocals.CleanableValue<MutableDateTime>>() {
@Override protected ThreadLocals.CleanableValue<MutableDateTime> initialValue() {
return new ThreadLocals.CleanableValue<MutableDateTime>(new MutableDateTime(DateTimeZone.UTC));
}
@ -67,6 +67,10 @@ public abstract class LongFieldData extends NumericFieldData<LongDocFieldData> {
return dateTime;
}
public void date(int docId, MutableDateTime dateTime) {
dateTime.setMillis(value(docId));
}
public abstract MutableDateTime[] dates(int docId);
@Override public LongDocFieldData docFieldData(int docId) {
@ -125,6 +129,19 @@ public abstract class LongFieldData extends NumericFieldData<LongDocFieldData> {
void onValue(long value);
}
public abstract void forEachValueInDoc(int docId, ValueInDocProc proc);
public static interface ValueInDocProc {
void onValue(int docId, long value);
}
public abstract void forEachValueInDoc(int docId, DateValueInDocProc proc);
public abstract void forEachValueInDoc(int docId, MutableDateTime dateTime, DateValueInDocProc proc);
public static interface DateValueInDocProc {
void onValue(int docId, MutableDateTime dateTime);
}
public static LongFieldData load(IndexReader reader, String field) throws IOException {
return FieldDataLoader.load(reader, field, new LongTypeLoader());

View File

@ -111,6 +111,39 @@ public class MultiValueLongFieldData extends LongFieldData {
}
}
@Override public void forEachValueInDoc(int docId, ValueInDocProc proc) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {
return;
}
for (int docOrder : docOrders) {
proc.onValue(docId, values[docOrder]);
}
}
@Override public void forEachValueInDoc(int docId, DateValueInDocProc proc) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {
return;
}
MutableDateTime dateTime = dateTimeCache.get().get();
for (int docOrder : docOrders) {
dateTime.setMillis(values[docOrder]);
proc.onValue(docId, dateTime);
}
}
@Override public void forEachValueInDoc(int docId, MutableDateTime dateTime, DateValueInDocProc proc) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {
return;
}
for (int docOrder : docOrders) {
dateTime.setMillis(values[docOrder]);
proc.onValue(docId, dateTime);
}
}
@Override public MutableDateTime[] dates(int docId) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {

View File

@ -87,6 +87,33 @@ public class SingleValueLongFieldData extends LongFieldData {
proc.onValue(docId, values[loc]);
}
@Override public void forEachValueInDoc(int docId, ValueInDocProc proc) {
int loc = ordinals[docId];
if (loc == 0) {
return;
}
proc.onValue(docId, values[loc]);
}
@Override public void forEachValueInDoc(int docId, DateValueInDocProc proc) {
int loc = ordinals[docId];
if (loc == 0) {
return;
}
MutableDateTime dateTime = dateTimeCache.get().get();
dateTime.setMillis(values[loc]);
proc.onValue(docId, dateTime);
}
@Override public void forEachValueInDoc(int docId, MutableDateTime dateTime, DateValueInDocProc proc) {
int loc = ordinals[docId];
if (loc == 0) {
return;
}
dateTime.setMillis(values[loc]);
proc.onValue(docId, dateTime);
}
@Override public MutableDateTime[] dates(int docId) {
int loc = ordinals[docId];
if (loc == 0) {

View File

@ -95,6 +95,16 @@ public class MultiValueShortFieldData extends ShortFieldData {
}
}
@Override public void forEachValueInDoc(int docId, ValueInDocProc proc) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {
return;
}
for (int docOrder : docOrders) {
proc.onValue(docId, values[docOrder]);
}
}
@Override public double[] doubleValues(int docId) {
int[] docOrders = ordinals[docId];
if (docOrders == null) {

View File

@ -107,6 +107,11 @@ public abstract class ShortFieldData extends NumericFieldData<ShortDocFieldData>
void onValue(short value);
}
public abstract void forEachValueInDoc(int docId, ValueInDocProc proc);
public static interface ValueInDocProc {
void onValue(int docId, short value);
}
public static ShortFieldData load(IndexReader reader, String field) throws IOException {
return FieldDataLoader.load(reader, field, new ShortTypeLoader());

View File

@ -77,6 +77,14 @@ public class SingleValueShortFieldData extends ShortFieldData {
proc.onValue(docId, values[loc]);
}
@Override public void forEachValueInDoc(int docId, ValueInDocProc proc) {
int loc = ordinals[docId];
if (loc == 0) {
return;
}
proc.onValue(docId, values[loc]);
}
@Override public short value(int docId) {
return values[ordinals[docId]];
}