Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5573: Move docvalues constants and helper methods to o.a.l.index.DocValues

Robert Muirb72cd4b7d947
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f431000ce46..b306f4ef6d2 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -218,6 +218,9 @@ API Changes
* LUCENE-5565: Refactor SpatialPrefixTree/Cell to not use Strings. (David Smiley)
+* LUCENE-5573: Move docvalues constants and helper methods to o.a.l.index.DocValues.
+ (Dawid Weiss, Robert Muir)
+
Optimizations
* LUCENE-5468: HunspellStemFilter uses 10 to 100x less RAM. It also loads
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectDocValuesProducer.java b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectDocValuesProducer.java
index c81448e9715..32cd3b93cbe 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectDocValuesProducer.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectDocValuesProducer.java
@@ -26,6 +26,7 @@ import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.NumericDocValues;
@@ -446,9 +447,9 @@ class DirectDocValuesProducer extends DocValuesProducer {
public Bits getDocsWithField(FieldInfo field) throws IOException {
switch(field.getDocValuesType()) {
case SORTED_SET:
- return new SortedSetDocsWithField(getSortedSet(field), maxDoc);
+ return DocValues.docsWithValue(getSortedSet(field), maxDoc);
case SORTED:
- return new SortedDocsWithField(getSorted(field), maxDoc);
+ return DocValues.docsWithValue(getSorted(field), maxDoc);
case BINARY:
BinaryEntry be = binaries.get(field.number);
return getMissingBits(field.number, be.missingOffset, be.missingBytes);
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesProducer.java b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesProducer.java
index 79790ebc078..815bad5ca30 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesProducer.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesProducer.java
@@ -26,6 +26,7 @@ import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocsAndPositionsEnum;
import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.FieldInfo;
@@ -321,7 +322,7 @@ class MemoryDocValuesProducer extends DocValuesProducer {
public SortedDocValues getSorted(FieldInfo field) throws IOException {
final FSTEntry entry = fsts.get(field.number);
if (entry.numOrds == 0) {
- return SortedDocValues.EMPTY;
+ return DocValues.EMPTY_SORTED;
}
FST<Long> instance;
synchronized(this) {
@@ -396,7 +397,7 @@ class MemoryDocValuesProducer extends DocValuesProducer {
public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException {
final FSTEntry entry = fsts.get(field.number);
if (entry.numOrds == 0) {
- return SortedSetDocValues.EMPTY; // empty FST!
+ return DocValues.EMPTY_SORTED_SET; // empty FST!
}
FST<Long> instance;
synchronized(this) {
@@ -509,9 +510,9 @@ class MemoryDocValuesProducer extends DocValuesProducer {
public Bits getDocsWithField(FieldInfo field) throws IOException {
switch(field.getDocValuesType()) {
case SORTED_SET:
- return new SortedSetDocsWithField(getSortedSet(field), maxDoc);
+ return DocValues.docsWithValue(getSortedSet(field), maxDoc);
case SORTED:
- return new SortedDocsWithField(getSorted(field), maxDoc);
+ return DocValues.docsWithValue(getSorted(field), maxDoc);
case BINARY:
BinaryEntry be = binaries.get(field.number);
return getMissingBits(field.number, be.missingOffset, be.missingBytes);
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java
index c00fd8adefc..07a804a46e8 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java
@@ -41,6 +41,7 @@ import java.util.Map;
import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfo.DocValuesType;
import org.apache.lucene.index.IndexFileNames;
@@ -433,9 +434,9 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
public Bits getDocsWithField(FieldInfo field) throws IOException {
switch (field.getDocValuesType()) {
case SORTED_SET:
- return new SortedSetDocsWithField(getSortedSet(field), maxDoc);
+ return DocValues.docsWithValue(getSortedSet(field), maxDoc);
case SORTED:
- return new SortedDocsWithField(getSorted(field), maxDoc);
+ return DocValues.docsWithValue(getSorted(field), maxDoc);
case BINARY:
return getBinaryDocsWithField(field);
case NUMERIC:
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesProducer.java
index 931c08238c0..0c7e3cdfdae 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesProducer.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesProducer.java
@@ -75,61 +75,4 @@ public abstract class DocValuesProducer implements Closeable {
* @lucene.internal
*/
public abstract void checkIntegrity() throws IOException;
-
- /**
- * A simple implementation of {@link DocValuesProducer#getDocsWithField} that
- * returns {@code true} if a document has an ordinal &gt;= 0
- * <p>
- * Codecs can choose to use this (or implement it more efficiently another way), but
- * in most cases a Bits is unnecessary anyway: users can check this as they go.
- */
- public static class SortedDocsWithField implements Bits {
- final SortedDocValues in;
- final int maxDoc;
-
- /** Creates a {@link Bits} returning true if the document has a value */
- public SortedDocsWithField(SortedDocValues in, int maxDoc) {
- this.in = in;
- this.maxDoc = maxDoc;
- }
-
- @Override
- public boolean get(int index) {
- return in.getOrd(index) >= 0;
- }
-
- @Override
- public int length() {
- return maxDoc;
- }
- }
-
- /**
- * A simple implementation of {@link DocValuesProducer#getDocsWithField} that
- * returns {@code true} if a document has any ordinals.
- * <p>
- * Codecs can choose to use this (or implement it more efficiently another way), but
- * in most cases a Bits is unnecessary anyway: users can check this as they go.
- */
- public static class SortedSetDocsWithField implements Bits {
- final SortedSetDocValues in;
- final int maxDoc;
-
- /** Creates a {@link Bits} returning true if the document has a value */
- public SortedSetDocsWithField(SortedSetDocValues in, int maxDoc) {
- this.in = in;
- this.maxDoc = maxDoc;
- }
-
- @Override
- public boolean get(int index) {
- in.setDocument(index);
- return in.nextOrd() != SortedSetDocValues.NO_MORE_ORDS;
- }
-
- @Override
- public int length() {
- return maxDoc;
- }
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesProducer.java
index afe956be636..938b2582d56 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesProducer.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesProducer.java
@@ -26,6 +26,7 @@ import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocsAndPositionsEnum;
import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.FieldInfo;
@@ -380,7 +381,7 @@ class Lucene42DocValuesProducer extends DocValuesProducer {
public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException {
final FSTEntry entry = fsts.get(field.number);
if (entry.numOrds == 0) {
- return SortedSetDocValues.EMPTY; // empty FST!
+ return DocValues.EMPTY_SORTED_SET; // empty FST!
}
FST<Long> instance;
synchronized(this) {
@@ -469,7 +470,7 @@ class Lucene42DocValuesProducer extends DocValuesProducer {
@Override
public Bits getDocsWithField(FieldInfo field) throws IOException {
if (field.getDocValuesType() == FieldInfo.DocValuesType.SORTED_SET) {
- return new SortedSetDocsWithField(getSortedSet(field), maxDoc);
+ return DocValues.docsWithValue(getSortedSet(field), maxDoc);
} else {
return new Bits.MatchAllBits(maxDoc);
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesProducer.java
index 8baccefa6cf..1c3faf6e841 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesProducer.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesProducer.java
@@ -37,6 +37,7 @@ import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocsAndPositionsEnum;
import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.FieldInfo;
@@ -45,7 +46,6 @@ import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.RandomAccessOrds;
import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SingletonSortedSetDocValues;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.index.TermsEnum;
@@ -525,7 +525,7 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos
SortedSetEntry ss = sortedSets.get(field.number);
if (ss.format == SORTED_SET_SINGLE_VALUED_SORTED) {
final SortedDocValues values = getSorted(field);
- return new SingletonSortedSetDocValues(values);
+ return DocValues.singleton(values);
} else if (ss.format != SORTED_SET_WITH_ADDRESSES) {
throw new AssertionError();
}
@@ -629,9 +629,9 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos
public Bits getDocsWithField(FieldInfo field) throws IOException {
switch(field.getDocValuesType()) {
case SORTED_SET:
- return new SortedSetDocsWithField(getSortedSet(field), maxDoc);
+ return DocValues.docsWithValue(getSortedSet(field), maxDoc);
case SORTED:
- return new SortedDocsWithField(getSorted(field), maxDoc);
+ return DocValues.docsWithValue(getSorted(field), maxDoc);
case BINARY:
BinaryEntry be = binaries.get(field.number);
return getMissingBits(be.missingOffset);
diff --git a/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java b/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java
index 67fe0b14486..9e90560e709 100644
--- a/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java
@@ -30,14 +30,4 @@ public abstract class BinaryDocValues {
/** Lookup the value for document. */
public abstract void get(int docID, BytesRef result);
-
- /** An empty BinaryDocValues which returns {@link BytesRef#EMPTY_BYTES} for every document */
- public static final BinaryDocValues EMPTY = new BinaryDocValues() {
- @Override
- public void get(int docID, BytesRef result) {
- result.bytes = BytesRef.EMPTY_BYTES;
- result.offset = 0;
- result.length = 0;
- }
- };
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java b/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java
index 8358312c8dc..19059640fa8 100644
--- a/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java
+++ b/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java
@@ -762,7 +762,7 @@ public class DocTermOrds {
/** Returns a SortedSetDocValues view of this instance */
public SortedSetDocValues iterator(AtomicReader reader) throws IOException {
if (isEmpty()) {
- return SortedSetDocValues.EMPTY;
+ return DocValues.EMPTY_SORTED_SET;
} else {
return new Iterator(reader);
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/DocValues.java b/lucene/core/src/java/org/apache/lucene/index/DocValues.java
new file mode 100644
index 00000000000..e894a512264
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/index/DocValues.java
@@ -0,0 +1,162 @@
+package org.apache.lucene.index;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BytesRef;
+
+/**
+ * This class contains utility methods and constants for DocValues
+ */
+public final class DocValues {
+
+ /* no instantiation */
+ private DocValues() {}
+
+ /**
+ * An empty BinaryDocValues which returns {@link BytesRef#EMPTY_BYTES} for every document
+ */
+ public static final BinaryDocValues EMPTY_BINARY = new BinaryDocValues() {
+ @Override
+ public void get(int docID, BytesRef result) {
+ result.bytes = BytesRef.EMPTY_BYTES;
+ result.offset = 0;
+ result.length = 0;
+ }
+ };
+
+ /**
+ * An empty NumericDocValues which returns zero for every document
+ */
+ public static final NumericDocValues EMPTY_NUMERIC = new NumericDocValues() {
+ @Override
+ public long get(int docID) {
+ return 0;
+ }
+ };
+
+ /**
+ * An empty SortedDocValues which returns {@link BytesRef#EMPTY_BYTES} for every document
+ */
+ public static final SortedDocValues EMPTY_SORTED = new SortedDocValues() {
+ @Override
+ public int getOrd(int docID) {
+ return -1;
+ }
+
+ @Override
+ public void lookupOrd(int ord, BytesRef result) {
+ result.bytes = BytesRef.EMPTY_BYTES;
+ result.offset = 0;
+ result.length = 0;
+ }
+
+ @Override
+ public int getValueCount() {
+ return 0;
+ }
+ };
+
+ /**
+ * An empty SortedDocValues which returns {@link SortedSetDocValues#NO_MORE_ORDS} for every document
+ */
+ public static final SortedSetDocValues EMPTY_SORTED_SET = new RandomAccessOrds() {
+
+ @Override
+ public long nextOrd() {
+ return NO_MORE_ORDS;
+ }
+
+ @Override
+ public void setDocument(int docID) {}
+
+ @Override
+ public void lookupOrd(long ord, BytesRef result) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ @Override
+ public long getValueCount() {
+ return 0;
+ }
+
+ @Override
+ public long ordAt(int index) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ @Override
+ public int cardinality() {
+ return 0;
+ }
+ };
+
+ /**
+ * Returns a multi-valued view over the provided SortedDocValues
+ */
+ public static SortedSetDocValues singleton(SortedDocValues dv) {
+ return new SingletonSortedSetDocValues(dv);
+ }
+
+ /**
+ * Returns a single-valued view of the SortedSetDocValues, if it was previously
+ * wrapped with {@link #singleton}, or null.
+ */
+ public static SortedDocValues unwrapSingleton(SortedSetDocValues dv) {
+ if (dv instanceof SingletonSortedSetDocValues) {
+ return ((SingletonSortedSetDocValues)dv).getSortedDocValues();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns a Bits representing all documents from <code>dv</code> that have a value.
+ */
+ public static Bits docsWithValue(final SortedDocValues dv, final int maxDoc) {
+ return new Bits() {
+ @Override
+ public boolean get(int index) {
+ return dv.getOrd(index) >= 0;
+ }
+
+ @Override
+ public int length() {
+ return maxDoc;
+ }
+ };
+ }
+
+ /**
+ * Returns a Bits representing all documents from <code>dv</code> that have a value.
+ */
+ public static Bits docsWithValue(final SortedSetDocValues dv, final int maxDoc) {
+ return new Bits() {
+ @Override
+ public boolean get(int index) {
+ dv.setDocument(index);
+ return dv.nextOrd() != SortedSetDocValues.NO_MORE_ORDS;
+ }
+
+ @Override
+ public int length() {
+ return maxDoc;
+ }
+ };
+ }
+}
diff --git a/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java b/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java
index b02ab5efeb2..b0e459c88bf 100644
--- a/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java
@@ -73,7 +73,7 @@ public class MultiDocValues {
AtomicReaderContext context = leaves.get(i);
NumericDocValues v = context.reader().getNormValues(field);
if (v == null) {
- v = NumericDocValues.EMPTY;
+ v = DocValues.EMPTY_NUMERIC;
} else {
anyReal = true;
}
@@ -115,7 +115,7 @@ public class MultiDocValues {
AtomicReaderContext context = leaves.get(i);
NumericDocValues v = context.reader().getNumericDocValues(field);
if (v == null) {
- v = NumericDocValues.EMPTY;
+ v = DocValues.EMPTY_NUMERIC;
} else {
anyReal = true;
}
@@ -205,7 +205,7 @@ public class MultiDocValues {
AtomicReaderContext context = leaves.get(i);
BinaryDocValues v = context.reader().getBinaryDocValues(field);
if (v == null) {
- v = BinaryDocValues.EMPTY;
+ v = DocValues.EMPTY_BINARY;
} else {
anyReal = true;
}
@@ -250,7 +250,7 @@ public class MultiDocValues {
AtomicReaderContext context = leaves.get(i);
SortedDocValues v = context.reader().getSortedDocValues(field);
if (v == null) {
- v = SortedDocValues.EMPTY;
+ v = DocValues.EMPTY_SORTED;
} else {
anyReal = true;
}
@@ -294,7 +294,7 @@ public class MultiDocValues {
AtomicReaderContext context = leaves.get(i);
SortedSetDocValues v = context.reader().getSortedSetDocValues(field);
if (v == null) {
- v = SortedSetDocValues.EMPTY;
+ v = DocValues.EMPTY_SORTED_SET;
} else {
anyReal = true;
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/NumericDocValues.java b/lucene/core/src/java/org/apache/lucene/index/NumericDocValues.java
index 8678a5bbc68..0cfcf7b2250 100644
--- a/lucene/core/src/java/org/apache/lucene/index/NumericDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/NumericDocValues.java
@@ -32,12 +32,4 @@ public abstract class NumericDocValues {
* @return numeric value
*/
public abstract long get(int docID);
-
- /** An empty NumericDocValues which returns zero for every document */
- public static final NumericDocValues EMPTY = new NumericDocValues() {
- @Override
- public long get(int docID) {
- return 0;
- }
- };
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java
index 572274b6b79..53bd05f3e61 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java
@@ -167,7 +167,7 @@ final class SegmentMerger {
NumericDocValues values = reader.getNumericDocValues(field.name);
Bits bits = reader.getDocsWithField(field.name);
if (values == null) {
- values = NumericDocValues.EMPTY;
+ values = DocValues.EMPTY_NUMERIC;
bits = new Bits.MatchNoBits(reader.maxDoc());
}
toMerge.add(values);
@@ -181,7 +181,7 @@ final class SegmentMerger {
BinaryDocValues values = reader.getBinaryDocValues(field.name);
Bits bits = reader.getDocsWithField(field.name);
if (values == null) {
- values = BinaryDocValues.EMPTY;
+ values = DocValues.EMPTY_BINARY;
bits = new Bits.MatchNoBits(reader.maxDoc());
}
toMerge.add(values);
@@ -193,7 +193,7 @@ final class SegmentMerger {
for (AtomicReader reader : mergeState.readers) {
SortedDocValues values = reader.getSortedDocValues(field.name);
if (values == null) {
- values = SortedDocValues.EMPTY;
+ values = DocValues.EMPTY_SORTED;
}
toMerge.add(values);
}
@@ -203,7 +203,7 @@ final class SegmentMerger {
for (AtomicReader reader : mergeState.readers) {
SortedSetDocValues values = reader.getSortedSetDocValues(field.name);
if (values == null) {
- values = SortedSetDocValues.EMPTY;
+ values = DocValues.EMPTY_SORTED_SET;
}
toMerge.add(values);
}
@@ -234,7 +234,7 @@ final class SegmentMerger {
for (AtomicReader reader : mergeState.readers) {
NumericDocValues norms = reader.getNormValues(field.name);
if (norms == null) {
- norms = NumericDocValues.EMPTY;
+ norms = DocValues.EMPTY_NUMERIC;
}
toMerge.add(norms);
docsWithField.add(new Bits.MatchAllBits(reader.maxDoc()));
diff --git a/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java b/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java
index 061b9bbcc9d..3454b090837 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java
@@ -26,7 +26,7 @@ import org.apache.lucene.util.BytesRef;
* against e.g. FieldCache.getDocTermOrds that also works for single-valued
* fields.
*/
-public class SingletonSortedSetDocValues extends SortedSetDocValues {
+final class SingletonSortedSetDocValues extends SortedSetDocValues {
private final SortedDocValues in;
private int docID;
private boolean set;
diff --git a/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java b/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
index b127e119dce..3481460ce8e 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
@@ -130,7 +130,7 @@ public final class SlowCompositeReaderWrapper extends AtomicReader {
AtomicReaderContext context = in.leaves().get(i);
SortedDocValues v = context.reader().getSortedDocValues(field);
if (v == null) {
- v = SortedDocValues.EMPTY;
+ v = DocValues.EMPTY_SORTED;
}
values[i] = v;
starts[i] = context.docBase;
@@ -169,7 +169,7 @@ public final class SlowCompositeReaderWrapper extends AtomicReader {
AtomicReaderContext context = in.leaves().get(i);
SortedSetDocValues v = context.reader().getSortedSetDocValues(field);
if (v == null) {
- v = SortedSetDocValues.EMPTY;
+ v = DocValues.EMPTY_SORTED_SET;
}
values[i] = v;
starts[i] = context.docBase;
diff --git a/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java b/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java
index a00ce9d493a..557c08237df 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java
@@ -68,26 +68,6 @@ public abstract class SortedDocValues extends BinaryDocValues {
}
}
- /** An empty SortedDocValues which returns {@link BytesRef#EMPTY_BYTES} for every document */
- public static final SortedDocValues EMPTY = new SortedDocValues() {
- @Override
- public int getOrd(int docID) {
- return -1;
- }
-
- @Override
- public void lookupOrd(int ord, BytesRef result) {
- result.bytes = BytesRef.EMPTY_BYTES;
- result.offset = 0;
- result.length = 0;
- }
-
- @Override
- public int getValueCount() {
- return 0;
- }
- };
-
/** If {@code key} exists, returns its ordinal, else
* returns {@code -insertionPoint-1}, like {@code
* Arrays.binarySearch}.
diff --git a/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValues.java b/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValues.java
index fd9e99ef5e9..03d61ae40fd 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SortedSetDocValues.java
@@ -67,39 +67,6 @@ public abstract class SortedSetDocValues {
*/
public abstract long getValueCount();
-
- /** An empty SortedDocValues which returns {@link #NO_MORE_ORDS} for every document */
- public static final SortedSetDocValues EMPTY = new RandomAccessOrds() {
-
- @Override
- public long nextOrd() {
- return NO_MORE_ORDS;
- }
-
- @Override
- public void setDocument(int docID) {}
-
- @Override
- public void lookupOrd(long ord, BytesRef result) {
- throw new IndexOutOfBoundsException();
- }
-
- @Override
- public long getValueCount() {
- return 0;
- }
-
- @Override
- public long ordAt(int index) {
- throw new IndexOutOfBoundsException();
- }
-
- @Override
- public int cardinality() {
- return 0;
- }
- };
-
/** If {@code key} exists, returns its ordinal, else
* returns {@code -insertionPoint-1}, like {@code
* Arrays.binarySearch}.
diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java b/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java
index 9da1de627a2..243e42af9fb 100644
--- a/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java
+++ b/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java
@@ -28,12 +28,12 @@ import java.util.WeakHashMap;
import org.apache.lucene.index.AtomicReader;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.DocTermOrds;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.SegmentReader;
-import org.apache.lucene.index.SingletonSortedSetDocValues;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.index.Terms;
@@ -942,13 +942,13 @@ class FieldCacheImpl implements FieldCache {
} else {
final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
if (info == null) {
- return SortedDocValues.EMPTY;
+ return DocValues.EMPTY_SORTED;
} else if (info.hasDocValues()) {
// we don't try to build a sorted instance from numeric/binary doc
// values because dedup can be very costly
throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
} else if (!info.isIndexed()) {
- return SortedDocValues.EMPTY;
+ return DocValues.EMPTY_SORTED;
}
return (SortedDocValues) caches.get(SortedDocValues.class).get(reader, new CacheKey(field, acceptableOverheadRatio), false);
}
@@ -1084,11 +1084,11 @@ class FieldCacheImpl implements FieldCache {
final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
if (info == null) {
- return BinaryDocValues.EMPTY;
+ return DocValues.EMPTY_BINARY;
} else if (info.hasDocValues()) {
throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
} else if (!info.isIndexed()) {
- return BinaryDocValues.EMPTY;
+ return DocValues.EMPTY_BINARY;
}
return (BinaryDocValues) caches.get(BinaryDocValues.class).get(reader, new CacheKey(field, acceptableOverheadRatio), setDocsWithField);
@@ -1198,16 +1198,16 @@ class FieldCacheImpl implements FieldCache {
SortedDocValues sdv = reader.getSortedDocValues(field);
if (sdv != null) {
- return new SingletonSortedSetDocValues(sdv);
+ return DocValues.singleton(sdv);
}
final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
if (info == null) {
- return SortedSetDocValues.EMPTY;
+ return DocValues.EMPTY_SORTED_SET;
} else if (info.hasDocValues()) {
throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
} else if (!info.isIndexed()) {
- return SortedSetDocValues.EMPTY;
+ return DocValues.EMPTY_SORTED_SET;
}
DocTermOrds dto = (DocTermOrds) caches.get(DocTermOrds.class).get(reader, new CacheKey(field, null), false);
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/DocValuesOrdinalsReader.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/DocValuesOrdinalsReader.java
index df89ffafde1..042ea176b7f 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/DocValuesOrdinalsReader.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/DocValuesOrdinalsReader.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import org.apache.lucene.facet.FacetsConfig;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.BinaryDocValues;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IntsRef;
@@ -45,7 +46,7 @@ public class DocValuesOrdinalsReader extends OrdinalsReader {
public OrdinalsSegmentReader getReader(AtomicReaderContext context) throws IOException {
BinaryDocValues values0 = context.reader().getBinaryDocValues(field);
if (values0 == null) {
- values0 = BinaryDocValues.EMPTY;
+ values0 = DocValues.EMPTY_BINARY;
}
final BinaryDocValues values = values0;
diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/SortedSetSortField.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/SortedSetSortField.java
index 2bfc7437b14..e6b2933e0b3 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/SortedSetSortField.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/SortedSetSortField.java
@@ -20,8 +20,8 @@ package org.apache.lucene.sandbox.queries;
import java.io.IOException;
import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.RandomAccessOrds;
-import org.apache.lucene.index.SingletonSortedSetDocValues;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.search.FieldCache;
@@ -165,11 +165,12 @@ public class SortedSetSortField extends SortField {
throw new UnsupportedOperationException("fields containing more than " + (Integer.MAX_VALUE-1) + " unique terms are unsupported");
}
- if (sortedSet instanceof SingletonSortedSetDocValues) {
+ SortedDocValues singleton = DocValues.unwrapSingleton(sortedSet);
+ if (singleton != null) {
// it's actually single-valued in practice, but indexed as multi-valued,
// so just sort on the underlying single-valued dv directly.
// regardless of selector type, this optimization is safe!
- return ((SingletonSortedSetDocValues) sortedSet).getSortedDocValues();
+ return singleton;
} else if (selector == Selector.MIN) {
return new MinValue(sortedSet);
} else {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
index 8aa0f008e12..0681f29eb2d 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
@@ -2188,7 +2188,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes
// can be null for the segment if no docs actually had any SortedDocValues
// in this case FC.getDocTermsOrds returns EMPTY
if (actual == null) {
- assertEquals(SortedSetDocValues.EMPTY, expected);
+ assertEquals(DocValues.EMPTY_SORTED_SET, expected);
return;
}
assertEquals(expected.getValueCount(), actual.getValueCount());
diff --git a/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java b/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java
index 9b3db15e849..c931c59e4c4 100644
--- a/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java
+++ b/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java
@@ -21,10 +21,10 @@ import java.io.IOException;
import java.util.List;
import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.MultiDocValues.MultiSortedDocValues;
import org.apache.lucene.index.MultiDocValues.MultiSortedSetDocValues;
import org.apache.lucene.index.MultiDocValues.OrdinalMap;
-import org.apache.lucene.index.SingletonSortedSetDocValues;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.search.DocIdSet;
@@ -70,7 +70,7 @@ public class DocValuesFacets {
}
} else {
SortedDocValues single = searcher.getAtomicReader().getSortedDocValues(fieldName);
- si = single == null ? null : new SingletonSortedSetDocValues(single);
+ si = single == null ? null : DocValues.singleton(single);
if (single instanceof MultiSortedDocValues) {
ordinalMap = ((MultiSortedDocValues)single).mapping;
}
@@ -129,19 +129,19 @@ public class DocValuesFacets {
if (schemaField.multiValued()) {
SortedSetDocValues sub = leaf.reader().getSortedSetDocValues(fieldName);
if (sub == null) {
- sub = SortedSetDocValues.EMPTY;
+ sub = DocValues.EMPTY_SORTED_SET;
}
- if (sub instanceof SingletonSortedSetDocValues) {
+ final SortedDocValues singleton = DocValues.unwrapSingleton(sub);
+ if (singleton != null) {
// some codecs may optimize SORTED_SET storage for single-valued fields
- final SortedDocValues values = ((SingletonSortedSetDocValues) sub).getSortedDocValues();
- accumSingle(counts, startTermIndex, values, disi, subIndex, ordinalMap);
+ accumSingle(counts, startTermIndex, singleton, disi, subIndex, ordinalMap);
} else {
accumMulti(counts, startTermIndex, sub, disi, subIndex, ordinalMap);
}
} else {
SortedDocValues sub = leaf.reader().getSortedDocValues(fieldName);
if (sub == null) {
- sub = SortedDocValues.EMPTY;
+ sub = DocValues.EMPTY_SORTED;
}
accumSingle(counts, startTermIndex, sub, disi, subIndex, ordinalMap);
}