Apache Lucene open-source search software
optimize lookupTerm
Robert Muir09d19ac341e6
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41SimpleDocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41SimpleDocValuesProducer.javaindex 5bcbafbae8e..2c419a237cd 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41SimpleDocValuesProducer.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41SimpleDocValuesProducer.java@@ -31,10 +31,13 @@ import org.apache.lucene.index.IndexFileNames;import org.apache.lucene.index.NumericDocValues;import org.apache.lucene.index.SegmentReadState;import org.apache.lucene.index.SortedDocValues;+import org.apache.lucene.index.TermsEnum;import org.apache.lucene.store.IndexInput;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.IntsRef;+import org.apache.lucene.util.fst.BytesRefFSTEnum;+import org.apache.lucene.util.fst.BytesRefFSTEnum.InputOutput;import org.apache.lucene.util.fst.FST;import org.apache.lucene.util.fst.FST.Arc;import org.apache.lucene.util.fst.FST.BytesReader;@@ -219,6 +222,7 @@ class Lucene41SimpleDocValuesProducer extends SimpleDVProducer {final Arc<Long> firstArc = new Arc<Long>();final Arc<Long> scratchArc = new Arc<Long>();final IntsRef scratchInts = new IntsRef();+ final BytesRefFSTEnum<Long> fstEnum = new BytesRefFSTEnum<Long>(fst);return new SortedDocValues() {@Override@@ -237,6 +241,22 @@ class Lucene41SimpleDocValuesProducer extends SimpleDVProducer {}}+ @Override+ public int lookupTerm(BytesRef key, BytesRef spare) {+ try {+ InputOutput<Long> o = fstEnum.seekCeil(key);+ if (o == null) {+ return -getValueCount()-1;+ } else if (o.input.equals(Util.toIntsRef(spare, scratchInts))) {+ return 0;+ } else {+ return (int)-o.output-1;+ }+ } catch (IOException bogus) {+ throw new RuntimeException(bogus);+ }+ }+@Overridepublic int getValueCount() {return entry.numOrds;