LUCENE-5834: Empty sorted set and numeric doc values are now singletons.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1612251 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrien Grand 2014-07-21 11:30:58 +00:00
parent 4bd3a57899
commit 052b84db2d
4 changed files with 13 additions and 51 deletions

View File

@ -171,6 +171,9 @@ Optimizations
warning in javadocs. It is almost always a better idea to implement
slicing on your own! (Uwe Schindler, Robert Muir)
* LUCENE-5834: Empty sorted set and numeric doc values are now singletons.
(Adrien Grand)
Bug Fixes
* LUCENE-5796: Fixes the Scorer.getChildren() method for two combinations

View File

@ -77,66 +77,25 @@ public final class DocValues {
}
};
}
/**
/**
* An empty SortedNumericDocValues which returns zero values for every document
*/
public static final SortedNumericDocValues emptySortedNumeric() {
return new SortedNumericDocValues() {
@Override
public void setDocument(int doc) {}
@Override
public long valueAt(int index) {
throw new IndexOutOfBoundsException();
}
@Override
public int count() {
return 0;
}
};
public static final SortedNumericDocValues emptySortedNumeric(int maxDoc) {
return singleton(emptyNumeric(), new Bits.MatchNoBits(maxDoc));
}
/**
* An empty SortedDocValues which returns {@link SortedSetDocValues#NO_MORE_ORDS} for every document
*/
public static final SortedSetDocValues emptySortedSet() {
return new RandomAccessOrds() {
@Override
public long nextOrd() {
return NO_MORE_ORDS;
}
@Override
public void setDocument(int docID) {}
@Override
public BytesRef lookupOrd(long ord) {
throw new IndexOutOfBoundsException();
}
@Override
public long getValueCount() {
return 0;
}
@Override
public long ordAt(int index) {
throw new IndexOutOfBoundsException();
}
@Override
public int cardinality() {
return 0;
}
};
public static final RandomAccessOrds emptySortedSet() {
return singleton(emptySorted());
}
/**
* Returns a multi-valued view over the provided SortedDocValues
*/
public static SortedSetDocValues singleton(SortedDocValues dv) {
public static RandomAccessOrds singleton(SortedDocValues dv) {
return new SingletonSortedSetDocValues(dv);
}
@ -286,7 +245,7 @@ public final class DocValues {
if (dv == null) {
NumericDocValues single = in.getNumericDocValues(field);
if (single == null) {
return emptySortedNumeric();
return emptySortedNumeric(in.maxDoc());
}
Bits bits = in.getDocsWithField(field);
return singleton(single, bits);

View File

@ -253,7 +253,7 @@ public class MultiDocValues {
AtomicReaderContext context = leaves.get(i);
SortedNumericDocValues v = context.reader().getSortedNumericDocValues(field);
if (v == null) {
v = DocValues.emptySortedNumeric();
v = DocValues.emptySortedNumeric(context.reader().maxDoc());
} else {
anyReal = true;
}

View File

@ -214,7 +214,7 @@ final class SegmentMerger {
for (AtomicReader reader : mergeState.readers) {
SortedNumericDocValues values = reader.getSortedNumericDocValues(field.name);
if (values == null) {
values = DocValues.emptySortedNumeric();
values = DocValues.emptySortedNumeric(reader.maxDoc());
}
toMerge.add(values);
}