From 09d19ac341e6bb70c76b650fcd82bfc2fbf6a6dd Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 15 Jan 2013 01:40:12 +0000 Subject: [PATCH] optimize lookupTerm git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1433254 13f79535-47bb-0310-9956-ffa450edef68 --- .../Lucene41SimpleDocValuesProducer.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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.java index 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 firstArc = new Arc(); final Arc scratchArc = new Arc(); final IntsRef scratchInts = new IntsRef(); + final BytesRefFSTEnum fstEnum = new BytesRefFSTEnum(fst); return new SortedDocValues() { @Override @@ -237,6 +241,22 @@ class Lucene41SimpleDocValuesProducer extends SimpleDVProducer { } } + @Override + public int lookupTerm(BytesRef key, BytesRef spare) { + try { + InputOutput 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); + } + } + @Override public int getValueCount() { return entry.numOrds;