optimize lookupTerm

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1433254 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-01-15 01:40:12 +00:00
parent 6dcc657d91
commit 09d19ac341
1 changed files with 20 additions and 0 deletions

View File

@ -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);
}
}
@Override
public int getValueCount() {
return entry.numOrds;