in lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90DocValuesProducer.java [1530:1728]
public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException {
SortedSetEntry entry = sortedSets.get(field.number);
if (entry.singleValueEntry != null) {
return DocValues.singleton(getSorted(entry.singleValueEntry));
}
// Specialize the common case for ordinals: single block of packed integers.
SortedNumericEntry ordsEntry = entry.ordsEntry;
if (ordsEntry.blockShift < 0 && ordsEntry.bitsPerValue > 0) {
if (ordsEntry.gcd != 1 || ordsEntry.minValue != 0 || ordsEntry.table != null) {
throw new IllegalStateException("Ordinals shouldn't use GCD, offset or table compression");
}
final RandomAccessInput addressesInput =
data.randomAccessSlice(ordsEntry.addressesOffset, ordsEntry.addressesLength);
// Prefetch the first page of data. Following pages are expected to get prefetched through
// read-ahead.
if (addressesInput.length() > 0) {
addressesInput.prefetch(0, 1);
}
final LongValues addresses =
DirectMonotonicReader.getInstance(ordsEntry.addressesMeta, addressesInput);
final RandomAccessInput slice =
data.randomAccessSlice(ordsEntry.valuesOffset, ordsEntry.valuesLength);
// Prefetch the first page of data. Following pages are expected to get prefetched through
// read-ahead.
if (slice.length() > 0) {
slice.prefetch(0, 1);
}
final LongValues values = DirectReader.getInstance(slice, ordsEntry.bitsPerValue);
if (ordsEntry.docsWithFieldOffset == -1) { // dense
return new BaseSortedSetDocValues(entry, data) {
private final int maxDoc = Lucene90DocValuesProducer.this.maxDoc;
private int doc = -1;
private long curr;
private int count;
@Override
public long nextOrd() throws IOException {
return values.get(curr++);
}
@Override
public boolean advanceExact(int target) throws IOException {
curr = addresses.get(target);
long end = addresses.get(target + 1L);
count = (int) (end - curr);
doc = target;
return true;
}
@Override
public int docValueCount() {
return count;
}
@Override
public int docID() {
return doc;
}
@Override
public int nextDoc() throws IOException {
return advance(doc + 1);
}
@Override
public int advance(int target) throws IOException {
if (target >= maxDoc) {
return doc = NO_MORE_DOCS;
}
curr = addresses.get(target);
long end = addresses.get(target + 1L);
count = (int) (end - curr);
return doc = target;
}
@Override
public long cost() {
return maxDoc;
}
};
} else if (ordsEntry.docsWithFieldOffset >= 0) { // sparse but non-empty
final IndexedDISI disi =
new IndexedDISI(
data,
ordsEntry.docsWithFieldOffset,
ordsEntry.docsWithFieldLength,
ordsEntry.jumpTableEntryCount,
ordsEntry.denseRankPower,
ordsEntry.numValues);
return new BaseSortedSetDocValues(entry, data) {
boolean set;
long curr;
int count;
@Override
public long nextOrd() throws IOException {
set();
return values.get(curr++);
}
@Override
public boolean advanceExact(int target) throws IOException {
set = false;
return disi.advanceExact(target);
}
@Override
public int docValueCount() {
set();
return count;
}
@Override
public int docID() {
return disi.docID();
}
@Override
public int nextDoc() throws IOException {
set = false;
return disi.nextDoc();
}
@Override
public int advance(int target) throws IOException {
set = false;
return disi.advance(target);
}
@Override
public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
set = false;
disi.intoBitSet(upTo, bitSet, offset);
}
@Override
public long cost() {
return disi.cost();
}
private void set() {
if (set == false) {
final int index = disi.index();
curr = addresses.get(index);
long end = addresses.get(index + 1L);
count = (int) (end - curr);
set = true;
}
}
};
}
}
final SortedNumericDocValues ords = getSortedNumeric(ordsEntry);
return new BaseSortedSetDocValues(entry, data) {
@Override
public long nextOrd() throws IOException {
return ords.nextValue();
}
@Override
public int docValueCount() {
return ords.docValueCount();
}
@Override
public boolean advanceExact(int target) throws IOException {
return ords.advanceExact(target);
}
@Override
public int docID() {
return ords.docID();
}
@Override
public int nextDoc() throws IOException {
return ords.nextDoc();
}
@Override
public int advance(int target) throws IOException {
return ords.advance(target);
}
@Override
public long cost() {
return ords.cost();
}
};
}