mirror of
https://github.com/apache/lucene.git
synced 2025-02-17 23:45:09 +00:00
add a cache to slow-wrapper for getSortedDocValues
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1442342 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9e62bd9282
commit
1d92d6f5df
@ -221,7 +221,6 @@ public class MultiDocValues {
|
||||
|
||||
/** maps per-segment ordinals to/from global ordinal space */
|
||||
// TODO: use more efficient packed ints structures (these are all positive values!)
|
||||
// nocommit: cache this in SlowWrapper, it can create MultiSortedDV with it directly.
|
||||
static class OrdinalMap {
|
||||
// globalOrd -> (globalOrd - segmentOrd)
|
||||
final AppendingLongBuffer globalOrdDeltas;
|
||||
|
@ -18,10 +18,14 @@ package org.apache.lucene.index;
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.util.Bits;
|
||||
|
||||
import org.apache.lucene.index.DirectoryReader; // javadoc
|
||||
import org.apache.lucene.index.MultiDocValues.MultiSortedDocValues;
|
||||
import org.apache.lucene.index.MultiDocValues.OrdinalMap;
|
||||
import org.apache.lucene.index.MultiReader; // javadoc
|
||||
|
||||
/**
|
||||
@ -94,8 +98,40 @@ public final class SlowCompositeReaderWrapper extends AtomicReader {
|
||||
@Override
|
||||
public SortedDocValues getSortedDocValues(String field) throws IOException {
|
||||
ensureOpen();
|
||||
return MultiDocValues.getSortedValues(in, field);
|
||||
OrdinalMap map = null;
|
||||
synchronized (cachedOrdMaps) {
|
||||
map = cachedOrdMaps.get(field);
|
||||
if (map == null) {
|
||||
// uncached, or not a multi dv
|
||||
SortedDocValues dv = MultiDocValues.getSortedValues(in, field);
|
||||
if (dv instanceof MultiSortedDocValues) {
|
||||
map = ((MultiSortedDocValues)dv).mapping;
|
||||
cachedOrdMaps.put(field, map);
|
||||
}
|
||||
return dv;
|
||||
}
|
||||
}
|
||||
// cached multi dv
|
||||
assert map != null;
|
||||
int size = in.leaves().size();
|
||||
final SortedDocValues[] values = new SortedDocValues[size];
|
||||
final int[] starts = new int[size+1];
|
||||
for (int i = 0; i < size; i++) {
|
||||
AtomicReaderContext context = in.leaves().get(i);
|
||||
SortedDocValues v = context.reader().getSortedDocValues(field);
|
||||
if (v == null) {
|
||||
v = SortedDocValues.EMPTY;
|
||||
}
|
||||
values[i] = v;
|
||||
starts[i] = context.docBase;
|
||||
}
|
||||
starts[size] = maxDoc();
|
||||
return new MultiSortedDocValues(values, starts, map);
|
||||
}
|
||||
|
||||
// TODO: this could really be a weak map somewhere else on the coreCacheKey,
|
||||
// but do we really need to optimize slow-wrapper any more?
|
||||
private final Map<String,OrdinalMap> cachedOrdMaps = new HashMap<String,OrdinalMap>();
|
||||
|
||||
@Override
|
||||
public NumericDocValues getNormValues(String field) throws IOException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user