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

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