Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5769: SingletonSortedSetDocValues now supports random access ordinals

Robert Muir565dfc3e1fb7
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 8b6aa79cd5d..ced44db7548 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -285,6 +285,9 @@ Optimizations
* LUCENE-5767: OrdinalMap optimizations, that mostly help on low cardinalities.
(Martijn van Groningen, Adrien Grand)
+* LUCENE-5769: SingletonSortedSetDocValues now supports random access ordinals.
+ (Robert Muir)
+
Bug fixes
* LUCENE-5738: Ensure NativeFSLock prevents opening the file channel for the
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 2e45ab1f9b8..b11c53a7093 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SingletonSortedSetDocValues.java
@@ -25,10 +25,10 @@ import org.apache.lucene.util.BytesRef;
* This can be used if you want to have one multi-valued implementation
* that works for single or multi-valued types.
*/
-final class SingletonSortedSetDocValues extends SortedSetDocValues {
+final class SingletonSortedSetDocValues extends RandomAccessOrds {
private final SortedDocValues in;
- private int docID;
- private boolean set;
+ private long currentOrd;
+ private long ord;
/** Creates a multi-valued view over the provided SortedDocValues */
public SingletonSortedSetDocValues(SortedDocValues in) {
@@ -43,18 +43,14 @@ final class SingletonSortedSetDocValues extends SortedSetDocValues {
@Override
public long nextOrd() {
- if (set) {
- return NO_MORE_ORDS;
- } else {
- set = true;
- return in.getOrd(docID);
- }
+ long v = currentOrd;
+ currentOrd = NO_MORE_ORDS;
+ return v;
}
@Override
public void setDocument(int docID) {
- this.docID = docID;
- set = false;
+ currentOrd = ord = in.getOrd(docID);
}
@Override
@@ -72,4 +68,19 @@ final class SingletonSortedSetDocValues extends SortedSetDocValues {
public long lookupTerm(BytesRef key) {
return in.lookupTerm(key);
}
+
+ @Override
+ public long ordAt(int index) {
+ return ord;
+ }
+
+ @Override
+ public int cardinality() {
+ return (int) (ord >>> 63) ^ 1;
+ }
+
+ @Override
+ public TermsEnum termsEnum() {
+ return in.termsEnum();
+ }
}