Fix computation of the missing ord (leftover of the ordinals change).

This commit is contained in:
Adrien Grand 2014-04-29 16:20:38 +02:00
parent fe89b8735a
commit 6ec01c13e5
1 changed files with 16 additions and 17 deletions

View File

@ -279,15 +279,20 @@ public final class BytesRefOrdValComparator extends NestedWrappableComparator<By
// find where to insert an ord in the current terms index
private long ordInCurrentReader(BytesValues.WithOrdinals termsIndex, BytesRef value) {
final long docOrd = binarySearch(termsIndex, value);
final long ord;
if (docOrd >= 0) {
if (value == null) {
ord = Ordinals.MISSING_ORDINAL << 2;
} else {
final long docOrd = binarySearch(termsIndex, value);
if (docOrd >= Ordinals.MIN_ORDINAL) {
// value exists in the current segment
ord = docOrd << 2;
} else {
// value doesn't exist, use the ord between the previous and the next term
ord = ((-2 - docOrd) << 2) + 2;
}
}
assert (ord & 1) == 0;
return ord;
}
@ -296,12 +301,8 @@ public final class BytesRefOrdValComparator extends NestedWrappableComparator<By
public FieldComparator<BytesRef> setNextReader(AtomicReaderContext context) throws IOException {
termsIndex = indexFieldData.load(context).getBytesValues(false);
assert termsIndex.ordinals() != null;
if (missingValue == null) {
missingOrd = Ordinals.MISSING_ORDINAL;
} else {
missingOrd = ordInCurrentReader(termsIndex, missingValue);
assert consistentInsertedOrd(termsIndex, missingOrd, missingValue);
}
FieldComparator<BytesRef> perSegComp = null;
assert termsIndex.ordinals() != null;
if (termsIndex.isMultiValued()) {
@ -332,14 +333,12 @@ public final class BytesRefOrdValComparator extends NestedWrappableComparator<By
bottomSlot = bottom;
final BytesRef bottomValue = values[bottomSlot];
if (bottomValue == null) {
bottomOrd = Ordinals.MISSING_ORDINAL;
} else if (currentReaderGen == readerGen[bottomSlot]) {
if (currentReaderGen == readerGen[bottomSlot]) {
bottomOrd = ords[bottomSlot];
} else {
// insert an ord
bottomOrd = ordInCurrentReader(termsIndex, bottomValue);
if (bottomOrd == missingOrd) {
if (bottomOrd == missingOrd && bottomValue != null) {
// bottomValue and missingValue and in-between the same field data values -> tie-break
// this is why we multiply ords by 4
assert missingValue != null;