LUCENE-10188: Give SortedSetDocValues a docValueCount() (#663)

Co-authored-by: vlc刘诚 <chengliu@trip.com>
This commit is contained in:
spike.liu 2022-05-02 22:41:12 +08:00 committed by GitHub
parent 5f48469837
commit d9d2cb6f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 70 additions and 1 deletions

View File

@ -1603,6 +1603,11 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
}
return ords.get(start++);
}
@Override
public long docValueCount() {
return end - start;
}
};
} else {
// sparse
@ -1663,6 +1668,11 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
return ords.get(start++);
}
}
@Override
public long docValueCount() {
return end - start;
}
};
}
}

View File

@ -727,6 +727,11 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
}
}
@Override
public long docValueCount() {
return currentOrds.length;
}
@Override
public BytesRef lookupOrd(long ord) throws IOException {
if (ord < 0 || ord >= field.numValues) {

View File

@ -947,6 +947,11 @@ public abstract class DocValuesConsumer implements Closeable {
return currentSub.map.get(subOrd);
}
@Override
public long docValueCount() {
return currentSub.values.docValueCount();
}
@Override
public long cost() {
return finalCost;

View File

@ -1448,6 +1448,11 @@ final class Lucene90DocValuesProducer extends DocValuesProducer {
return ords.nextValue();
}
@Override
public long docValueCount() {
return count;
}
@Override
public boolean advanceExact(int target) throws IOException {
set = false;

View File

@ -43,6 +43,11 @@ public class FilterSortedSetDocValues extends SortedSetDocValues {
return in.nextOrd();
}
@Override
public long docValueCount() {
return in.docValueCount();
}
@Override
public BytesRef lookupOrd(long ord) throws IOException {
return in.lookupOrd(ord);

View File

@ -927,6 +927,11 @@ public class MultiDocValues {
}
}
@Override
public long docValueCount() {
return currentValues.docValueCount();
}
@Override
public BytesRef lookupOrd(long ord) throws IOException {
int subIndex = mapping.getFirstSegmentNumber(ord);

View File

@ -57,6 +57,11 @@ final class SingletonSortedSetDocValues extends SortedSetDocValues {
return v;
}
@Override
public long docValueCount() {
return 1;
}
@Override
public int nextDoc() throws IOException {
int docID = in.nextDoc();

View File

@ -44,7 +44,11 @@ public abstract class SortedSetDocValues extends DocValuesIterator {
*/
public abstract long nextOrd() throws IOException;
// TODO: should we have a docValueCount, like SortedNumeric?
/**
* Retrieves the number of values for the current document. This must always be greater than zero.
* It is illegal to call this method after {@link #advanceExact(int)} returned {@code false}.
*/
public abstract long docValueCount();
/**
* Retrieves the value for the specified ordinal. The returned {@link BytesRef} may be re-used

View File

@ -310,6 +310,11 @@ class SortedSetDocValuesWriter extends DocValuesWriter<SortedSetDocValues> {
}
}
@Override
public long docValueCount() {
return ordCount;
}
@Override
public long cost() {
return docsWithField.cost();
@ -391,6 +396,11 @@ class SortedSetDocValuesWriter extends DocValuesWriter<SortedSetDocValues> {
}
}
@Override
public long docValueCount() {
return ords.ords.size();
}
@Override
public long cost() {
return in.cost();

View File

@ -93,6 +93,11 @@ interface GenericTermsCollector extends Collector {
return target.nextOrd();
}
@Override
public long docValueCount() {
return target.docValueCount();
}
@Override
public BytesRef lookupOrd(long ord) throws IOException {
final BytesRef val = target.lookupOrd(ord);

View File

@ -1154,6 +1154,11 @@ public class MemoryIndex {
return ord++;
}
@Override
public long docValueCount() {
return values.size();
}
@Override
public BytesRef lookupOrd(long ord) throws IOException {
return values.get(bytesIds[(int) ord], scratch);

View File

@ -1064,6 +1064,11 @@ public class AssertingLeafReader extends FilterLeafReader {
return ord;
}
@Override
public long docValueCount() {
return in.docValueCount();
}
@Override
public BytesRef lookupOrd(long ord) throws IOException {
assertThread("Sorted set doc values", creationThread);