improve iteration on multi valued field data by breaking fast

This commit is contained in:
Shay Banon 2012-06-07 14:59:20 +02:00
parent 8df0e35532
commit 2d46b41021
7 changed files with 339 additions and 397 deletions

View File

@ -87,16 +87,15 @@ public class MultiValueByteFieldData extends ByteFieldData {
@Override @Override
public void forEachValueInDoc(int docId, StringValueInDocProc proc) { public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, Byte.toString(values[loc])); }
break;
} }
} proc.onValue(docId, Byte.toString(values[loc]));
if (!found) {
proc.onMissing(docId);
} }
} }
@ -104,9 +103,10 @@ public class MultiValueByteFieldData extends ByteFieldData {
public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, values[loc]); break;
} }
proc.onValue(docId, values[loc]);
} }
} }
@ -114,69 +114,66 @@ public class MultiValueByteFieldData extends ByteFieldData {
public void forEachValueInDoc(int docId, LongValueInDocProc proc) { public void forEachValueInDoc(int docId, LongValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, values[loc]); break;
} }
proc.onValue(docId, values[loc]);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) { public void forEachValueInDoc(int docId, ValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onOrdinal(docId, 0);
proc.onOrdinal(docId, loc); }
break;
} }
} proc.onOrdinal(docId, loc);
if (!found) {
proc.onOrdinal(docId, 0);
} }
} }
@ -184,9 +181,10 @@ public class MultiValueByteFieldData extends ByteFieldData {
public double[] doubleValues(int docId) { public double[] doubleValues(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
@ -197,12 +195,8 @@ public class MultiValueByteFieldData extends ByteFieldData {
} else { } else {
doubles = new double[length]; doubles = new double[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { doubles[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
doubles[i++] = values[loc];
}
} }
return doubles; return doubles;
} }
@ -222,9 +216,10 @@ public class MultiValueByteFieldData extends ByteFieldData {
public byte[] values(int docId) { public byte[] values(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return EMPTY_BYTE_ARRAY; return EMPTY_BYTE_ARRAY;
@ -235,12 +230,8 @@ public class MultiValueByteFieldData extends ByteFieldData {
} else { } else {
bytes = new byte[length]; bytes = new byte[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { bytes[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
bytes[i++] = values[loc];
}
} }
return bytes; return bytes;
} }

View File

@ -75,16 +75,15 @@ public class MultiValueDoubleFieldData extends DoubleFieldData {
@Override @Override
public void forEachValueInDoc(int docId, StringValueInDocProc proc) { public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, Double.toString(values[loc])); }
break;
} }
} proc.onValue(docId, Double.toString(values[loc]));
if (!found) {
proc.onMissing(docId);
} }
} }
@ -92,9 +91,10 @@ public class MultiValueDoubleFieldData extends DoubleFieldData {
public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, values[loc]); break;
} }
proc.onValue(docId, values[loc]);
} }
} }
@ -102,69 +102,66 @@ public class MultiValueDoubleFieldData extends DoubleFieldData {
public void forEachValueInDoc(int docId, LongValueInDocProc proc) { public void forEachValueInDoc(int docId, LongValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, (long) values[loc]); break;
} }
proc.onValue(docId, (long) values[loc]);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, (long) values[loc]); }
break;
} }
} proc.onValue(docId, (long) values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) { public void forEachValueInDoc(int docId, ValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onOrdinal(docId, 0);
proc.onOrdinal(docId, loc); }
break;
} }
} proc.onOrdinal(docId, loc);
if (!found) {
proc.onOrdinal(docId, 0);
} }
} }
@ -188,9 +185,10 @@ public class MultiValueDoubleFieldData extends DoubleFieldData {
public double[] values(int docId) { public double[] values(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return EMPTY_DOUBLE_ARRAY; return EMPTY_DOUBLE_ARRAY;
@ -201,12 +199,8 @@ public class MultiValueDoubleFieldData extends DoubleFieldData {
} else { } else {
doubles = new double[length]; doubles = new double[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { doubles[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
doubles[i++] = values[loc];
}
} }
return doubles; return doubles;
} }

View File

@ -87,16 +87,15 @@ public class MultiValueFloatFieldData extends FloatFieldData {
@Override @Override
public void forEachValueInDoc(int docId, StringValueInDocProc proc) { public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, Float.toString(values[loc])); }
break;
} }
} proc.onValue(docId, Double.toString(values[loc]));
if (!found) {
proc.onMissing(docId);
} }
} }
@ -104,9 +103,10 @@ public class MultiValueFloatFieldData extends FloatFieldData {
public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, values[loc]); break;
} }
proc.onValue(docId, values[loc]);
} }
} }
@ -114,69 +114,66 @@ public class MultiValueFloatFieldData extends FloatFieldData {
public void forEachValueInDoc(int docId, LongValueInDocProc proc) { public void forEachValueInDoc(int docId, LongValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, (long) values[loc]); break;
} }
proc.onValue(docId, (long) values[loc]);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, (long) values[loc]); }
break;
} }
} proc.onValue(docId, (long) values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) { public void forEachValueInDoc(int docId, ValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onOrdinal(docId, 0);
proc.onOrdinal(docId, loc); }
break;
} }
} proc.onOrdinal(docId, loc);
if (!found) {
proc.onOrdinal(docId, 0);
} }
} }
@ -184,9 +181,10 @@ public class MultiValueFloatFieldData extends FloatFieldData {
public double[] doubleValues(int docId) { public double[] doubleValues(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
@ -197,12 +195,8 @@ public class MultiValueFloatFieldData extends FloatFieldData {
} else { } else {
doubles = new double[length]; doubles = new double[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { doubles[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
doubles[i++] = values[loc];
}
} }
return doubles; return doubles;
} }
@ -222,9 +216,10 @@ public class MultiValueFloatFieldData extends FloatFieldData {
public float[] values(int docId) { public float[] values(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return EMPTY_FLOAT_ARRAY; return EMPTY_FLOAT_ARRAY;
@ -235,12 +230,8 @@ public class MultiValueFloatFieldData extends FloatFieldData {
} else { } else {
floats = new float[length]; floats = new float[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { floats[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
floats[i++] = values[loc];
}
} }
return floats; return floats;
} }

View File

@ -87,16 +87,15 @@ public class MultiValueIntFieldData extends IntFieldData {
@Override @Override
public void forEachValueInDoc(int docId, StringValueInDocProc proc) { public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, Integer.toString(values[loc])); }
break;
} }
} proc.onValue(docId, Integer.toString(values[loc]));
if (!found) {
proc.onMissing(docId);
} }
} }
@ -104,9 +103,10 @@ public class MultiValueIntFieldData extends IntFieldData {
public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, values[loc]); break;
} }
proc.onValue(docId, values[loc]);
} }
} }
@ -114,69 +114,66 @@ public class MultiValueIntFieldData extends IntFieldData {
public void forEachValueInDoc(int docId, LongValueInDocProc proc) { public void forEachValueInDoc(int docId, LongValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, values[loc]); break;
} }
proc.onValue(docId, values[loc]);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) { public void forEachValueInDoc(int docId, ValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onOrdinal(docId, 0);
proc.onOrdinal(docId, loc); }
break;
} }
} proc.onOrdinal(docId, loc);
if (!found) {
proc.onOrdinal(docId, 0);
} }
} }
@ -184,9 +181,10 @@ public class MultiValueIntFieldData extends IntFieldData {
public double[] doubleValues(int docId) { public double[] doubleValues(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
@ -197,12 +195,8 @@ public class MultiValueIntFieldData extends IntFieldData {
} else { } else {
doubles = new double[length]; doubles = new double[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { doubles[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
doubles[i++] = values[loc];
}
} }
return doubles; return doubles;
} }
@ -222,9 +216,10 @@ public class MultiValueIntFieldData extends IntFieldData {
public int[] values(int docId) { public int[] values(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return EMPTY_INT_ARRAY; return EMPTY_INT_ARRAY;
@ -235,12 +230,8 @@ public class MultiValueIntFieldData extends IntFieldData {
} else { } else {
ints = new int[length]; ints = new int[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { ints[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
ints[i++] = values[loc];
}
} }
return ints; return ints;
} }

View File

@ -104,16 +104,15 @@ public class MultiValueLongFieldData extends LongFieldData {
@Override @Override
public void forEachValueInDoc(int docId, StringValueInDocProc proc) { public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, Long.toString(values[loc])); }
break;
} }
} proc.onValue(docId, Long.toString(values[loc]));
if (!found) {
proc.onMissing(docId);
} }
} }
@ -121,9 +120,10 @@ public class MultiValueLongFieldData extends LongFieldData {
public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, values[loc]); break;
} }
proc.onValue(docId, values[loc]);
} }
} }
@ -131,69 +131,66 @@ public class MultiValueLongFieldData extends LongFieldData {
public void forEachValueInDoc(int docId, LongValueInDocProc proc) { public void forEachValueInDoc(int docId, LongValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, values[loc]); break;
} }
proc.onValue(docId, values[loc]);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onOrdinal(docId, 0);
proc.onOrdinal(docId, loc); }
break;
} }
} proc.onOrdinal(docId, loc);
if (!found) {
proc.onOrdinal(docId, 0);
} }
} }
@Override @Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) { public void forEachValueInDoc(int docId, ValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@ -202,10 +199,11 @@ public class MultiValueLongFieldData extends LongFieldData {
MutableDateTime dateTime = dateTimeCache.get().get(); MutableDateTime dateTime = dateTimeCache.get().get();
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
dateTime.setMillis(values[loc]); break;
proc.onValue(docId, dateTime);
} }
dateTime.setMillis(values[loc]);
proc.onValue(docId, dateTime);
} }
} }
@ -213,10 +211,11 @@ public class MultiValueLongFieldData extends LongFieldData {
public void forEachValueInDoc(int docId, MutableDateTime dateTime, DateValueInDocProc proc) { public void forEachValueInDoc(int docId, MutableDateTime dateTime, DateValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
dateTime.setMillis(values[loc]); break;
proc.onValue(docId, dateTime);
} }
dateTime.setMillis(values[loc]);
proc.onValue(docId, dateTime);
} }
} }
@ -254,9 +253,10 @@ public class MultiValueLongFieldData extends LongFieldData {
public double[] doubleValues(int docId) { public double[] doubleValues(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
@ -267,12 +267,8 @@ public class MultiValueLongFieldData extends LongFieldData {
} else { } else {
doubles = new double[length]; doubles = new double[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { doubles[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
doubles[i++] = values[loc];
}
} }
return doubles; return doubles;
} }
@ -292,9 +288,10 @@ public class MultiValueLongFieldData extends LongFieldData {
public long[] values(int docId) { public long[] values(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return EMPTY_LONG_ARRAY; return EMPTY_LONG_ARRAY;
@ -305,12 +302,8 @@ public class MultiValueLongFieldData extends LongFieldData {
} else { } else {
longs = new long[length]; longs = new long[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { longs[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
longs[i++] = values[loc];
}
} }
return longs; return longs;
} }

View File

@ -76,31 +76,29 @@ public class MultiValueStringFieldData extends StringFieldData {
@Override @Override
public void forEachValueInDoc(int docId, StringValueInDocProc proc) { public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, values[loc]); }
break;
} }
} proc.onValue(docId, values[loc]);
if (!found) {
proc.onMissing(docId);
} }
} }
@Override @Override
public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onOrdinal(docId, 0);
proc.onOrdinal(docId, loc); }
break;
} }
} proc.onOrdinal(docId, loc);
if (!found) {
proc.onOrdinal(docId, 0);
} }
} }
@ -119,9 +117,10 @@ public class MultiValueStringFieldData extends StringFieldData {
public String[] values(int docId) { public String[] values(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return Strings.EMPTY_ARRAY; return Strings.EMPTY_ARRAY;
@ -132,12 +131,8 @@ public class MultiValueStringFieldData extends StringFieldData {
} else { } else {
strings = new String[length]; strings = new String[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { strings[i] = values[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
strings[i++] = values[loc];
}
} }
return strings; return strings;
} }

View File

@ -102,16 +102,15 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
@Override @Override
public void forEachValueInDoc(int docId, StringValueInDocProc proc) { public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onMissing(docId);
proc.onValue(docId, GeoHashUtils.encode(lat[loc], lon[loc])); }
break;
} }
} proc.onValue(docId, GeoHashUtils.encode(lat[loc], lon[loc]));
if (!found) {
proc.onMissing(docId);
} }
} }
@ -119,24 +118,24 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
public void forEachValueInDoc(int docId, ValueInDocProc proc) { public void forEachValueInDoc(int docId, ValueInDocProc proc) {
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
int loc = ordinal[docId]; int loc = ordinal[docId];
if (loc != 0) { if (loc == 0) {
proc.onValue(docId, lat[loc], lon[loc]); break;
} }
proc.onValue(docId, lat[loc], lon[loc]);
} }
} }
@Override @Override
public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) {
boolean found = false; for (int i = 0; i < ordinals.length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; if (loc == 0) {
if (loc != 0) { if (i == 0) {
found = true; proc.onOrdinal(docId, 0);
proc.onOrdinal(docId, loc); }
break;
} }
} proc.onOrdinal(docId, loc);
if (!found) {
proc.onOrdinal(docId, 0);
} }
} }
@ -157,9 +156,10 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
public GeoPoint[] values(int docId) { public GeoPoint[] values(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return EMPTY_ARRAY; return EMPTY_ARRAY;
@ -167,21 +167,15 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
GeoPoint[] points; GeoPoint[] points;
if (length < VALUE_CACHE_SIZE) { if (length < VALUE_CACHE_SIZE) {
points = valuesArrayCache.get().get()[length]; points = valuesArrayCache.get().get()[length];
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; points[i].latlon(lat[loc], lon[loc]);
if (loc != 0) {
points[i++].latlon(lat[loc], lon[loc]);
}
} }
} else { } else {
points = new GeoPoint[length]; points = new GeoPoint[length];
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { int loc = ordinals[i][docId];
int loc = ordinal[docId]; points[i] = new GeoPoint(lat[loc], lon[loc]);
if (loc != 0) {
points[i++] = new GeoPoint(lat[loc], lon[loc]);
}
} }
} }
return points; return points;
@ -213,9 +207,10 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
public double[] latValues(int docId) { public double[] latValues(int docId) {
int length = 0; int length = 0;
for (int[] ordinal : ordinals) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) { if (ordinal[docId] == 0) {
length++; break;
} }
length++;
} }
if (length == 0) { if (length == 0) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
@ -226,12 +221,8 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} else { } else {
doubles = new double[length]; doubles = new double[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { doubles[i] = lat[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
doubles[i++] = lat[loc];
}
} }
return doubles; return doubles;
} }
@ -253,12 +244,8 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} else { } else {
doubles = new double[length]; doubles = new double[length];
} }
int i = 0; for (int i = 0; i < length; i++) {
for (int[] ordinal : ordinals) { doubles[i] = lon[ordinals[i][docId]];
int loc = ordinal[docId];
if (loc != 0) {
doubles[i++] = lon[loc];
}
} }
return doubles; return doubles;
} }