==== //app/sfdc/java/src/org/apache/lucene/index/SegmentReader.java#9 - c:\dev\sfdc\java\src\org\apache\lucene\index\SegmentReader.java ==== @@ -51,6 +51,10 @@ // Compound File Reader when based on a compound file segment CompoundFileReader cfsReader = null; + /** If true, it will always loads the norms into memory, if false, it will load them from disk + Unless the indexes are short lived, this should be true. */ + private final static boolean LOAD_NORMS_INTO_MEM = true; + private class Norm extends NormFactors { public Norm(IndexInput in, int number) { @@ -83,7 +87,10 @@ } - public byte getByte(int doc) { - return bytes[doc]; + public byte getByte(int doc) throws IOException { + if (bytes != null) return bytes[doc]; + // OK, we don't have bytes, so we need to seek the input stream (i.e. READ_NORMS_FROM_DISK). + in.seek(doc); + return in.readByte(); } } @@ -515,11 +522,12 @@ Norm norm = norms.get(field); if (norm == null) return NormFactors.getEmptyInstance(); // not indexed, or norms not stored - if (norm.bytes == null) { // value not yet read + if (LOAD_NORMS_INTO_MEM && norm.bytes == null) { // value not yet read byte[] bytes = new byte[maxDoc()]; norms(field, bytes, 0); norm.bytes = bytes; // cache it } + return norm; }